diff options
| -rw-r--r-- | client/Test/index.html | 18 | ||||
| -rw-r--r-- | client/index.html | 44 | ||||
| -rw-r--r-- | client/js/app.js | 2 | ||||
| -rwxr-xr-x | client/js/controllers/home/home.js | 104 | ||||
| -rw-r--r-- | client/js/controllers/home/machineDetails.js | 55 | ||||
| -rw-r--r-- | client/js/controllers/image/image.js | 34 | ||||
| -rw-r--r-- | client/js/controllers/image/upload.js | 106 | ||||
| -rw-r--r-- | client/js/controllers/login.js | 97 | ||||
| -rw-r--r-- | client/js/controllers/network/network.js | 1 | ||||
| -rw-r--r-- | client/js/controllers/status.js | 20 | ||||
| -rw-r--r-- | client/js/services/Compute.js | 285 | ||||
| -rw-r--r-- | client/js/services/Identity.js | 336 | ||||
| -rw-r--r-- | client/js/services/Image.js | 214 | ||||
| -rw-r--r-- | client/js/services/Loading.js | 45 | ||||
| -rw-r--r-- | client/js/services/Network.js | 50 | ||||
| -rw-r--r-- | client/partials/home/home.html | 11 | ||||
| -rw-r--r-- | client/partials/image/upload.html | 13 | ||||
| -rwxr-xr-x | server/core/Image.php | 2 |
18 files changed, 721 insertions, 716 deletions
diff --git a/client/Test/index.html b/client/Test/index.html index 147745c..bff3ee1 100644 --- a/client/Test/index.html +++ b/client/Test/index.html @@ -1,19 +1,19 @@ <head> -<script src="../vendors/angularjs/angular.min.js"></script> + <script src="../vendors/angularjs/angular.min.js"></script> <script src="../vendors/angularjs/angular-route.min.js"></script> <script src="../vendors/angularjs/angular-sanitize.min.js"></script> <script src="../vendors/angularjs/angular-cookies.min.js"></script> - <script src="../js/services/Test.js"></script> + <script src="../js/services/Test.js"></script> <script src="../js/app.js"></script> </head> <body ng-app="mainApp"> - <div ng-controller="hassan"> - <ul> - <li ng-repeat="person in persons"> - {{person.Name + ' : ' + person.Age}} - </li> - </ul> - </div> + <div ng-controller="hassan"> + <ul> + <li ng-repeat="person in persons"> + {{person.Name + ' : ' + person.Age}} + </li> + </ul> + </div> </body> diff --git a/client/index.html b/client/index.html index 97e0734..45bee7f 100644 --- a/client/index.html +++ b/client/index.html @@ -11,27 +11,27 @@ <link rel="stylesheet" href="./css/style.css"> - <!--[if lt IE 9]> - <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> - <![endif]--> + <!--[if lt IE 9]> + <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> + <![endif]--> </head> - - + + <body> - <!-- Overlay --> + <!-- Overlay --> <div ng-include="'./partials/login.html'"></div> <div ng-include="'./partials/home/machineDetails.html'"></div> - <div ng-include="'./partials/loading.html'"></div> -<div ng-include="'./partials/image/upload.html'"></div> + <div ng-include="'./partials/loading.html'"></div> + <div ng-include="'./partials/image/upload.html'"></div> + - <!-- MAIN GRID --> <div class="container-lg"> <!-- Status bar --> <div class="row" ng-controller="statusCtrl"> <div class="col-lg-12"> - <!-- Status bar --> + <!-- Status bar --> <div ng-include="'./partials/status.html'"></div> </div> </div> @@ -57,45 +57,45 @@ </div> </div> </div> - </div> + </div> </div> </div> </div> </body> - - + + <!-- Include JQuery --> <script src="./vendors/jquery/jquery-2.2.0.min.js"></script> - <script src="./vendors/jquery/dmuploader.min.js"></script> + <script src="./vendors/jquery/dmuploader.min.js"></script> <!-- Include Bootstrap --> <script src="./vendors/bootstrap/js/bootstrap.min.js"></script> - + <!-- Include AngularJS and dependencies--> <script src="./vendors/angularjs/angular.min.js"></script> <script src="./vendors/angularjs/angular-route.min.js"></script> <script src="./vendors/angularjs/angular-sanitize.min.js"></script> <script src="./vendors/angularjs/angular-cookies.min.js"></script> - <script src="./vendors/angularjs/angular-upload.min.js"></script> + <script src="./vendors/angularjs/angular-upload.min.js"></script> <script src="./js/app.js"></script> - + <!-- Include services --> <script src="./js/services/Identity.js"></script> <script src="./js/services/Image.js"></script> <script src="./js/services/Compute.js"></script> <script src="./js/services/Loading.js"></script> - + <!-- Include controller --> <script src="./js/controllers/login.js"></script> <script src="./js/controllers/status.js"></script> <script src="./js/controllers/home/home.js"></script> <script src="./js/controllers/home/machineDetails.js"></script> <script src="./js/controllers/network/network.js"></script> - <script src="./js/controllers/image/image.js"></script> - <script src="./js/controllers/image/upload.js"></script> + <script src="./js/controllers/image/image.js"></script> + <script src="./js/controllers/image/upload.js"></script> + + - - diff --git a/client/js/app.js b/client/js/app.js index e911050..4ef35b5 100644 --- a/client/js/app.js +++ b/client/js/app.js @@ -25,7 +25,7 @@ mainApp.config(['$routeProvider', function($routeProvider){ controller: 'imageCtrl' }) .otherwise({ - redirectTo: '/' + redirectTo: '/home' }); }]); diff --git a/client/js/controllers/home/home.js b/client/js/controllers/home/home.js index 10142c9..7880e12 100755 --- a/client/js/controllers/home/home.js +++ b/client/js/controllers/home/home.js @@ -3,58 +3,52 @@ * * @param {$scope} $scope The $scope service from angular */ -mainApp.controller('homeCtrl', [ '$scope', 'Compute', '$rootScope', 'Loading','Identity', 'Image', function ($scope, Compute, $rootScope, Loading, Identity, Image) -{ - - var callMeAfterPullData=function(data){ - console.log(data); - $scope.machines=Compute.getData().machines; - Loading.stop(); - } - - ; - if(Compute.getData().machines == null && Identity.isAlreadyLogin()){ - Loading.start(); - Compute.pullData(callMeAfterPullData); - } - else{ - if(Identity.isAlreadyLogin()){ - callMeAfterPullData(); - } - } - - - Image.getImages(function(){}); - - - - $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); - } - - - - - - if(Identity.isAlreadyLogin()){ - if(Compute.getData().machines == null){ - Loading.start(); - Compute.pullData(callMeAfterPullData); - } - else{ - if(Identity.isAlreadyLogin()){ - callMeAfterPullData(); - } - } - Image.getImages(function(){}); - } - -}]); +mainApp.controller('homeCtrl', ['$scope', 'Compute', '$rootScope', 'Loading', 'Identity', 'Image', function ($scope, Compute, $rootScope, Loading, Identity, Image) + { + + // Function to call after pull all data about machines + var callMeAfterPullData = function (data) { + $scope.machines = Compute.getData().machines; + Loading.stop(); + }; + + // Function to call to try to retrieve data and update the view + var tryToRetrieveData = function () { + // If no data retrieve about machine and user is logged + if (Compute.getData().machines == null && Identity.isAlreadyLogin()) { + Loading.start(); // Show loading gif + Compute.pullData(callMeAfterPullData); // Retrieve data and call the callback + } else { + // Else if user is logged and data is already retrieve + // simply display data + if (Identity.isAlreadyLogin()) { + callMeAfterPullData(); // Display data + } + } + }; + + + // On user login + $scope.$on('loginEvent', function () { + tryToRetrieveData(); + }); + + + + // Function to call from view to display the details of a machine + $scope.raiseShowMachineDetailsEvent = function (id) { + + // Stop loading gif and display overlay + var callback = function () { + Loading.stop(); + var data = Compute.getData(); + $rootScope.$broadcast("showMachineDetailsEvent", data.machines[id], data.axioms); + + }; + Loading.start(); // Show loading gif + Compute.pullMachines(callback); // Retrieve machine info and display overlay + }; + + // Try to retrieve data for the first time + tryToRetrieveData(); + }]); diff --git a/client/js/controllers/home/machineDetails.js b/client/js/controllers/home/machineDetails.js index 371310b..9c8c602 100644 --- a/client/js/controllers/home/machineDetails.js +++ b/client/js/controllers/home/machineDetails.js @@ -3,42 +3,43 @@ * * @param {$scope} $scope The $scope service from angular */ -mainApp.controller('machineDetailsCtrl', [ '$scope', 'Compute', '$rootScope', '$timeout', 'Identity', function ($scope, Compute, $rootScope, $timeout, Identity) -{ +mainApp.controller('machineDetailsCtrl', ['$scope', 'Compute', '$rootScope', '$timeout', 'Identity', function ($scope, Compute, $rootScope, $timeout, Identity) + { - // Init scope - $scope.machine={}; - $scope.machineIsStarting=false; // For loading icon + // Init scope + $scope.machine = {}; + $scope.machineIsStarting = false; // For loading icon + // When we need to show details of machine + $scope.$on('showMachineDetailsEvent', function (eventName, machine, axioms) { + $scope.machine = machine; + $scope.axioms = axioms; + $('#machineDetailsModal').modal({backdrop: false, keyboard: true}); + }); - $scope.$on('showMachineDetailsEvent', function(eventName ,machine, axioms){ - $scope.machine=machine; - $scope.axioms=axioms; - $('#machineDetailsModal').modal({backdrop: false, keyboard: true}); - }); + // Try to stop or start a machine + $scope.toggleMachineState = function () { + // Display gif + $scope.machineIsStarting = true; + // Fake timeout + $timeout(function () { + $scope.machineIsStarting = false; + }, 3000); + $timeout(function () { + $scope.machine.online = !$scope.machine.online; - $scope.toggleMachineState=function(){ - // Display gif - $scope.machineIsStarting=true; + }, 3000); - // Fake timeout - $timeout(function(){ - $scope.machineIsStarting=false; - }, 3000); - $timeout(function(){ - $scope.machine.online=!$scope.machine.online; - }, 3000); + }; - - }; + // Apply modifications + $scope.applyModifications = function () { + //Todo + }; - $scope.applyModifications=function(){ - //Todo - } - -}]); + }]); diff --git a/client/js/controllers/image/image.js b/client/js/controllers/image/image.js index d9a9c06..d0578d7 100644 --- a/client/js/controllers/image/image.js +++ b/client/js/controllers/image/image.js @@ -4,23 +4,21 @@ * @param {$scope} $scope The $scope service from angular */ mainApp.controller('imageCtrl', ['$scope', 'Image', 'Loading', 'Identity', function ($scope, Image, Loading, Identity) -{ + { - var callbackTest=function(){ - $scope.images=Image.getData().images; - Loading.stop(); - }; + // Update view + var callMeAfterGetImage = function () { + $scope.images = Image.getData().images; + Loading.stop(); + }; - - if(Identity.isAlreadyLogin()){ - - if(Image.getData().images==null){ - Loading.start(); - Image.getImages(callbackTest); - } - else{ - callbackTest(); - } - - } -}]); + // If user is login try to retrieve data + if (Identity.isAlreadyLogin()) { + if (Image.getData().images == null) { + Loading.start(); + Image.getImages(callMeAfterGetImage); + } else { + callMeAfterGetImage(); + } + } + }]); diff --git a/client/js/controllers/image/upload.js b/client/js/controllers/image/upload.js index eca9406..6737269 100644 --- a/client/js/controllers/image/upload.js +++ b/client/js/controllers/image/upload.js @@ -3,58 +3,60 @@ * * @param {$scope} $scope The $scope service from angular */ -mainApp.controller('uploadImageCtrl', ['$scope', 'Image', 'Loading', 'Identity', 'upload', function ($scope, Image, Loading, Identity,upload) -{ +mainApp.controller('uploadImageCtrl', ['$scope', 'Image', 'Loading', 'Identity', 'upload', function ($scope, Image, Loading, Identity, upload) + { /*$scope.uploader = new FileUploader({ - "token" : Identity.getToken(), - "task" : "image", - 'action':'uploadImage', - 'id':'6564' - }); - $scope.uploader.url='../server/index.php' - $scope.uploader.alias='file_name' - $scope.uploader.formData={ - "token" : Identity.getToken(), - "task" : "image", - 'action':'uploadImage', - 'id':'6564' - } - */ + "token" : Identity.getToken(), + "task" : "image", + 'action':'uploadImage', + 'id':'6564' + }); + $scope.uploader.url='../server/index.php' + $scope.uploader.alias='file_name' + $scope.uploader.formData={ + "token" : Identity.getToken(), + "task" : "image", + 'action':'uploadImage', + 'id':'6564' + } + */ - $scope.doUpload = function () { - console.log($('#imageToUpload').prop('files')[0]); - Image.uploadImage($('#imageToUpload').prop('files')[0], function(){alert("done")}) - /*$("#drop-area-div").dmUploader({ - extraData: { - "token" : Identity.getToken(), - "task" : "image", - 'action':'uploadImage', - 'id':'6564'}, - url:"../server/index.php" - }); - */ - - /*upload({ - url: '../server/index.php', - method: 'POST', - data: { - "token" : Identity.getToken(), - "task" : "image", - 'action':'uploadImage', - 'id':'6564', - "file_name": $scope.myFile, // a jqLite type="file" element, upload() will extract all the files from the input and put them into the FormData object before sending. - } - }).then( - function (response) { - console.log(response.data); // will output whatever you choose to return from the server on a successful upload - }, - function (response) { - console.error(response); // Will return if status code is above 200 and lower than 300, same as $http - } - );*/ - - - }; - + $scope.doUpload = function () { + console.log($('#imageToUpload').prop('files')[0]); + Image.uploadImage($('#imageToUpload').prop('files')[0], function () { + alert("done") + }) + /*$("#drop-area-div").dmUploader({ + extraData: { + "token" : Identity.getToken(), + "task" : "image", + 'action':'uploadImage', + 'id':'6564'}, + url:"../server/index.php" + }); + */ -}]); + /*upload({ + url: '../server/index.php', + method: 'POST', + data: { + "token" : Identity.getToken(), + "task" : "image", + 'action':'uploadImage', + 'id':'6564', + "file_name": $scope.myFile, // a jqLite type="file" element, upload() will extract all the files from the input and put them into the FormData object before sending. + } + }).then( + function (response) { + console.log(response.data); // will output whatever you choose to return from the server on a successful upload + }, + function (response) { + console.error(response); // Will return if status code is above 200 and lower than 300, same as $http + } + );*/ + + + }; + + $scope.token = Identity.getToken(); + }]); diff --git a/client/js/controllers/login.js b/client/js/controllers/login.js index fed358d..4a0de42 100644 --- a/client/js/controllers/login.js +++ b/client/js/controllers/login.js @@ -5,62 +5,63 @@ * @param {$sce} $sce The $sce angular service * @param {$http} $http The $http angular service * @param {Identity} The Identity service - + */ -mainApp.controller('loginCtrl', ['$scope','$sce','Identity', function ($scope,$sce, Identity) -{ - // Check for login and define default states - if(!Identity.isAlreadyLogin()){ - $('#loginModal').modal({backdrop: 'static', keyboard: false}); - } +mainApp.controller('loginCtrl', ['$scope', '$sce', 'Identity', '$rootScope', function ($scope, $sce, Identity, $rootScope) + { + // Check for login and define default states + if (!Identity.isAlreadyLogin()) { + $('#loginModal').modal({backdrop: 'static', keyboard: false}); + } - // Manager logout event - $scope.$on('logoutEvent', function(){ - $('#loginModal').modal({backdrop: 'static', keyboard: false}); - }); + // Manager logout event + $scope.$on('logoutEvent', function () { + $('#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 - $('#loginButton').hide(); - $('#loadingLoginButton').show(); + // Hide loading button and message alert + $('#loadingLoginButton').hide(); $('#failedToLoginAlert').hide(); - // Get data from templates - var username=$("#loginFormUsername").val(); - var password=$("#loginFormPassword").val(); - var projectname=$("#loginFormProjectname").val(); - // Function to call to handle result - var responseCallback=function(response){ + // Defined function for login + $scope.loginAction = function () { + + // Begin login state for template + $('#loginButton').hide(); + $('#loadingLoginButton').show(); + $('#failedToLoginAlert').hide(); + + // Get data from templates + var username = $("#loginFormUsername").val(); + var password = $("#loginFormPassword").val(); + var projectname = $("#loginFormProjectname").val(); + + // Function to call to handle result + var responseCallback = function (response) { + + if (response.status !== 0) { + // Set reason of fail + $scope.failReason = response.failReason; + + // Display the error + $('#failedToLoginAlert').show(); + } else { + // Else the user is online ! + $('#loginModal').modal('hide'); + // Send login event + $rootScope.$broadcast("loginEvent"); + } - if(response.status!==0){ - // Set reason of fail - $scope.failReason=response.failReason; + // Reset button state + $('#loginButton').show(); + $('#loadingLoginButton').hide(); + }; - // Display the error - $('#failedToLoginAlert').show(); - } - else { - // Else the user is online ! - $('#loginModal').modal('hide'); - } + // Try to login + Identity.login(username, password, projectname, responseCallback); + }; - // Reset button state - $('#loginButton').show(); - $('#loadingLoginButton').hide(); - } - - // Try to login - Identity.login(username, password, projectname, responseCallback); - }; - -}]); + }]); diff --git a/client/js/controllers/network/network.js b/client/js/controllers/network/network.js index 7264aec..f600f83 100644 --- a/client/js/controllers/network/network.js +++ b/client/js/controllers/network/network.js @@ -5,4 +5,5 @@ */ mainApp.controller('networkCtrl', function ($scope) { + });
\ No newline at end of file diff --git a/client/js/controllers/status.js b/client/js/controllers/status.js index 15850f4..c3e634b 100644 --- a/client/js/controllers/status.js +++ b/client/js/controllers/status.js @@ -6,16 +6,14 @@ * @param {$scope} $scope The $scope service from angular * @param {Identity} The Identity service */ -mainApp.controller('statusCtrl', ['$scope','Identity', '$rootScope', function ($scope, Identity, $rootScope) -{ +mainApp.controller('statusCtrl', ['$scope', 'Identity', '$rootScope', function ($scope, Identity, $rootScope) + { + // Give profile to model + $scope.profile = Identity.getProfile(); - - // Give profile to model - $scope.profile=Identity.getProfile(); - - // Function to logout - $scope.logout=function(){ - Identity.logout(); - }; + // Function to logout + $scope.logout = function () { + Identity.logout(); + }; -}]); + }]); diff --git a/client/js/services/Compute.js b/client/js/services/Compute.js index 2bf28d8..5e95f22 100644 --- a/client/js/services/Compute.js +++ b/client/js/services/Compute.js @@ -1,147 +1,140 @@ -mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){ - - - // Init data - var data={}; - 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 - - - /** - * 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 PullMachine request"; - } - else{ - requestParserResult.failReason="Error"; - } - return requestParserResult; - }; - - - /** - * 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.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 PullImage 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){ - alert(Identity.getToken()); - - 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){ - var nextFunction=function(response){ - if(response.status==0){ - pullMachines(callback); - } - else{ - callback(response); - } - } - pullImages(nextFunction); - } - - - /** - * Get Data - * @return {data} return the data object - */ - var getData=function(){ - return data; - } - - // Return services objects - return { - pullMachines: pullMachines, - pullData: pullData, - getData: getData - }; - - -}]); +mainApp.factory('Compute', ['$http', 'Identity', function ($http, Identity) { + + + // Init data + var data = {}; + 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 + + + /** + * 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 PullMachine request"; + } else { + requestParserResult.failReason = "Error"; + } + return requestParserResult; + }; + + + /** + * 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.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 PullImage 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) { + var nextFunction = function (response) { + if (response.status == 0) { + pullMachines(callback); + } else { + callback(response); + } + }; + pullImages(nextFunction); + }; + + + /** + * Get Data + * @return {data} return the data object + */ + var getData = function () { + return data; + }; + + // Return services objects + return { + pullMachines: pullMachines, + pullData: pullData, + getData: getData + }; + + + }]); diff --git a/client/js/services/Identity.js b/client/js/services/Identity.js index 73e5d86..17678ed 100644 --- a/client/js/services/Identity.js +++ b/client/js/services/Identity.js @@ -1,170 +1,168 @@ -mainApp.factory('Identity',[ '$http', '$cookies', '$rootScope', function($http, $cookies, $rootScope){ - - /* Create profile structure to store informations - * about current session - */ - var profile={}; - profile.username=null; - 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(token!==null){ - // If yes, put it into variables - angular.extend(profile, profileInCookie); - token=tokenPart_0InCookie+tokenPart_1InCookie; - //} - - // Return I'm Login - return true; - } - - // Show the login overlay - $rootScope.$broadcast("logoutEvent"); - - // 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; - - // Reload Page - //location.reload(); - $rootScope.$broadcast("logoutEvent"); - - } - - - /** - * - * @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){ - - // Defined return object - var requestParserResult={}; - requestParserResult.status=1; - requestParserResult.failReason=null; - - if (typeof response.data.token !== 'undefined') { - // Set status code - requestParserResult.status=0; - - // 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"; - } - 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)); - }); - }; - - - - - - /* - * Get the profile - */ - var getProfile=function(){ - return profile; - } - - /* - * Get the token - */ - var getToken=function(){ - return token; - } - - - - // Return services objects - return { - login: login, - getProfile: getProfile, - isAlreadyLogin: isAlreadyLogin, - logout:logout, - getToken:getToken - }; - - -}]); +mainApp.factory('Identity', ['$http', '$cookies', '$rootScope', function ($http, $cookies, $rootScope) { + + /* Create profile structure to store informations + * about current session + */ + var profile = {}; + profile.username = null; + 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(token!==null){ + // If yes, put it into variables + angular.extend(profile, profileInCookie); + token = tokenPart_0InCookie + tokenPart_1InCookie; + //} + + // Return I'm Login + return true; + } + + // Show the login overlay + $rootScope.$broadcast("logoutEvent"); + + // 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; + + // Reload Page + //location.reload(); + $rootScope.$broadcast("logoutEvent"); + + }; + + + /** + * + * @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) { + + // Defined return object + var requestParserResult = {}; + requestParserResult.status = 1; + requestParserResult.failReason = null; + + if (typeof response.data.token !== 'undefined') { + // Set status code + requestParserResult.status = 0; + + // 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"; + } 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)); + }); + }; + + + + + + /* + * Get the profile + */ + var getProfile = function () { + return profile; + }; + + /* + * Get the token + */ + var getToken = function () { + return token; + }; + + + + // Return services objects + return { + login: login, + getProfile: getProfile, + isAlreadyLogin: isAlreadyLogin, + logout: logout, + getToken: getToken + }; + + + }]); diff --git a/client/js/services/Image.js b/client/js/services/Image.js index d6c9fed..795f85e 100644 --- a/client/js/services/Image.js +++ b/client/js/services/Image.js @@ -1,102 +1,114 @@ -mainApp.factory('Image',[ '$http', 'Identity', function($http, Identity){ - - var data={}; - data.images=null; - - - var parseUploadImageAnswer=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.images=response.data.Images; - - } - else if(failedToSendRequest){ - requestParserResult.failReason="Failed to send request"; - } - else{ - requestParserResult.failReason="Error"; - } - return requestParserResult; - }; - - - var getImages=function(callback){ - - var result=$http.post('../server/index.php', - $.param({"token" : Identity.getToken(), "task" : "image", 'action':'listImage'})); - - // Wait and handle the response - result.then(function (response){ - callback(parseUploadImageAnswer(response, false)); - },function(response){ - callback(parseUploadImageAnswer(response, true)); - }); - - - }; - - var uploadImage=function(fileToUpload, callback) { - var form_data = new FormData(); - form_data.append('file', fileToUpload); - console.log(fileToUpload) - form_data.append("task" , "image") - form_data.append("token" , Identity.getToken()) - form_data.append('action',"uploadImage") - form_data.append('id','6564') - form_data.append('file_name', fileToUpload); - - $.ajax({ - url: "../server/index.php", // Url to which the request is send - type: "POST", // Type of request to be send, called as method - data: form_data, // Data sent to server, a set of key/value pairs (i.e. form fields and values) - file_name:fileToUpload, - token : Identity.getToken(), - task : "image", - action:'uploadImage', - id:'6564', - contentType: false, // The content type used when sending data to the server. - cache: false, // To unable request pages to be cached - processData:false, // To send DOMDocument or non processed data file it is set to false - success: function(data) // A function to be called if request succeeds - { - alert("success") - } - }); - - //var result=$http.post('../server/index.php', - // $.param({"token" : Identity.getToken(), "task" : "image", 'action':'uploadImage', 'file_name':form_data, 'id':'6564'})); - - // Wait and handle the response - /* result.then(function (response){ - callback(parseUploadImageAnswer(response, false)); - },function(response){ - callback(parseUploadImageAnswer(response, true)); - });*/ - - - - } - - - var getData=function(response){ - return data; - }; - - // Return services objects - return { - getImages:getImages, - getData:getData, - uploadImage:uploadImage - }; - - -}]); +mainApp.factory('Image', ['$http', 'Identity', function ($http, Identity) { + + // Data object + var data = {}; + data.images = null; // Images + + /** + * Parse uploadImage anwser + * @param {type} response + * @param {type} failedToSendRequest + * @returns {Image_L2.parseUploadImageAnswer.requestParserResult} + */ + var parseUploadImageAnswer = 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.images = response.data.Images; + + } else if (failedToSendRequest) { + requestParserResult.failReason = "Failed to send request"; + } else { + requestParserResult.failReason = "Error"; + } + return requestParserResult; + }; + + + /** + * Get images + * @param {type} callback + * @returns {undefined} + */ + var getImages = function (callback) { + + var result = $http.post('../server/index.php', + $.param({"token": Identity.getToken(), "task": "image", 'action': 'listImage'})); + + // Wait and handle the response + result.then(function (response) { + callback(parseUploadImageAnswer(response, false)); + }, function (response) { + callback(parseUploadImageAnswer(response, true)); + }); + + + }; + + /** + * Upload an image + * @param {type} fileToUpload + * @param {type} callback + * @returns {undefined} + */ + var uploadImage = function (fileToUpload, callback) { + var form_data = new FormData(); + form_data.append('file', fileToUpload); + console.log(fileToUpload); + form_data.append("task", "image"); + form_data.append("token", Identity.getToken()); + form_data.append('action', "uploadImage"); + form_data.append('id', '6564'); + form_data.append('file_name', fileToUpload); + + $.ajax({ + url: "../server/index.php", // Url to which the request is send + type: "POST", // Type of request to be send, called as method + data: form_data, // Data sent to server, a set of key/value pairs (i.e. form fields and values) + file_name: fileToUpload, + token: Identity.getToken(), + task: "image", + action: 'uploadImage', + id: '6564', + contentType: false, // The content type used when sending data to the server. + cache: false, // To unable request pages to be cached + processData: false, // To send DOMDocument or non processed data file it is set to false + success: function (data) // A function to be called if request succeeds + { + alert("success"); + } + }); + + //var result=$http.post('../server/index.php', + // $.param({"token" : Identity.getToken(), "task" : "image", 'action':'uploadImage', 'file_name':form_data, 'id':'6564'})); + + // Wait and handle the response + /* result.then(function (response){ + callback(parseUploadImageAnswer(response, false)); + },function(response){ + callback(parseUploadImageAnswer(response, true)); + });*/ + }; + + + var getData = function (response) { + return data; + }; + + // Return services objects + return { + getImages: getImages, + getData: getData, + uploadImage: uploadImage + }; + + + }]); diff --git a/client/js/services/Loading.js b/client/js/services/Loading.js index db06194..7ea2b42 100644 --- a/client/js/services/Loading.js +++ b/client/js/services/Loading.js @@ -1,23 +1,26 @@ +/** + * Loading service + * @param {type} param1 + * @param {type} param2 + */ +mainApp.factory('Loading', [function () { + /** + * Display Loading modal + */ + var start = function () { + $('#loadingModal').modal({backdrop: 'static', keyboard: false}); + }; -mainApp.factory('Loading',[ function(){ - /** - * Display Loading modal - */ - var start=function(){ - $('#loadingModal').modal({backdrop: 'static', keyboard: false}); - }; + /** + * Hide Loading modal + */ + var stop = function () { + $('#loadingModal').modal('hide'); + }; - /** - * Hide Loading modal - */ - var stop=function(){ - $('#loadingModal').modal('hide'); - } - - - // Service returns - return { - start:start, - stop:stop - }; -}]); + // Service returns + return { + start: start, + stop: stop + }; + }]); diff --git a/client/js/services/Network.js b/client/js/services/Network.js index bd2a24f..a0cd5a4 100644 --- a/client/js/services/Network.js +++ b/client/js/services/Network.js @@ -1,27 +1,29 @@ -mainApp.factory('Network',[ '$http', 'Identity', function($http, Identity){ - - var data={}; - data.networks=null; - -var ListId=function(fileToUpload, callback) { - - - var result=$http.post('../server/index.php', - $.param({"token" : Identity.getToken(), "task" : "network", 'action':'list_network_ids'})); - - // Wait and handle the response - result.then(function (response){ - callback(parseUploadImageAnswer(response, false)); - },function(response){ - callback(parseUploadImageAnswer(response, true)); - }); - - console.log(result) - - } - - -}]); +mainApp.factory('Network', ['$http', 'Identity', function ($http, Identity) { + + // Data object + var data = {}; + data.networks = null; // Networks + + /** + * ListId + * @param {type} fileToUpload + * @param {type} callback + * @returns {undefined} + */ + var ListId = function (fileToUpload, callback) { + var result = $http.post('../server/index.php', + $.param({"token": Identity.getToken(), "task": "network", 'action': 'list_network_ids'})); + + // Wait and handle the response + result.then(function (response) { + callback(parseUploadImageAnswer(response, false)); + }, function (response) { + callback(parseUploadImageAnswer(response, true)); + }); + }; + + + }]); diff --git a/client/partials/home/home.html b/client/partials/home/home.html index f9f8878..11958d2 100644 --- a/client/partials/home/home.html +++ b/client/partials/home/home.html @@ -1,12 +1,11 @@ - <div class="panel panel-default" ng-controller="homeCtrl"> +<div class="panel panel-default" ng-controller="homeCtrl"> <div class="panel-heading"> Home </div> <div class="panel-body"> - - Pour charger les machines, recharger la page (temporaire)<br /> - Selectionner une machine: - <div ng-repeat="machine in machines"> <a ng-click="raiseShowMachineDetailsEvent(machine.id)"> {{ machine.name }}</a></div> - + + Selectionner une machine: + <div ng-repeat="machine in machines"> <a ng-click="raiseShowMachineDetailsEvent(machine.id)"> {{ machine.name}}</a></div> + </div> </div> diff --git a/client/partials/image/upload.html b/client/partials/image/upload.html index 72a8e01..01c54b2 100644 --- a/client/partials/image/upload.html +++ b/client/partials/image/upload.html @@ -12,11 +12,14 @@ <div class="modal-body"> - - - Choose a file to upload: <input id="imageToUpload" name="uploaded_file" type="file" /> - <input type="submit" value="Upload" /> - + <form action="../server/index.php" method="post"> + <input type="hidden" name="task" value="image" /> + <input type="hidden" name="token" value="{{ token }}" /> + <input type="hidden" name="action" value="uploadImage" /> + <input type="hidden" name="id" value="2564" /> + <input name="file" type="file" /> + <input type="submit" value="Upload" /> + </form> <div class="modal-footer"> <!--<a href="#" data-dismiss="modal" class="btn btn-default">Close</a>--> diff --git a/server/core/Image.php b/server/core/Image.php index fdf4e3a..334fce4 100755 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -678,4 +678,4 @@ class image implements Core{ } } -?>
\ No newline at end of file +?> |
