summaryrefslogtreecommitdiff
path: root/client/js
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 /client/js
parentae1100c16880d4bae77513ec433ac6734da8dea4 (diff)
parentb6d7d2c30efe5e9758072bb82ea3a947bda7fd1d (diff)
Merge branch 'develop' into Evan
Diffstat (limited to 'client/js')
-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
5 files changed, 167 insertions, 36 deletions
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
+ };
+
+
+}]);