summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/js/controllers/home/main.js14
-rw-r--r--client/js/services/Compute.js51
-rw-r--r--client/js/services/Identity.js46
3 files changed, 83 insertions, 28 deletions
diff --git a/client/js/controllers/home/main.js b/client/js/controllers/home/main.js
index d93c376..805bc63 100644
--- a/client/js/controllers/home/main.js
+++ b/client/js/controllers/home/main.js
@@ -10,12 +10,18 @@ mainApp.controller('homeCtrl', [ '$scope', 'Compute', '$rootScope', function ($s
// TODO Update graph etc...
}
- // Retrieve all Data
- Compute.pullData(updatePage);
+
+
+
$scope.raiseShowMachineDetailsEvent=function(){
- var machine={name: "Machine 1", online:true};
- $rootScope.$broadcast("showMachineDetailsEvent", machine);
+ var callback=function(){
+ var data=Compute.getData();
+ console.log(data.machines[Object.keys(data.machines)[0]]);
+ $rootScope.$broadcast("showMachineDetailsEvent", data.machines[Object.keys(data.machines)[0]]);
+
+ }
+ Compute.pullMachines(callback);
}
diff --git a/client/js/services/Compute.js b/client/js/services/Compute.js
index 70359ee..7c9df26 100644
--- a/client/js/services/Compute.js
+++ b/client/js/services/Compute.js
@@ -2,22 +2,57 @@
mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){
-
+ // Create data
var data={};
data.machines={};
+
// Parser
var parseGetMachinesAnswer=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 pullMachines=function(callback){
+ var params={
+ "token" : Identity.getToken(),
+ "task" : "compute",
+ "action":"listServers"
+ };
+
var result=$http.post('../server/index.php',
- $.param({"token" : Identity.profile.token, "task" : "Compute"}));
+ $.param(params));
+
+ // Wait and handle the response
+ result.then(function (response){
+
+ callback(parseGetMachinesAnswer(response, false));
+ },function(response){
+ alert(response.status);
+ callback(parseGetMachinesAnswer(response, true));
+ });
};
@@ -28,12 +63,16 @@ mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){
// TODO call getMachines etc...
}
-
+
+ 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 7604230..b1d2a48 100644
--- a/client/js/services/Identity.js
+++ b/client/js/services/Identity.js
@@ -9,42 +9,37 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
profile.projectname=null;
var token=null;
+
/*
* @returns {boolean} Return true if a cookie is found (and load it in profile) false else
*/
var isAlreadyLogin=function(){
+
+ // Load cookies
var profileInCookie=$cookies.getObject('profile');
var tokenPart_0InCookie=$cookies.getObject('token.part_0');
var tokenPart_1InCookie=$cookies.getObject('token.part_1');
+ // Check if cookie is defined
if(typeof profileInCookie !== 'undefined'
&& typeof tokenPart_0InCookie !== 'undefined'
&& typeof tokenPart_1InCookie !== 'undefined'
){
+
+ // If yes, put it into variables
angular.extend(profile, profileInCookie);
token=tokenPart_0InCookie+tokenPart_1InCookie;
-
+
+ // Return I'm Login
return true;
}
+ // Return I'm not Login
return false;
}
- /*
- * Get the profile
- */
- var getProfile=function(){
- return profile;
- }
-
- /*
- * Get the token
- */
- var getToken=function(){
- return token;
- }
/*
* Destroy profile cookies
@@ -64,7 +59,7 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
*/
var parseLoginAnswer=function(response, failedToSendRequest){
-
+ // Defined return object
var requestParserResult={};
requestParserResult.status=1;
requestParserResult.failReason=null;
@@ -96,6 +91,7 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
return requestParserResult;
};
+
/**
* Function to connect to OpenStack
@@ -113,17 +109,31 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
profile.projectname=projectname;
var result=$http.post('../server/index.php',
- $.param({"task" : "Authenticate", "user" : username, "password" : password, "project" : projectname}));
+ $.param({"task" : "Authenticate", "user" : username, "password" : password, "project" : projectname}));
// Wait and handle the response
result.then(function (response){
- callback(parseLoginAnswer(response), false);
+ callback(parseLoginAnswer(response, false));
},function(response){
- callback(parseLoginAnswer(response), true)
+ callback(parseLoginAnswer(response, true));
});
};
+ /*
+ * Get the profile
+ */
+ var getProfile=function(){
+ return profile;
+ }
+
+ /*
+ * Get the token
+ */
+ var getToken=function(){
+ return token;
+ }
+
// Return services objects
return {