From 60cfe3ebc039df8d6a468a43a59e7fd8c2a16956 Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Mon, 28 Mar 2016 11:27:37 +0200 Subject: Test --- client/js/services/Compute.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'client/js/services/Compute.js') diff --git a/client/js/services/Compute.js b/client/js/services/Compute.js index 36ddc16..2bf28d8 100644 --- a/client/js/services/Compute.js +++ b/client/js/services/Compute.js @@ -32,7 +32,7 @@ mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){ } else if(failedToSendRequest){ - requestParserResult.failReason="Failed to send request"; + requestParserResult.failReason="Failed to send PullMachine request"; } else{ requestParserResult.failReason="Error"; @@ -79,7 +79,7 @@ mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){ data.axioms.images=response.data.Images; } else if(failedToSendRequest){ - requestParserResult.failReason="Failed to send request"; + requestParserResult.failReason="Failed to send PullImage request"; } else{ requestParserResult.failReason="Error"; @@ -101,8 +101,11 @@ mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){ // Wait and handle the response result.then(function (response){ + alert(Identity.getToken()); + callback(parsePullImagesAnswer(response, false)); },function(response){ + callback(parsePullImagesAnswer(response, true)); }); }; @@ -117,6 +120,9 @@ mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){ if(response.status==0){ pullMachines(callback); } + else{ + callback(response); + } } pullImages(nextFunction); } -- cgit v1.2.3 From 8e700c2b7de7a2bc095ea8edf3204f160f8a8941 Mon Sep 17 00:00:00 2001 From: Loic GUEGAN Date: Sun, 17 Apr 2016 18:42:15 +0200 Subject: Add comments and correct some bugs --- client/js/app.js | 2 +- client/js/controllers/home/home.js | 104 +++++++++++++++++-------------------- client/js/controllers/login.js | 6 ++- client/js/controllers/status.js | 20 ++++--- client/js/services/Compute.js | 2 - client/partials/home/home.html | 11 ++-- 6 files changed, 68 insertions(+), 77 deletions(-) (limited to 'client/js/services/Compute.js') diff --git a/client/js/app.js b/client/js/app.js index e911050..4ef35b5 100644 --- a/client/js/app.js +++ b/client/js/app.js @@ -25,7 +25,7 @@ mainApp.config(['$routeProvider', function($routeProvider){ controller: 'imageCtrl' }) .otherwise({ - redirectTo: '/' + redirectTo: '/home' }); }]); diff --git a/client/js/controllers/home/home.js b/client/js/controllers/home/home.js index 10142c9..7880e12 100755 --- a/client/js/controllers/home/home.js +++ b/client/js/controllers/home/home.js @@ -3,58 +3,52 @@ * * @param {$scope} $scope The $scope service from angular */ -mainApp.controller('homeCtrl', [ '$scope', 'Compute', '$rootScope', 'Loading','Identity', 'Image', function ($scope, Compute, $rootScope, Loading, Identity, Image) -{ - - var callMeAfterPullData=function(data){ - console.log(data); - $scope.machines=Compute.getData().machines; - Loading.stop(); - } - - ; - if(Compute.getData().machines == null && Identity.isAlreadyLogin()){ - Loading.start(); - Compute.pullData(callMeAfterPullData); - } - else{ - if(Identity.isAlreadyLogin()){ - callMeAfterPullData(); - } - } - - - Image.getImages(function(){}); - - - - $scope.raiseShowMachineDetailsEvent=function(id){ - - var callback=function(){ - Loading.stop(); - var data=Compute.getData(); - $rootScope.$broadcast("showMachineDetailsEvent", data.machines[id], data.axioms); - - } - Loading.start(); - Compute.pullMachines(callback); - } - - - - - - if(Identity.isAlreadyLogin()){ - if(Compute.getData().machines == null){ - Loading.start(); - Compute.pullData(callMeAfterPullData); - } - else{ - if(Identity.isAlreadyLogin()){ - callMeAfterPullData(); - } - } - Image.getImages(function(){}); - } - -}]); +mainApp.controller('homeCtrl', ['$scope', 'Compute', '$rootScope', 'Loading', 'Identity', 'Image', function ($scope, Compute, $rootScope, Loading, Identity, Image) + { + + // Function to call after pull all data about machines + var callMeAfterPullData = function (data) { + $scope.machines = Compute.getData().machines; + Loading.stop(); + }; + + // Function to call to try to retrieve data and update the view + var tryToRetrieveData = function () { + // If no data retrieve about machine and user is logged + if (Compute.getData().machines == null && Identity.isAlreadyLogin()) { + Loading.start(); // Show loading gif + Compute.pullData(callMeAfterPullData); // Retrieve data and call the callback + } else { + // Else if user is logged and data is already retrieve + // simply display data + if (Identity.isAlreadyLogin()) { + callMeAfterPullData(); // Display data + } + } + }; + + + // On user login + $scope.$on('loginEvent', function () { + tryToRetrieveData(); + }); + + + + // Function to call from view to display the details of a machine + $scope.raiseShowMachineDetailsEvent = function (id) { + + // Stop loading gif and display overlay + var callback = function () { + Loading.stop(); + var data = Compute.getData(); + $rootScope.$broadcast("showMachineDetailsEvent", data.machines[id], data.axioms); + + }; + Loading.start(); // Show loading gif + Compute.pullMachines(callback); // Retrieve machine info and display overlay + }; + + // Try to retrieve data for the first time + tryToRetrieveData(); + }]); diff --git a/client/js/controllers/login.js b/client/js/controllers/login.js index 93a373e..4a0de42 100644 --- a/client/js/controllers/login.js +++ b/client/js/controllers/login.js @@ -7,7 +7,7 @@ * @param {Identity} The Identity service */ -mainApp.controller('loginCtrl', ['$scope', '$sce', 'Identity', function ($scope, $sce, Identity) +mainApp.controller('loginCtrl', ['$scope', '$sce', 'Identity', '$rootScope', function ($scope, $sce, Identity, $rootScope) { // Check for login and define default states if (!Identity.isAlreadyLogin()) { @@ -51,12 +51,14 @@ mainApp.controller('loginCtrl', ['$scope', '$sce', 'Identity', function ($scope, } else { // Else the user is online ! $('#loginModal').modal('hide'); + // Send login event + $rootScope.$broadcast("loginEvent"); } // Reset button state $('#loginButton').show(); $('#loadingLoginButton').hide(); - } + }; // Try to login Identity.login(username, password, projectname, responseCallback); diff --git a/client/js/controllers/status.js b/client/js/controllers/status.js index 15850f4..c3e634b 100644 --- a/client/js/controllers/status.js +++ b/client/js/controllers/status.js @@ -6,16 +6,14 @@ * @param {$scope} $scope The $scope service from angular * @param {Identity} The Identity service */ -mainApp.controller('statusCtrl', ['$scope','Identity', '$rootScope', function ($scope, Identity, $rootScope) -{ +mainApp.controller('statusCtrl', ['$scope', 'Identity', '$rootScope', function ($scope, Identity, $rootScope) + { + // Give profile to model + $scope.profile = Identity.getProfile(); - - // Give profile to model - $scope.profile=Identity.getProfile(); - - // Function to logout - $scope.logout=function(){ - Identity.logout(); - }; + // Function to logout + $scope.logout = function () { + Identity.logout(); + }; -}]); + }]); diff --git a/client/js/services/Compute.js b/client/js/services/Compute.js index 2bf28d8..032b402 100644 --- a/client/js/services/Compute.js +++ b/client/js/services/Compute.js @@ -101,8 +101,6 @@ mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){ // Wait and handle the response result.then(function (response){ - alert(Identity.getToken()); - callback(parsePullImagesAnswer(response, false)); },function(response){ diff --git a/client/partials/home/home.html b/client/partials/home/home.html index f9f8878..11958d2 100644 --- a/client/partials/home/home.html +++ b/client/partials/home/home.html @@ -1,12 +1,11 @@ -
+
Home
- - Pour charger les machines, recharger la page (temporaire)
- Selectionner une machine: - - + + Selectionner une machine: + +
-- cgit v1.2.3 From fdfdd27a35ebc22222361ed273b6889fec4cf51e Mon Sep 17 00:00:00 2001 From: Loic GUEGAN Date: Sun, 17 Apr 2016 18:43:49 +0200 Subject: Add ';' --- client/js/services/Compute.js | 283 +++++++++++++++++++++--------------------- 1 file changed, 139 insertions(+), 144 deletions(-) (limited to 'client/js/services/Compute.js') diff --git a/client/js/services/Compute.js b/client/js/services/Compute.js index 032b402..5e95f22 100644 --- a/client/js/services/Compute.js +++ b/client/js/services/Compute.js @@ -1,145 +1,140 @@ -mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){ - - - // Init data - var data={}; - data.machines=null; - data.axioms={} // Contain static data - data.axioms.ram=[128,512,1024,2048,4096]; - data.axioms.disk=[1,2,5,10,25,50,100,150,200] - data.axioms.images={}; // Retrieve after - - - /** - * Parse pullMachines answer - * @param {response} the server response - * @param {boolean} false if the request as been send true else - * @return {requestParserResult} the result of parsing - */ - var parsePullMachinesAnswer=function(response, failedToSendRequest){ - - // Defined return object - var requestParserResult={}; - requestParserResult.status=1; - requestParserResult.failReason=null; - - - if (typeof response.data.Servers !== 'undefined') { - // Set status code - requestParserResult.status=0; - data.machines=response.data.Servers; - - } - else if(failedToSendRequest){ - requestParserResult.failReason="Failed to send PullMachine request"; - } - else{ - requestParserResult.failReason="Error"; - } - return requestParserResult; - }; - - - /** - * Retrieve machine list - * @param {callback} function to call after request complete - */ - var pullMachines=function(callback){ - // Send listServers request - var result=$http.post('../server/index.php', - $.param({"token" : Identity.getToken(), "task" : "compute", "action":"listServers"})); - - // Wait and handle the response - result.then(function (response){ - callback(parsePullMachinesAnswer(response, false)); - },function(response){ - callback(parsePullMachinesAnswer(response, true)); - }); - }; - - - /** - * Parse pullImages answer - * @param {response} the server response - * @param {boolean} false if the request as been send true else - * @return {requestParserResult} the result of parsing - */ - var parsePullImagesAnswer=function(response, failedToSendRequest){ - - // Defined return object - var requestParserResult={}; - requestParserResult.status=1; - requestParserResult.failReason=null; - - - if (typeof response.data.Images !== 'undefined') { - // Set status code - requestParserResult.status=0; - data.axioms.images=response.data.Images; - } - else if(failedToSendRequest){ - requestParserResult.failReason="Failed to send PullImage request"; - } - else{ - requestParserResult.failReason="Error"; - } - return requestParserResult; - }; - - - - - /** - * Retrieve machine list - * @param {callback} function to call after request complete - */ - var pullImages=function(callback){ - // Send listServers request - var result=$http.post('../server/index.php', - $.param({"token" : Identity.getToken(), "task" : "compute", "action":"listImages"})); - - // Wait and handle the response - result.then(function (response){ - callback(parsePullImagesAnswer(response, false)); - },function(response){ - - callback(parsePullImagesAnswer(response, true)); - }); - }; - - - /** - * Retrieve all data - * @param {callback} function to call after request complete - */ - var pullData=function(callback){ - var nextFunction=function(response){ - if(response.status==0){ - pullMachines(callback); - } - else{ - callback(response); - } - } - pullImages(nextFunction); - } - - - /** - * Get Data - * @return {data} return the data object - */ - var getData=function(){ - return data; - } - - // Return services objects - return { - pullMachines: pullMachines, - pullData: pullData, - getData: getData - }; - - -}]); +mainApp.factory('Compute', ['$http', 'Identity', function ($http, Identity) { + + + // Init data + var data = {}; + data.machines = null; + data.axioms = {} // Contain static data + data.axioms.ram = [128, 512, 1024, 2048, 4096]; + data.axioms.disk = [1, 2, 5, 10, 25, 50, 100, 150, 200] + data.axioms.images = {}; // Retrieve after + + + /** + * Parse pullMachines answer + * @param {response} the server response + * @param {boolean} false if the request as been send true else + * @return {requestParserResult} the result of parsing + */ + var parsePullMachinesAnswer = function (response, failedToSendRequest) { + + // Defined return object + var requestParserResult = {}; + requestParserResult.status = 1; + requestParserResult.failReason = null; + + + if (typeof response.data.Servers !== 'undefined') { + // Set status code + requestParserResult.status = 0; + data.machines = response.data.Servers; + + } else if (failedToSendRequest) { + requestParserResult.failReason = "Failed to send PullMachine request"; + } else { + requestParserResult.failReason = "Error"; + } + return requestParserResult; + }; + + + /** + * Retrieve machine list + * @param {callback} function to call after request complete + */ + var pullMachines = function (callback) { + // Send listServers request + var result = $http.post('../server/index.php', + $.param({"token": Identity.getToken(), "task": "compute", "action": "listServers"})); + + // Wait and handle the response + result.then(function (response) { + callback(parsePullMachinesAnswer(response, false)); + }, function (response) { + callback(parsePullMachinesAnswer(response, true)); + }); + }; + + + /** + * Parse pullImages answer + * @param {response} the server response + * @param {boolean} false if the request as been send true else + * @return {requestParserResult} the result of parsing + */ + var parsePullImagesAnswer = function (response, failedToSendRequest) { + + // Defined return object + var requestParserResult = {}; + requestParserResult.status = 1; + requestParserResult.failReason = null; + + + if (typeof response.data.Images !== 'undefined') { + // Set status code + requestParserResult.status = 0; + data.axioms.images = response.data.Images; + } else if (failedToSendRequest) { + requestParserResult.failReason = "Failed to send PullImage request"; + } else { + requestParserResult.failReason = "Error"; + } + return requestParserResult; + }; + + + + + /** + * Retrieve machine list + * @param {callback} function to call after request complete + */ + var pullImages = function (callback) { + // Send listServers request + var result = $http.post('../server/index.php', + $.param({"token": Identity.getToken(), "task": "compute", "action": "listImages"})); + + // Wait and handle the response + result.then(function (response) { + callback(parsePullImagesAnswer(response, false)); + }, function (response) { + + callback(parsePullImagesAnswer(response, true)); + }); + }; + + + /** + * Retrieve all data + * @param {callback} function to call after request complete + */ + var pullData = function (callback) { + var nextFunction = function (response) { + if (response.status == 0) { + pullMachines(callback); + } else { + callback(response); + } + }; + pullImages(nextFunction); + }; + + + /** + * Get Data + * @return {data} return the data object + */ + var getData = function () { + return data; + }; + + // Return services objects + return { + pullMachines: pullMachines, + pullData: pullData, + getData: getData + }; + + + }]); -- cgit v1.2.3