diff options
| author | manzerbredes <loic.guegan_secondary@yahoo.fr> | 2016-03-01 22:50:37 +0100 |
|---|---|---|
| committer | manzerbredes <loic.guegan_secondary@yahoo.fr> | 2016-03-01 22:50:37 +0100 |
| commit | e9108d4b97132e853a71cb1dfbad6cf4bddb599b (patch) | |
| tree | ba6d0e3f6ac7a7e9fe05372f1bab1cafbdadc9ee | |
| parent | 5ef1c9b8b1ab47b659f512db86e51dacf1bec860 (diff) | |
Finish details machine
| -rw-r--r-- | client/js/controllers/home/machineDetails.js | 3 | ||||
| -rw-r--r-- | client/js/controllers/home/main.js | 6 | ||||
| -rw-r--r-- | client/js/services/Compute.js | 64 | ||||
| -rw-r--r-- | 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 @@ <fieldset class="form-group"> <label class="control-label col-sm-2">RAM</label> <select class="col-sm-20" id="ramSelected"> - <option>{{ machine.ram }} MB</option> - <option>512 MB</option> - <option>1024 MB</option> - <option>2048 MB</option> - <option>4096 MB</option> + <option ng-repeat="ram in axioms.ram" ng-selected="machine.ram == ram">{{ ram }}</option> </select> + <span>MB</span> </fieldset> <fieldset class="form-group"> <label class="control-label col-sm-2">Disk</label> <select class="col-sm-20" id="ramSelected"> - <option>{{ machine.disk }} Go</option> - <option>2 Go</option> - <option>5 Go</option> - <option>10 Go</option> - <option>25 Go</option> - <option>50 Go</option> - <option>100 Go</option> - <option>150 Go</option> - <option>200 Go</option> + <option ng-repeat="disk in axioms.disk" ng-selected="machine.disk == disk">{{ disk }}</option> </select> </fieldset> <fieldset class="form-group"> <label class="control-label col-sm-2">Image</label> <select class="col-sm-20" id="ramSelected"> - <option>{{ machine.imageId }}</option> - <option>Debian</option> - <option>Tiny Core</option> - <option>Centos</option> + <option ng-repeat="image in axioms.images" ng-selected="machine.imageId == Object.keys(image)">{{ image.name }}</option> </select> </fieldset> |
