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/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 +-- 5 files changed, 71 insertions(+), 14 deletions(-) create mode 100644 client/js/controllers/image/upload.js (limited to 'client/js/controllers') 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(); + }; }]); -- 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/controllers') 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