summaryrefslogtreecommitdiff
path: root/client/js/services
diff options
context:
space:
mode:
authorroot <root@kabir-PC>2016-02-23 20:34:59 +0100
committerroot <root@kabir-PC>2016-02-23 20:34:59 +0100
commitd2f5ae5c83ef5bc41cf430ace79769459b4acbf8 (patch)
treeb48882db52687bdd64a398c7d1844d05dbc01343 /client/js/services
parent1eff9ee90bf26127463cae0ae2cb2e1951527591 (diff)
parentff1832adcfe10fadb6cbf738c874611f77f6dd43 (diff)
Merge branch 'develop' of https://github.com/manzerbredes/istic-openstack into othmane
Diffstat (limited to 'client/js/services')
-rw-r--r--client/js/services/Compute.js40
-rw-r--r--client/js/services/Identity.js111
-rw-r--r--client/js/services/Image.js28
3 files changed, 179 insertions, 0 deletions
diff --git a/client/js/services/Compute.js b/client/js/services/Compute.js
new file mode 100644
index 0000000..c5c8da9
--- /dev/null
+++ b/client/js/services/Compute.js
@@ -0,0 +1,40 @@
+
+mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){
+
+
+
+ var data={};
+ data.machines={};
+
+
+ // Parser
+ var parseGetMachinesAnswer=function(response, failedToSendRequest){
+
+ };
+
+
+ // Get Machine
+ var getMachines=function(callback){
+
+ var result=$http.post('../server/index.php',
+ $.param({"token" : Identity.profile.token, "task" : "Compute"}));
+
+
+ };
+
+
+
+ var pullData=function(callback){
+ // TODO call getMachines etc...
+ }
+
+
+ // Return services objects
+ return {
+ getMachines: getMachines
+ pullData: pullData
+ data:data
+ };
+
+
+}]);
diff --git a/client/js/services/Identity.js b/client/js/services/Identity.js
new file mode 100644
index 0000000..8ee664c
--- /dev/null
+++ b/client/js/services/Identity.js
@@ -0,0 +1,111 @@
+
+mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){
+
+ /* Create profile structure to store informations
+ * about current session
+ */
+ var profile={};
+ profile.username=null;
+ profile.projectname=null;
+ profile.token=null;
+
+
+ /**
+ * Save profile in cookies
+ */
+ var saveCookieForSession=function(){
+ $cookies.putObject('profile', 5);
+ };
+
+
+ /*
+ * @returns {boolean} Return true if a cookie is found (and load it in profile) false else
+ */
+ var isAlreadyLogin=function(){
+ var profileInCookie=$cookies.getObject('profile');
+ console.log(profileInCookie);
+
+ if(typeof profileInCookie !== 'undefined'){
+ angular.extend(profile, profileInCookie);
+ return true;
+ }
+
+ return false;
+ }
+
+ /*
+ * Destroy profile cookies
+ */
+ var logout=function(){
+ $cookies.remove('profile');
+ }
+
+
+ /**
+ *
+ * @param {string} response The response to parse
+ * @param {boolean} to check if the request is send or not
+ * @returns {requestParserResult} Formated data
+ */
+ var parseLoginAnswer=function(response, failedToSendRequest){
+
+
+ var requestParserResult={};
+ requestParserResult.status=1;
+ requestParserResult.failReason=null;
+
+ if (typeof response.data.token !== 'undefined') {
+ requestParserResult.status=0;
+ profile.token=response.data.token;
+ saveCookieForSession();
+ }
+ else if(failedToSendRequest){
+ requestParserResult.failReason="Failed to send request";
+ }
+ else{
+ requestParserResult.failReason="Please check your username, password and project name !";
+ }
+
+ return requestParserResult;
+ };
+
+
+
+ /**
+ * Function to connect to OpenStack
+ *
+ * @param {object} $http Angular $http service
+ * @param {string} username The user name
+ * @param {string} password The user password
+ * @param {string} projectname The user project name
+ * @param {function} function to call when data is avalaible
+ */
+ 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}));
+
+ // Wait and handle the response
+ result.then(function (response){
+ callback(parseLoginAnswer(response), false);
+ },function(response){
+ callback(parseLoginAnswer(response), true)
+ });
+ };
+
+
+
+ // Return services objects
+ return {
+ login: login,
+ profile: profile,
+ isAlreadyLogin: isAlreadyLogin,
+ logout:logout
+ };
+
+
+}]);
diff --git a/client/js/services/Image.js b/client/js/services/Image.js
new file mode 100644
index 0000000..23b33a8
--- /dev/null
+++ b/client/js/services/Image.js
@@ -0,0 +1,28 @@
+
+mainApp.factory('Image',[ '$http', 'Identity', function($http, Identity){
+
+
+
+ var parseUploadImageAnswer=function(response, failedToSendRequest){
+
+ };
+
+
+ var getImages=function(callback){
+
+ var result=$http.post('../server/index.php',
+ $.param({"token" : Identity.profile.token, "task" : "Image"}));
+
+
+
+ };
+
+
+
+ // Return services objects
+ return {
+ uploadImage: uploadImage
+ };
+
+
+}]);