summaryrefslogtreecommitdiff
path: root/client/js
diff options
context:
space:
mode:
authorroot <root@kabir-PC>2016-03-02 15:11:56 +0100
committerroot <root@kabir-PC>2016-03-02 15:11:56 +0100
commitdac5c28a6795984a32687fe21c41783de2e85d8b (patch)
treebb5b719f923b33e31d5a0880d1d50dbe49543e45 /client/js
parent70fcf3553abb4a25672ee198dafb89e430e2bd79 (diff)
parentb6d7d2c30efe5e9758072bb82ea3a947bda7fd1d (diff)
Merge branch 'develop' of https://github.com/manzerbredes/istic-openstack into othmane
Diffstat (limited to 'client/js')
-rw-r--r--client/js/controllers/home/machineDetails.js41
-rw-r--r--client/js/controllers/home/main.js31
-rw-r--r--client/js/controllers/login.js9
-rw-r--r--client/js/controllers/status.js6
-rw-r--r--client/js/services/Compute.js127
-rw-r--r--client/js/services/Identity.js92
-rw-r--r--client/js/services/Loading.js22
7 files changed, 281 insertions, 47 deletions
diff --git a/client/js/controllers/home/machineDetails.js b/client/js/controllers/home/machineDetails.js
new file mode 100644
index 0000000..24fac42
--- /dev/null
+++ b/client/js/controllers/home/machineDetails.js
@@ -0,0 +1,41 @@
+/**
+ * The home controller
+ *
+ * @param {$scope} $scope The $scope service from angular
+ */
+mainApp.controller('machineDetailsCtrl', [ '$scope', 'Compute', '$rootScope', '$timeout', function ($scope, Compute, $rootScope, $timeout)
+{
+
+ $scope.machine={};
+ $("#waitingForToggleMachine").hide();
+
+ $scope.$on('showMachineDetailsEvent', function(eventName ,machine, axioms){
+ $scope.machine=machine;
+ $scope.axioms=axioms;
+ console.log(machine);
+ $('#machineDetailsModal').modal({backdrop: false, keyboard: true});
+ });
+
+
+ $scope.toggleMachineState=function(){
+ $("#waitingForToggleMachine").show();
+
+ // Fake timeout
+ $timeout(function(){
+ $("#waitingForToggleMachine").hide();
+ }, 3000);
+ $timeout(function(){
+ $scope.machine.online=!$scope.machine.online;
+
+ }, 3000);
+
+
+ };
+
+ $scope.applyModifications=function(){
+ //Todo
+ }
+
+
+
+}]);
diff --git a/client/js/controllers/home/main.js b/client/js/controllers/home/main.js
index d25bfad..f84f625 100644
--- a/client/js/controllers/home/main.js
+++ b/client/js/controllers/home/main.js
@@ -3,15 +3,34 @@
*
* @param {$scope} $scope The $scope service from angular
*/
-mainApp.controller('homeCtrl', [ '$scope', 'Compute', function ($scope, Compute)
+mainApp.controller('homeCtrl', [ '$scope', 'Compute', '$rootScope', 'Loading','Identity', function ($scope, Compute, $rootScope, Loading, Identity)
{
+ var callMeAfterPullData=function(data){
+ $scope.machines=Compute.getData().machines;
+ Loading.stop();
+ }
- var updatePage=function(){
- // TODO Update graph etc...
+ ;
+ if(Compute.getData().machines == null && Identity.isAlreadyLogin()){
+ Loading.start();
+ Compute.pullData(callMeAfterPullData);
}
- // Retrieve all Data
- Compute.pullData(updatePage);
-
+
+
+
+ $scope.raiseShowMachineDetailsEvent=function(id){
+
+ var callback=function(){
+ Loading.stop();
+ var data=Compute.getData();
+ $rootScope.$broadcast("showMachineDetailsEvent", data.machines[id], data.axioms);
+
+ }
+ Loading.start();
+ Compute.pullMachines(callback);
+ }
+
+
}]);
diff --git a/client/js/controllers/login.js b/client/js/controllers/login.js
index 829fc1d..1a89563 100644
--- a/client/js/controllers/login.js
+++ b/client/js/controllers/login.js
@@ -13,14 +13,19 @@ mainApp.controller('loginCtrl', ['$scope','$sce','Identity', function ($scope,$s
if(!Identity.isAlreadyLogin()){
$('#loginModal').modal({backdrop: 'static', keyboard: false});
}
+
+ // Manager logout event
$scope.$on('logoutEvent', function(){
+ Identity.logout();
$('#loginModal').modal({backdrop: 'static', keyboard: false});
});
-
+
+ // Hide loading button and message alert
$('#loadingLoginButton').hide();
$('#failedToLoginAlert').hide();
-
+
+ // Defined function for login
$scope.loginAction=function(){
// Begin login state for template
diff --git a/client/js/controllers/status.js b/client/js/controllers/status.js
index e01df34..940d794 100644
--- a/client/js/controllers/status.js
+++ b/client/js/controllers/status.js
@@ -10,13 +10,11 @@ mainApp.controller('statusCtrl', ['$scope','Identity', '$rootScope', function ($
{
// Give profile to model
- $scope.profile=Identity.profile;
+ $scope.profile=Identity.getProfile();
// Function to logout
- $scope.logout=function(){
- Identity.logout();
+ $scope.raiseLogoutEvent=function(){
$rootScope.$broadcast('logoutEvent');
-
};
}]);
diff --git a/client/js/services/Compute.js b/client/js/services/Compute.js
index c5c8da9..36ddc16 100644
--- a/client/js/services/Compute.js
+++ b/client/js/services/Compute.js
@@ -2,38 +2,139 @@
mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){
-
+ // 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){
+ /**
+ * 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({"token" : Identity.profile.token, "task" : "Compute"}));
+ $.param({"token" : Identity.getToken(), "task" : "compute", "action":"listServers"}));
+
+ // Wait and handle the response
+ result.then(function (response){
+ callback(parsePullMachinesAnswer(response, false));
+ },function(response){
+ 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
- pullData: pullData
- data:data
+ pullMachines: pullMachines,
+ pullData: pullData,
+ getData: getData
};
diff --git a/client/js/services/Identity.js b/client/js/services/Identity.js
index 8ee664c..da85ecd 100644
--- a/client/js/services/Identity.js
+++ b/client/js/services/Identity.js
@@ -7,37 +7,50 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
var profile={};
profile.username=null;
profile.projectname=null;
- profile.token=null;
-
-
- /**
- * Save profile in cookies
- */
- var saveCookieForSession=function(){
- $cookies.putObject('profile', 5);
- };
-
+ 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');
- console.log(profileInCookie);
+ var tokenPart_0InCookie=$cookies.getObject('token.part_0');
+ var tokenPart_1InCookie=$cookies.getObject('token.part_1');
+
- if(typeof profileInCookie !== 'undefined'){
+ // 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;
}
+
+
/*
* Destroy profile cookies
*/
var logout=function(){
$cookies.remove('profile');
+ $cookies.remove('token.part_0');
+ $cookies.remove('token.part_1');
+ token=null;
+ profile.username=null;
+ profile.projectname=null;
}
@@ -49,15 +62,32 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
*/
var parseLoginAnswer=function(response, failedToSendRequest){
-
+ // Defined return object
var requestParserResult={};
requestParserResult.status=1;
requestParserResult.failReason=null;
if (typeof response.data.token !== 'undefined') {
+ // Set status code
requestParserResult.status=0;
- profile.token=response.data.token;
- saveCookieForSession();
+
+ // Find the middle of the token to split it
+ var middle=parseInt(response.data.token.length/2);
+
+ // Create expire date (cookie expire in 55 mins)
+ var expireDate=new Date();
+ expireDate.setMinutes(expireDate.getMinutes()+55);
+
+ // Save profile
+ $cookies.putObject('profile', profile, {'expires': expireDate});
+ // Save first part of token
+ $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";
@@ -69,7 +99,6 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
return requestParserResult;
};
-
/**
* Function to connect to OpenStack
@@ -80,31 +109,50 @@ 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;
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 {
login: login,
- profile: profile,
+ getProfile: getProfile,
isAlreadyLogin: isAlreadyLogin,
- logout:logout
+ logout:logout,
+ getToken:getToken
};
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
+ };
+
+
+}]);