summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYoggzo <yogg@epsina.com>2016-03-02 10:58:01 +0100
committerYoggzo <yogg@epsina.com>2016-03-02 10:58:01 +0100
commitd1bd9b4a0c3168eec28ea1c3992748afe1953218 (patch)
tree538ef3d0b37e1dcb0528ce6395c3a82a672a5089
parentae1100c16880d4bae77513ec433ac6734da8dea4 (diff)
parentb6d7d2c30efe5e9758072bb82ea3a947bda7fd1d (diff)
Merge branch 'develop' into Evan
-rw-r--r--client/index.html4
-rw-r--r--client/js/controllers/home/machineDetails.js4
-rw-r--r--client/js/controllers/home/main.js30
-rw-r--r--client/js/services/Compute.js134
-rw-r--r--client/js/services/Identity.js13
-rw-r--r--client/js/services/Loading.js22
-rw-r--r--client/partials/home/machineDetails.html30
-rw-r--r--client/partials/home/main.html9
-rw-r--r--client/partials/loading.html18
-rw-r--r--server/core/Compute.php31
10 files changed, 229 insertions, 66 deletions
diff --git a/client/index.html b/client/index.html
index 8d81ac3..8ca2b9f 100644
--- a/client/index.html
+++ b/client/index.html
@@ -28,8 +28,9 @@
<div ng-include="'./partials/login.html'"></div>
<!-- Machine Details Overlay -->
<div ng-include="'./partials/home/machineDetails.html'"></div>
+ <div ng-include="'./partials/loading.html'"></div>
- <!-- Nav -->
+ <!-- Nav -->
<div ng-include="'./partials/nav.html'"></div>
</div>
</div>
@@ -79,6 +80,7 @@
<script src="./js/services/Identity.js"></script>
<script src="./js/services/Image.js"></script>
<script src="./js/services/Compute.js"></script>
+ <script src="./js/services/Loading.js"></script>
<!-- Include controller -->
<script src="./js/controllers/login.js"></script>
diff --git a/client/js/controllers/home/machineDetails.js b/client/js/controllers/home/machineDetails.js
index f84a073..24fac42 100644
--- a/client/js/controllers/home/machineDetails.js
+++ b/client/js/controllers/home/machineDetails.js
@@ -9,8 +9,10 @@ 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 4e3bcda..f84f625 100644
--- a/client/js/controllers/home/main.js
+++ b/client/js/controllers/home/main.js
@@ -3,21 +3,33 @@
*
* @param {$scope} $scope The $scope service from angular
*/
-mainApp.controller('homeCtrl', [ '$scope', 'Compute', '$rootScope', function ($scope, Compute, $rootScope)
+mainApp.controller('homeCtrl', [ '$scope', 'Compute', '$rootScope', 'Loading','Identity', function ($scope, Compute, $rootScope, Loading, Identity)
{
- var updatePage=function(){
- // TODO Update graph etc...
+ var callMeAfterPullData=function(data){
+ $scope.machines=Compute.getData().machines;
+ Loading.stop();
}
- // Retrieve all Data
- Compute.pullData(updatePage);
+ ;
+ if(Compute.getData().machines == null && Identity.isAlreadyLogin()){
+ Loading.start();
+ Compute.pullData(callMeAfterPullData);
+ }
+
+
+
+
+ $scope.raiseShowMachineDetailsEvent=function(id){
- Compute.getMachines(function(adzda){});
+ var callback=function(){
+ Loading.stop();
+ var data=Compute.getData();
+ $rootScope.$broadcast("showMachineDetailsEvent", data.machines[id], data.axioms);
- $scope.raiseShowMachineDetailsEvent=function(){
- var machine={name: "Machine 1", online:true};
- $rootScope.$broadcast("showMachineDetailsEvent", machine);
+ }
+ Loading.start();
+ Compute.pullMachines(callback);
}
diff --git a/client/js/services/Compute.js b/client/js/services/Compute.js
index 8148948..36ddc16 100644
--- a/client/js/services/Compute.js
+++ b/client/js/services/Compute.js
@@ -2,55 +2,139 @@
mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){
- // Create data
+ // Init data
var data={};
- data.machines={};
+ 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
-
- // Parser
- var parseGetMachinesAnswer=function(response, failedToSendRequest){
+ /**
+ * 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 request";
+ }
+ else{
+ requestParserResult.failReason="Error";
+ }
+ return requestParserResult;
+ };
- // Get Machine
- var getMachines=function(callback){
- var params={
- "token" : Identity.getToken(),
- "task" : "compute",
- "action":"getServer",
- "serverId":"69d5bcc4-2fab-4634-b0d2-f455fee5b7bd"
- };
-
+ /**
+ * 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(params));
+ $.param({"token" : Identity.getToken(), "task" : "compute", "action":"listServers"}));
// Wait and handle the response
result.then(function (response){
- console.log(response.data.Servers);
- callback(parseGetMachinesAnswer(response, false));
+ callback(parsePullMachinesAnswer(response, false));
},function(response){
- alert(response.status);
- callback(parseGetMachinesAnswer(response, true));
- });
+ 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);
}
-
+
+ /**
+ * Get Data
+ * @return {data} return the data object
+ */
+ var getData=function(){
+ return data;
+ }
+
// Return services objects
return {
- getMachines: getMachines,
+ pullMachines: pullMachines,
pullData: pullData,
- data:data
+ getData: getData
};
diff --git a/client/js/services/Identity.js b/client/js/services/Identity.js
index b1d2a48..da85ecd 100644
--- a/client/js/services/Identity.js
+++ b/client/js/services/Identity.js
@@ -48,6 +48,9 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
$cookies.remove('profile');
$cookies.remove('token.part_0');
$cookies.remove('token.part_1');
+ token=null;
+ profile.username=null;
+ profile.projectname=null;
}
@@ -81,6 +84,10 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
$cookies.putObject('token.part_0', response.data.token.substring(0, middle), {'expires': expireDate});
// Save second part of token
$cookies.putObject('token.part_1', response.data.token.substring(middle, response.data.token.length), {'expires': expireDate});
+
+ // Put token in var
+ token=response.data.token;
+
}
else if(failedToSendRequest){
requestParserResult.failReason="Failed to send request";
@@ -102,7 +109,7 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
* @param {string} projectname The user project name
* @param {function} function to call when data is avalaible
*/
- var login=function(username, password,projectname, callback){
+ var login=function(username, password,projectname,callback){
// Set profile information (early)
profile.username=username;
@@ -120,6 +127,9 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
};
+
+
+
/*
* Get the profile
*/
@@ -133,6 +143,7 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
var getToken=function(){
return token;
}
+
// Return services objects
diff --git a/client/js/services/Loading.js b/client/js/services/Loading.js
new file mode 100644
index 0000000..b12aaa0
--- /dev/null
+++ b/client/js/services/Loading.js
@@ -0,0 +1,22 @@
+
+mainApp.factory('Loading',[ '$http', 'Identity', function($http, Identity){
+
+
+
+
+ var start=function(){
+ $('#loadingModal').modal({backdrop: 'static', keyboard: false});
+ };
+
+ var stop=function(){
+ $('#loadingModal').modal('hide');
+ }
+
+
+ return {
+ start:start,
+ stop:stop
+ };
+
+
+}]);
diff --git a/client/partials/home/machineDetails.html b/client/partials/home/machineDetails.html
index 606edcf..47a65fb 100644
--- a/client/partials/home/machineDetails.html
+++ b/client/partials/home/machineDetails.html
@@ -21,11 +21,11 @@
<div class="form-group">
<label class="control-label col-sm-2" for="pwd">State</label>
<div class="col-sm-10">
- <span ng-if="machine.online">Online</span>
- <span ng-if="!machine.online">Offline</span>
+ <span ng-if="machine.status=='ACTIVE'">Online</span>
+ <span ng-if="machine.status!=='ACTIVE'">Offline</span>
&nbsp;
- <button class="btn btn-danger" ng-if="machine.online" ng-click="toggleMachineState()">Turn Off</button>
- <button class="btn btn-success" ng-if="!machine.online" ng-click="toggleMachineState()">Turn On</button>
+ <button class="btn btn-danger" ng-if="machine.status=='ACTIVE'" ng-click="toggleMachineState()">Turn Off</button>
+ <button class="btn btn-success" ng-if="machine.status!=='ACTIVE'" ng-click="toggleMachineState()">Turn On</button>
&nbsp;<img src="images/spin/32x32/Preloader_1.gif" id="waitingForToggleMachine"></span>
@@ -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>128 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>1 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>Cirros</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>
diff --git a/client/partials/home/main.html b/client/partials/home/main.html
index 37638d3..f9f8878 100644
--- a/client/partials/home/main.html
+++ b/client/partials/home/main.html
@@ -3,9 +3,10 @@
Home
</div>
<div class="panel-body">
- Main Content
- <button ng-click="raiseShowMachineDetailsEvent()" > Show Machine details</button>
- <div id="test">
- </div>
+
+ Pour charger les machines, recharger la page (temporaire)<br />
+ Selectionner une machine:
+ <div ng-repeat="machine in machines"> <a ng-click="raiseShowMachineDetailsEvent(machine.id)"> {{ machine.name }}</a></div>
+
</div>
</div>
diff --git a/client/partials/loading.html b/client/partials/loading.html
new file mode 100644
index 0000000..c978190
--- /dev/null
+++ b/client/partials/loading.html
@@ -0,0 +1,18 @@
+<div class="modal fade" id="loadingModal" ng-controller="loginCtrl">
+ <div class="modal-dialog">
+ <div class="modal-content"></div>
+ </div>
+ <div class="modal-dialog" style="width:200px;">
+ <div class="modal-content">
+
+ <div class="modal-body" >
+ <div align="center">
+ <img src="images/spin/128x128/Preloader_8.gif" />
+ </div>
+
+
+ </div>
+
+ </div>
+ </div>
+</div>
diff --git a/server/core/Compute.php b/server/core/Compute.php
index 94e219c..a5b8375 100644
--- a/server/core/Compute.php
+++ b/server/core/Compute.php
@@ -35,7 +35,20 @@ class compute
*/
public function listServers()
{
- $servers = $this->libClass->listServers();
+ $serverList = $this->libClass->listServers(true);
+ $servers = Array();
+ foreach($serverList as $server){
+ $servers[$server->id] = Array();
+ $server->flavor->retrieve();
+ $server->image->retrieve();
+ $servers[$server->id]["id"] = $server->id;
+ $servers[$server->id]["name"] = $server->name;
+ $servers[$server->id]["imageId"] = $server->image->id;
+ $servers[$server->id]["flavorId"] = $server->flavor->id;
+ $servers[$server->id]["status"] = $server->status;
+ $servers[$server->id]["ram"] = $server->flavor->ram;
+ $servers[$server->id]["disk"] = $server->flavor->disk;
+ }
$this->app->setOutput("Servers", $servers);
return;
}
@@ -45,7 +58,13 @@ class compute
*/
public function listFlavors()
{
- $flavors = $this->libClass->listFlavors();
+ $flavorList = $this->libClass->listFlavors();
+ $flavors = Array();
+ foreach($flavorList as $flavor){
+ $flavors[$flavor->id] = Array();
+ $flavors[$flavor->id]["id"] = $flavor->id;
+ $flavors[$flavor->id]["name"] = $flavor->name;
+ }
$this->app->setOutput("Flavors", $flavors);
return;
}
@@ -55,7 +74,13 @@ class compute
*/
public function listImages()
{
- $images = $this->libClass->listImages();
+ $imageList = $this->libClass->listImages();
+ $images = Array();
+ foreach($imageList as $image){
+ $images[$image->id] = Array();
+ $images[$image->id]["id"] = $image->id;
+ $images[$image->id]["name"] = $image->name;
+ }
$this->app->setOutput("Images", $images);
return;
}