From 3c336f00d29ba927d41e2029a3c1d893cee43f9d Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Mon, 21 Mar 2016 06:47:01 +0100 Subject: Add login check witouth reloading page --- client/js/app.js | 2 +- client/js/controllers/home/home.js | 2 +- client/js/controllers/image/image.js | 3 -- client/js/controllers/image/upload.js | 60 +++++++++++++++++++++++++++++++++++ client/js/controllers/login.js | 16 +++++----- client/js/controllers/status.js | 4 +-- client/js/services/Identity.js | 15 ++++++--- client/js/services/Image.js | 37 +++++++++++++++++---- 8 files changed, 113 insertions(+), 26 deletions(-) create mode 100644 client/js/controllers/image/upload.js (limited to 'client/js') diff --git a/client/js/app.js b/client/js/app.js index 1602e65..f571cb7 100644 --- a/client/js/app.js +++ b/client/js/app.js @@ -3,7 +3,7 @@ * The main app module instance * @type angular.module.angular-1_3_6_L1749.moduleInstance */ -var mainApp=angular.module("mainApp",['ngRoute', 'ngSanitize', 'ngCookies']); +var mainApp=angular.module("mainApp",['ngRoute', 'ngSanitize', 'ngCookies','lr.upload']); /** * Configure routeProvider diff --git a/client/js/controllers/home/home.js b/client/js/controllers/home/home.js index 2b355b1..835d6ac 100644 --- a/client/js/controllers/home/home.js +++ b/client/js/controllers/home/home.js @@ -29,7 +29,7 @@ mainApp.controller('homeCtrl', [ '$scope', 'Compute', '$rootScope', 'Loading','I if(Identity.isAlreadyLogin()){ - if(Compute.getData().machines == null{ + if(Compute.getData().machines == null){ Loading.start(); Compute.pullData(callMeAfterPullData); } diff --git a/client/js/controllers/image/image.js b/client/js/controllers/image/image.js index b0b162b..d9a9c06 100644 --- a/client/js/controllers/image/image.js +++ b/client/js/controllers/image/image.js @@ -11,9 +11,6 @@ mainApp.controller('imageCtrl', ['$scope', 'Image', 'Loading', 'Identity', funct Loading.stop(); }; - $scope.doUpload = function () { - Image.uploadImage($scope.myFile,function(){}); - }; if(Identity.isAlreadyLogin()){ diff --git a/client/js/controllers/image/upload.js b/client/js/controllers/image/upload.js new file mode 100644 index 0000000..eca9406 --- /dev/null +++ b/client/js/controllers/image/upload.js @@ -0,0 +1,60 @@ +/** + * The image controller + * + * @param {$scope} $scope The $scope service from angular + */ +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' + } + */ + + $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 + } + );*/ + + + }; + + +}]); diff --git a/client/js/controllers/login.js b/client/js/controllers/login.js index 63cb6d1..fed358d 100644 --- a/client/js/controllers/login.js +++ b/client/js/controllers/login.js @@ -9,15 +9,15 @@ */ 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}); - } + // 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}); + }); diff --git a/client/js/controllers/status.js b/client/js/controllers/status.js index b4a5dd9..15850f4 100644 --- a/client/js/controllers/status.js +++ b/client/js/controllers/status.js @@ -15,7 +15,7 @@ mainApp.controller('statusCtrl', ['$scope','Identity', '$rootScope', function ($ // Function to logout $scope.logout=function(){ - Identity.logout(); - }; + Identity.logout(); + }; }]); diff --git a/client/js/services/Identity.js b/client/js/services/Identity.js index f9d1df4..1e8d9ff 100644 --- a/client/js/services/Identity.js +++ b/client/js/services/Identity.js @@ -1,5 +1,5 @@ -mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){ +mainApp.factory('Identity',[ '$http', '$cookies', '$rootScope', function($http, $cookies, $rootScope){ /* Create profile structure to store informations * about current session @@ -27,17 +27,20 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){ && typeof tokenPart_1InCookie !== 'undefined' ){ - if(token!==null){ + //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; } @@ -56,7 +59,9 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){ profile.projectname=null; // Reload Page - location.reload(); + //location.reload(); + $rootScope.$broadcast("logoutEvent"); + } diff --git a/client/js/services/Image.js b/client/js/services/Image.js index decb5b2..d427e51 100644 --- a/client/js/services/Image.js +++ b/client/js/services/Image.js @@ -45,17 +45,42 @@ mainApp.factory('Image',[ '$http', 'Identity', function($http, Identity){ }; var uploadImage=function(fileToUpload, callback) { - - - var result=$http.post('../server/index.php', - $.param({"token" : Identity.getToken(), "task" : "image", 'action':'uploadImage', 'filename':fileToUpload, 'id':'6564'})); + 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.name); + + $.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.name, + 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){ + /* result.then(function (response){ callback(parseUploadImageAnswer(response, false)); },function(response){ callback(parseUploadImageAnswer(response, true)); - }); + });*/ -- cgit v1.2.3 From 60cfe3ebc039df8d6a468a43a59e7fd8c2a16956 Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Mon, 28 Mar 2016 11:27:37 +0200 Subject: Test --- client/js/controllers/home/home.js | 1 + client/js/services/Compute.js | 10 ++++++++-- client/js/services/Identity.js | 1 - 3 files changed, 9 insertions(+), 3 deletions(-) (limited to 'client/js') diff --git a/client/js/controllers/home/home.js b/client/js/controllers/home/home.js index 835d6ac..b508c97 100644 --- a/client/js/controllers/home/home.js +++ b/client/js/controllers/home/home.js @@ -7,6 +7,7 @@ mainApp.controller('homeCtrl', [ '$scope', 'Compute', '$rootScope', 'Loading','I { var callMeAfterPullData=function(data){ + console.log(data); $scope.machines=Compute.getData().machines; Loading.stop(); }; diff --git a/client/js/services/Compute.js b/client/js/services/Compute.js index 36ddc16..2bf28d8 100644 --- a/client/js/services/Compute.js +++ b/client/js/services/Compute.js @@ -32,7 +32,7 @@ mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){ } else if(failedToSendRequest){ - requestParserResult.failReason="Failed to send request"; + requestParserResult.failReason="Failed to send PullMachine request"; } else{ requestParserResult.failReason="Error"; @@ -79,7 +79,7 @@ mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){ data.axioms.images=response.data.Images; } else if(failedToSendRequest){ - requestParserResult.failReason="Failed to send request"; + requestParserResult.failReason="Failed to send PullImage request"; } else{ requestParserResult.failReason="Error"; @@ -101,8 +101,11 @@ mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){ // Wait and handle the response result.then(function (response){ + alert(Identity.getToken()); + callback(parsePullImagesAnswer(response, false)); },function(response){ + callback(parsePullImagesAnswer(response, true)); }); }; @@ -117,6 +120,9 @@ mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){ if(response.status==0){ pullMachines(callback); } + else{ + callback(response); + } } pullImages(nextFunction); } diff --git a/client/js/services/Identity.js b/client/js/services/Identity.js index 1e8d9ff..73e5d86 100644 --- a/client/js/services/Identity.js +++ b/client/js/services/Identity.js @@ -31,7 +31,6 @@ mainApp.factory('Identity',[ '$http', '$cookies', '$rootScope', function($http, // If yes, put it into variables angular.extend(profile, profileInCookie); token=tokenPart_0InCookie+tokenPart_1InCookie; - //} // Return I'm Login -- cgit v1.2.3 From a577b60ce475f94221462befcb0b5b4a347aad33 Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Mon, 28 Mar 2016 18:20:29 +0200 Subject: Test --- client/js/app.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'client/js') diff --git a/client/js/app.js b/client/js/app.js index 925f033..e911050 100644 --- a/client/js/app.js +++ b/client/js/app.js @@ -12,19 +12,20 @@ mainApp.config(['$routeProvider', function($routeProvider){ $routeProvider. - when('/home',{ - templateUrl: 'partials/home/home.html', - controller: 'homeCtrl' - }). - when('/network',{ - templateUrl: 'partials/network/network.html', - controller: 'networkCtrl' - }). - when('/image',{ - templateUrl: 'partials/image/image.html', - controller: 'imageCtrl' - }).otherwise({ - redirectTo: '/' + when('/home',{ + templateUrl: 'partials/home/home.html', + controller: 'homeCtrl' + }). + when('/network',{ + templateUrl: 'partials/network/network.html', + controller: 'networkCtrl' + }). + when('/image',{ + templateUrl: 'partials/image/image.html', + controller: 'imageCtrl' + }) + .otherwise({ + redirectTo: '/' }); }]); -- cgit v1.2.3 From f4da4f285a4689e1d4eb8bb7d800d6570dfba6d0 Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Mon, 28 Mar 2016 19:01:32 +0200 Subject: test --- client/js/services/Image.js | 4 ++-- server/Test/DisplayListCidr.php | 0 server/Test/getIdNetwork.php | 0 server/Test/getNetwork.php | 0 server/core/Automating.php | 0 server/core/Network.php~ | 0 server/vendor/php-opencloud/common/.travis.yml | 0 7 files changed, 2 insertions(+), 2 deletions(-) mode change 100644 => 100755 server/Test/DisplayListCidr.php mode change 100644 => 100755 server/Test/getIdNetwork.php mode change 100644 => 100755 server/Test/getNetwork.php mode change 100644 => 100755 server/core/Automating.php mode change 100644 => 100755 server/core/Network.php~ mode change 100644 => 100755 server/vendor/php-opencloud/common/.travis.yml (limited to 'client/js') diff --git a/client/js/services/Image.js b/client/js/services/Image.js index d427e51..d6c9fed 100644 --- a/client/js/services/Image.js +++ b/client/js/services/Image.js @@ -52,13 +52,13 @@ mainApp.factory('Image',[ '$http', 'Identity', function($http, Identity){ form_data.append("token" , Identity.getToken()) form_data.append('action',"uploadImage") form_data.append('id','6564') - form_data.append('file_name', fileToUpload.name); + 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.name, + file_name:fileToUpload, token : Identity.getToken(), task : "image", action:'uploadImage', diff --git a/server/Test/DisplayListCidr.php b/server/Test/DisplayListCidr.php old mode 100644 new mode 100755 diff --git a/server/Test/getIdNetwork.php b/server/Test/getIdNetwork.php old mode 100644 new mode 100755 diff --git a/server/Test/getNetwork.php b/server/Test/getNetwork.php old mode 100644 new mode 100755 diff --git a/server/core/Automating.php b/server/core/Automating.php old mode 100644 new mode 100755 diff --git a/server/core/Network.php~ b/server/core/Network.php~ old mode 100644 new mode 100755 diff --git a/server/vendor/php-opencloud/common/.travis.yml b/server/vendor/php-opencloud/common/.travis.yml old mode 100644 new mode 100755 -- cgit v1.2.3