Skip to content

Commit

Permalink
poll server instead of waiting for a response
Browse files Browse the repository at this point in the history
  • Loading branch information
Domenico Iezzi committed Nov 5, 2017
1 parent 1273226 commit d85313d
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 156 deletions.
1 change: 1 addition & 0 deletions playmaker/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def download(self):
def check(self):
return service.check_local_apks()

@run_on_executor
def update_state(self):
service.update_state()

Expand Down
23 changes: 19 additions & 4 deletions playmaker/static/app.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,25 @@ app.component('loginView', {
ctrl.badUsername = false;
ctrl.badPassword = false;

setInterval(function() {
api.getApps(function(response) {
if (response === 'err') {
ctrl.loggingIn = false;
console.log('unable to contact server');
}
if (response.status === 'PENDING' ||
response.status === 'UNAUTHORIZED') {
return;
}
if (response.status === 'SUCCESS') {
global.auth.login();
$location.path('/');
ctrl.loggingIn = false;
}
});
}, 5000);


ctrl.login = function(user) {
ctrl.badUsername = false;
ctrl.badPassword = false;
Expand All @@ -304,7 +323,6 @@ app.component('loginView', {
}

ctrl.loggingIn = true;

var email = CryptoJS.enc.Utf8.parse(user.email);
var passwd = CryptoJS.enc.Utf8.parse(user.password);
var emailB64 = CryptoJS.enc.Base64.stringify(email);
Expand All @@ -315,9 +333,6 @@ app.component('loginView', {
ctrl.loggingIn = false;
return;
}
global.auth.login();
$location.path('/');
ctrl.loggingIn = false;
});
};
}
Expand Down
304 changes: 152 additions & 152 deletions playmaker/static/app.service.js
Original file line number Diff line number Diff line change
@@ -1,152 +1,152 @@
angular.module('playmaker').service('global', ['$http', function($http) {

function AuthManager() {

this.loggedIn = false;

this.isLoggedIn = function () {
return this.loggedIn;
};

this.login = function () {
this.loggedIn = !this.loggedIn;
};
}

this.addAlert = {};

this.desktop = false;
this.mobile = false;

this.forceHttp = false;

this.auth = new AuthManager();

var screenWidth = window.innerWidth;
if (screenWidth < 700) {
this.mobile = true;
} else {
this.desktop = true;
}

}]);


angular.module('playmaker').service('api', ['$http', '$location', 'global', function($http, $location, global) {

function loginHandler(result) {
if (result.data.status === 'ERROR') {
if (result.data.message !== undefined) {
global.addAlert('danger', result.data.message);
} else {
global.addAlert('danger', 'Application error');
}
global.auth.loggedIn = false;
$location.path('/login');
}
}

this.getApps = function(callback) {
$http({
method: 'GET',
url: '/api/apps'
}).then(function success(response) {
callback(response.data);
}, function error(response) {
callback('err');
});
};

this.search = function(app, callback) {
$http({
method: 'GET',
url: '/api/search?search=' + app
}).then(function success(response) {
loginHandler(response);
callback(response.data);
}, function error(response) {
callback('err');
});
};

this.check = function(callback) {
$http.post('/api/check')
.then(function success(response) {
loginHandler(response);
callback(response.data);
}, function error(response) {
callback('err');
});
};

this.download = function(app, callback) {
var requestData = {
download: [app]
};
$http({
method: 'POST',
url: '/api/download',
data: JSON.stringify(requestData)
}).then(function success(response) {
callback(response.data);
}, function error(response) {
callback('err');
});
};

this.remove = function(app, callback) {
var requestData = {
delete: app
};
$http({
method: 'DELETE',
url: '/api/delete',
data: JSON.stringify(requestData)
}).then(function success(response) {
loginHandler(response);
callback(response.data);
}, function error(response) {
callback('err');
});
};

this.fdroid = function(callback) {
$http({
method: 'GET',
url: '/api/fdroid'
}).then(function success(response) {
callback(response.data);
}, function error(response) {
callback('err');
});
};

this.fdroidUpdate = function(callback) {
$http({
method: 'POST',
url: '/api/fdroid'
}).then(function success(response) {
loginHandler(response);
callback(response.data);
}, function error(response) {
callback('err');
});
};

this.login = function(email, password, callback) {
$http({
method: 'POST',
url: '/api/login',
data: JSON.stringify({
email: email,
password: password
})
}).then(function success(response) {
callback(response.data);
}, function error(response) {
callback('err');
});
};

}]);
angular.module('playmaker').service('global', ['$http', function($http) {

function AuthManager() {

this.loggedIn = false;

this.isLoggedIn = function () {
return this.loggedIn;
};

this.login = function () {
this.loggedIn = !this.loggedIn;
};
}

this.addAlert = {};

this.desktop = false;
this.mobile = false;

this.forceHttp = false;

this.auth = new AuthManager();

var screenWidth = window.innerWidth;
if (screenWidth < 700) {
this.mobile = true;
} else {
this.desktop = true;
}

}]);


angular.module('playmaker').service('api', ['$http', '$location', 'global', function($http, $location, global) {

function loginHandler(result) {
if (result.data.status === 'ERROR') {
if (result.data.message !== undefined) {
global.addAlert('danger', result.data.message);
} else {
global.addAlert('danger', 'Application error');
}
global.auth.loggedIn = false;
$location.path('/login');
}
}

this.getApps = function(callback) {
$http({
method: 'GET',
url: '/api/apps'
}).then(function success(response) {
callback(response.data);
}, function error(response) {
callback('err');
});
};

this.search = function(app, callback) {
$http({
method: 'GET',
url: '/api/search?search=' + app
}).then(function success(response) {
loginHandler(response);
callback(response.data);
}, function error(response) {
callback('err');
});
};

this.check = function(callback) {
$http.post('/api/check')
.then(function success(response) {
loginHandler(response);
callback(response.data);
}, function error(response) {
callback('err');
});
};

this.download = function(app, callback) {
var requestData = {
download: [app]
};
$http({
method: 'POST',
url: '/api/download',
data: JSON.stringify(requestData)
}).then(function success(response) {
callback(response.data);
}, function error(response) {
callback('err');
});
};

this.remove = function(app, callback) {
var requestData = {
delete: app
};
$http({
method: 'DELETE',
url: '/api/delete',
data: JSON.stringify(requestData)
}).then(function success(response) {
loginHandler(response);
callback(response.data);
}, function error(response) {
callback('err');
});
};

this.fdroid = function(callback) {
$http({
method: 'GET',
url: '/api/fdroid'
}).then(function success(response) {
callback(response.data);
}, function error(response) {
callback('err');
});
};

this.fdroidUpdate = function(callback) {
$http({
method: 'POST',
url: '/api/fdroid'
}).then(function success(response) {
loginHandler(response);
callback(response.data);
}, function error(response) {
callback('err');
});
};

this.login = function(email, password, callback) {
$http({
method: 'POST',
url: '/api/login',
data: JSON.stringify({
email: email,
password: password
})
}).then(function success(response) {
callback(response.data);
}, function error(response) {
callback('err');
});
};

}]);

0 comments on commit d85313d

Please sign in to comment.