-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
poll server instead of waiting for a response
- Loading branch information
Domenico Iezzi
committed
Nov 5, 2017
1 parent
1273226
commit d85313d
Showing
3 changed files
with
172 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}; | ||
|
||
}]); | ||
|