Finish details machine

This commit is contained in:
manzerbredes 2016-03-01 22:50:37 +01:00
parent 5ef1c9b8b1
commit e9108d4b97
4 changed files with 69 additions and 26 deletions

View file

@ -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});
});

View file

@ -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);

View file

@ -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);
}

View file

@ -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>