summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/js/controllers/home/main.js2
-rw-r--r--client/js/services/Compute.js21
-rw-r--r--client/js/services/Identity.js46
3 files changed, 49 insertions, 20 deletions
diff --git a/client/js/controllers/home/main.js b/client/js/controllers/home/main.js
index d93c376..4e3bcda 100644
--- a/client/js/controllers/home/main.js
+++ b/client/js/controllers/home/main.js
@@ -13,6 +13,8 @@ mainApp.controller('homeCtrl', [ '$scope', 'Compute', '$rootScope', function ($s
// Retrieve all Data
Compute.pullData(updatePage);
+ Compute.getMachines(function(adzda){});
+
$scope.raiseShowMachineDetailsEvent=function(){
var machine={name: "Machine 1", online:true};
$rootScope.$broadcast("showMachineDetailsEvent", machine);
diff --git a/client/js/services/Compute.js b/client/js/services/Compute.js
index 70359ee..8148948 100644
--- a/client/js/services/Compute.js
+++ b/client/js/services/Compute.js
@@ -2,11 +2,12 @@
mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){
-
+ // Create data
var data={};
data.machines={};
+
// Parser
var parseGetMachinesAnswer=function(response, failedToSendRequest){
@@ -16,8 +17,24 @@ mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){
// Get Machine
var getMachines=function(callback){
+ var params={
+ "token" : Identity.getToken(),
+ "task" : "compute",
+ "action":"getServer",
+ "serverId":"69d5bcc4-2fab-4634-b0d2-f455fee5b7bd"
+ };
+
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){
+ console.log(response.data.Servers);
+ callback(parseGetMachinesAnswer(response, false));
+ },function(response){
+ alert(response.status);
+ callback(parseGetMachinesAnswer(response, true));
+ });
};
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 {