Clean code
This commit is contained in:
parent
6a67f6ba9d
commit
3656654077
2 changed files with 37 additions and 19 deletions
|
@ -2,11 +2,12 @@
|
||||||
mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){
|
mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){
|
||||||
|
|
||||||
|
|
||||||
|
// Create data
|
||||||
var data={};
|
var data={};
|
||||||
data.machines={};
|
data.machines={};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Parser
|
// Parser
|
||||||
var parseGetMachinesAnswer=function(response, failedToSendRequest){
|
var parseGetMachinesAnswer=function(response, failedToSendRequest){
|
||||||
|
|
||||||
|
@ -15,9 +16,16 @@ mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){
|
||||||
|
|
||||||
// Get Machine
|
// Get Machine
|
||||||
var getMachines=function(callback){
|
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',
|
var result=$http.post('../server/index.php',
|
||||||
$.param({"token" : Identity.getToken(), "task" : "compute", "action":"getServer", serverId:"69d5bcc4-2fab-4634-b0d2-f455fee5b7bd"}));
|
$.param(params));
|
||||||
|
|
||||||
// Wait and handle the response
|
// Wait and handle the response
|
||||||
result.then(function (response){
|
result.then(function (response){
|
||||||
|
@ -25,7 +33,7 @@ mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){
|
||||||
callback(parseGetMachinesAnswer(response, false));
|
callback(parseGetMachinesAnswer(response, false));
|
||||||
},function(response){
|
},function(response){
|
||||||
alert(response.status);
|
alert(response.status);
|
||||||
callback(parseGetMachinesAnswer(response, true));
|
callback(parseGetMachinesAnswer(response, true));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,42 +9,37 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
|
||||||
profile.projectname=null;
|
profile.projectname=null;
|
||||||
var token=null;
|
var token=null;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @returns {boolean} Return true if a cookie is found (and load it in profile) false else
|
* @returns {boolean} Return true if a cookie is found (and load it in profile) false else
|
||||||
*/
|
*/
|
||||||
var isAlreadyLogin=function(){
|
var isAlreadyLogin=function(){
|
||||||
|
|
||||||
|
// Load cookies
|
||||||
var profileInCookie=$cookies.getObject('profile');
|
var profileInCookie=$cookies.getObject('profile');
|
||||||
var tokenPart_0InCookie=$cookies.getObject('token.part_0');
|
var tokenPart_0InCookie=$cookies.getObject('token.part_0');
|
||||||
var tokenPart_1InCookie=$cookies.getObject('token.part_1');
|
var tokenPart_1InCookie=$cookies.getObject('token.part_1');
|
||||||
|
|
||||||
|
|
||||||
|
// Check if cookie is defined
|
||||||
if(typeof profileInCookie !== 'undefined'
|
if(typeof profileInCookie !== 'undefined'
|
||||||
&& typeof tokenPart_0InCookie !== 'undefined'
|
&& typeof tokenPart_0InCookie !== 'undefined'
|
||||||
&& typeof tokenPart_1InCookie !== 'undefined'
|
&& typeof tokenPart_1InCookie !== 'undefined'
|
||||||
){
|
){
|
||||||
|
|
||||||
|
// If yes, put it into variables
|
||||||
angular.extend(profile, profileInCookie);
|
angular.extend(profile, profileInCookie);
|
||||||
token=tokenPart_0InCookie+tokenPart_1InCookie;
|
token=tokenPart_0InCookie+tokenPart_1InCookie;
|
||||||
|
|
||||||
|
// Return I'm Login
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return I'm not Login
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get the profile
|
|
||||||
*/
|
|
||||||
var getProfile=function(){
|
|
||||||
return profile;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get the token
|
|
||||||
*/
|
|
||||||
var getToken=function(){
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Destroy profile cookies
|
* Destroy profile cookies
|
||||||
|
@ -64,7 +59,7 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
|
||||||
*/
|
*/
|
||||||
var parseLoginAnswer=function(response, failedToSendRequest){
|
var parseLoginAnswer=function(response, failedToSendRequest){
|
||||||
|
|
||||||
|
// Defined return object
|
||||||
var requestParserResult={};
|
var requestParserResult={};
|
||||||
requestParserResult.status=1;
|
requestParserResult.status=1;
|
||||||
requestParserResult.failReason=null;
|
requestParserResult.failReason=null;
|
||||||
|
@ -96,6 +91,7 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
|
||||||
|
|
||||||
return requestParserResult;
|
return requestParserResult;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to connect to OpenStack
|
* Function to connect to OpenStack
|
||||||
|
@ -113,7 +109,7 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
|
||||||
profile.projectname=projectname;
|
profile.projectname=projectname;
|
||||||
|
|
||||||
var result=$http.post('../server/index.php',
|
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
|
// Wait and handle the response
|
||||||
result.then(function (response){
|
result.then(function (response){
|
||||||
|
@ -124,6 +120,20 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the profile
|
||||||
|
*/
|
||||||
|
var getProfile=function(){
|
||||||
|
return profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the token
|
||||||
|
*/
|
||||||
|
var getToken=function(){
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Return services objects
|
// Return services objects
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Add table
Reference in a new issue