diff options
| author | Yoggzo <yogg@epsina.com> | 2016-02-24 13:23:47 +0100 |
|---|---|---|
| committer | Yoggzo <yogg@epsina.com> | 2016-02-24 13:23:47 +0100 |
| commit | fafb5eeaa4676823680c828ac57adf2e855b7afd (patch) | |
| tree | 58c914ba9b277252daf53c27e878f262cb4579ad /client/js | |
| parent | 16e0328884f318d97ac991ee8e70f43ee1c14b38 (diff) | |
| parent | d2f5ae5c83ef5bc41cf430ace79769459b4acbf8 (diff) | |
Merge branch 'develop' into Evan
Diffstat (limited to 'client/js')
| -rw-r--r-- | client/js/app.js | 3 | ||||
| -rw-r--r-- | client/js/controllers/home/main.js | 13 | ||||
| -rw-r--r-- | client/js/controllers/login.js | 16 | ||||
| -rw-r--r-- | client/js/controllers/status.js | 14 | ||||
| -rw-r--r-- | client/js/services/Compute.js | 40 | ||||
| -rw-r--r-- | client/js/services/Identity.js | 45 | ||||
| -rw-r--r-- | client/js/services/Image.js | 21 |
7 files changed, 126 insertions, 26 deletions
diff --git a/client/js/app.js b/client/js/app.js index 90fae89..e2d5b9b 100644 --- a/client/js/app.js +++ b/client/js/app.js @@ -3,7 +3,7 @@ * The main app module instance * @type angular.module.angular-1_3_6_L1749.moduleInstance */ -var mainApp=angular.module("mainApp",['ngRoute', 'ngSanitize']); +var mainApp=angular.module("mainApp",['ngRoute', 'ngSanitize', 'ngCookies']); /** * Configure routeProvider @@ -29,6 +29,5 @@ mainApp.config(['$routeProvider', function($routeProvider){ */ mainApp.config(['$httpProvider', function($httpProvider){ $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'; - }]); diff --git a/client/js/controllers/home/main.js b/client/js/controllers/home/main.js index e629779..d25bfad 100644 --- a/client/js/controllers/home/main.js +++ b/client/js/controllers/home/main.js @@ -3,8 +3,15 @@ * * @param {$scope} $scope The $scope service from angular */ -mainApp.controller('homeCtrl', function ($scope) +mainApp.controller('homeCtrl', [ '$scope', 'Compute', function ($scope, Compute) { - + + + var updatePage=function(){ + // TODO Update graph etc... + } + + // Retrieve all Data + Compute.pullData(updatePage); -});
\ No newline at end of file +}]); diff --git a/client/js/controllers/login.js b/client/js/controllers/login.js index 6358a6d..829fc1d 100644 --- a/client/js/controllers/login.js +++ b/client/js/controllers/login.js @@ -9,14 +9,20 @@ */ mainApp.controller('loginCtrl', ['$scope','$sce','Identity', function ($scope,$sce, Identity) { - // Define default states - $('#loginModal').modal({backdrop: 'static', keyboard: false}); + // Check for login and define default states + if(!Identity.isAlreadyLogin()){ + $('#loginModal').modal({backdrop: 'static', keyboard: false}); + } + $scope.$on('logoutEvent', function(){ + $('#loginModal').modal({backdrop: 'static', keyboard: false}); + }); + $('#loadingLoginButton').hide(); $('#failedToLoginAlert').hide(); - $('#loginButton').click(function(){ - + $scope.loginAction=function(){ + // Begin login state for template $('#loginButton').hide(); $('#loadingLoginButton').show(); @@ -49,6 +55,6 @@ mainApp.controller('loginCtrl', ['$scope','$sce','Identity', function ($scope,$s // Try to login Identity.login(username, password, projectname, responseCallback); - }); + }; }]); diff --git a/client/js/controllers/status.js b/client/js/controllers/status.js index 2930e34..e01df34 100644 --- a/client/js/controllers/status.js +++ b/client/js/controllers/status.js @@ -6,9 +6,17 @@ * @param {$scope} $scope The $scope service from angular * @param {Identity} The Identity service */ -mainApp.controller('statusCtrl', ['$scope','Identity', function ($scope, Identity) +mainApp.controller('statusCtrl', ['$scope','Identity', '$rootScope', function ($scope, Identity, $rootScope) { + + // Give profile to model $scope.profile=Identity.profile; - - + + // Function to logout + $scope.logout=function(){ + Identity.logout(); + $rootScope.$broadcast('logoutEvent'); + + }; + }]); diff --git a/client/js/services/Compute.js b/client/js/services/Compute.js new file mode 100644 index 0000000..c5c8da9 --- /dev/null +++ b/client/js/services/Compute.js @@ -0,0 +1,40 @@ + +mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){ + + + + var data={}; + data.machines={}; + + + // Parser + var parseGetMachinesAnswer=function(response, failedToSendRequest){ + + }; + + + // Get Machine + var getMachines=function(callback){ + + var result=$http.post('../server/index.php', + $.param({"token" : Identity.profile.token, "task" : "Compute"})); + + + }; + + + + var pullData=function(callback){ + // TODO call getMachines etc... + } + + + // Return services objects + return { + getMachines: getMachines + pullData: pullData + data:data + }; + + +}]); diff --git a/client/js/services/Identity.js b/client/js/services/Identity.js index 4c8919c..8ee664c 100644 --- a/client/js/services/Identity.js +++ b/client/js/services/Identity.js @@ -1,5 +1,5 @@ -mainApp.factory('Identity',[ '$http', function($http){ +mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){ /* Create profile structure to store informations * about current session @@ -11,12 +11,44 @@ mainApp.factory('Identity',[ '$http', function($http){ /** + * Save profile in cookies + */ + var saveCookieForSession=function(){ + $cookies.putObject('profile', 5); + }; + + + /* + * @returns {boolean} Return true if a cookie is found (and load it in profile) false else + */ + var isAlreadyLogin=function(){ + var profileInCookie=$cookies.getObject('profile'); + console.log(profileInCookie); + + if(typeof profileInCookie !== 'undefined'){ + angular.extend(profile, profileInCookie); + return true; + } + + return false; + } + + /* + * Destroy profile cookies + */ + var logout=function(){ + $cookies.remove('profile'); + } + + + /** * * @param {string} response The response to parse * @param {boolean} to check if the request is send or not * @returns {requestParserResult} Formated data */ var parseLoginAnswer=function(response, failedToSendRequest){ + var requestParserResult={}; requestParserResult.status=1; @@ -24,7 +56,8 @@ mainApp.factory('Identity',[ '$http', function($http){ if (typeof response.data.token !== 'undefined') { requestParserResult.status=0; - profile.token=response.data.token; + profile.token=response.data.token; + saveCookieForSession(); } else if(failedToSendRequest){ requestParserResult.failReason="Failed to send request"; @@ -48,7 +81,7 @@ mainApp.factory('Identity',[ '$http', function($http){ * @param {function} function to call when data is avalaible */ var login=function(username, password,projectname, callback){ - + // Set profile information (early) profile.username=username; profile.projectname=projectname; @@ -64,10 +97,14 @@ mainApp.factory('Identity',[ '$http', function($http){ }); }; + + // Return services objects return { login: login, - profile: profile + profile: profile, + isAlreadyLogin: isAlreadyLogin, + logout:logout }; diff --git a/client/js/services/Image.js b/client/js/services/Image.js index 4cb3590..23b33a8 100644 --- a/client/js/services/Image.js +++ b/client/js/services/Image.js @@ -1,24 +1,27 @@ mainApp.factory('Image',[ '$http', 'Identity', function($http, Identity){ - var httpResponse; - var uploadImage=function(image){ + + var parseUploadImageAnswer=function(response, failedToSendRequest){ }; - var parseUploadImageRequest=function(){ + + var getImages=function(callback){ + + var result=$http.post('../server/index.php', + $.param({"token" : Identity.profile.token, "task" : "Image"})); + + }; - var getResponse=function(){ - return parseUploadImageRequest(httpResponse); - }; - + + // Return services objects return { - uploadImage: uploadImage, - getResponse: getResponse + uploadImage: uploadImage }; |
