From e9108d4b97132e853a71cb1dfbad6cf4bddb599b Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Tue, 1 Mar 2016 22:50:37 +0100 Subject: [PATCH] Finish details machine --- client/js/controllers/home/machineDetails.js | 3 +- client/js/controllers/home/main.js | 6 +- client/js/services/Compute.js | 64 ++++++++++++++++++-- client/partials/home/machineDetails.html | 22 ++----- 4 files changed, 69 insertions(+), 26 deletions(-) diff --git a/client/js/controllers/home/machineDetails.js b/client/js/controllers/home/machineDetails.js index 7476c69..24fac42 100644 --- a/client/js/controllers/home/machineDetails.js +++ b/client/js/controllers/home/machineDetails.js @@ -9,8 +9,9 @@ mainApp.controller('machineDetailsCtrl', [ '$scope', 'Compute', '$rootScope', '$ $scope.machine={}; $("#waitingForToggleMachine").hide(); - $scope.$on('showMachineDetailsEvent', function(eventName ,machine){ + $scope.$on('showMachineDetailsEvent', function(eventName ,machine, axioms){ $scope.machine=machine; + $scope.axioms=axioms; console.log(machine); $('#machineDetailsModal').modal({backdrop: false, keyboard: true}); }); diff --git a/client/js/controllers/home/main.js b/client/js/controllers/home/main.js index b44836b..9d7ddfc 100644 --- a/client/js/controllers/home/main.js +++ b/client/js/controllers/home/main.js @@ -6,19 +6,19 @@ mainApp.controller('homeCtrl', [ '$scope', 'Compute', '$rootScope', function ($scope, Compute, $rootScope) { - var callMeAfterGetMachines=function(data){ + var callMeAfterPullData=function(data){ $scope.machines=Compute.getData().machines; } - Compute.pullMachines(callMeAfterGetMachines); + Compute.pullData(callMeAfterPullData); $scope.raiseShowMachineDetailsEvent=function(id){ var callback=function(){ var data=Compute.getData(); - $rootScope.$broadcast("showMachineDetailsEvent", data.machines[id]); + $rootScope.$broadcast("showMachineDetailsEvent", data.machines[id], data.axioms); } Compute.pullMachines(callback); diff --git a/client/js/services/Compute.js b/client/js/services/Compute.js index e2fb3df..36ddc16 100644 --- a/client/js/services/Compute.js +++ b/client/js/services/Compute.js @@ -5,12 +5,14 @@ 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 /** - * Retrieve machine list + * 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 @@ -55,14 +57,68 @@ mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){ 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 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){ - // TODO call getMachines etc... + var nextFunction=function(response){ + if(response.status==0){ + pullMachines(callback); + } + } + pullImages(nextFunction); } diff --git a/client/partials/home/machineDetails.html b/client/partials/home/machineDetails.html index 28c9165..47a65fb 100644 --- a/client/partials/home/machineDetails.html +++ b/client/partials/home/machineDetails.html @@ -34,36 +34,22 @@
+ MB