summaryrefslogtreecommitdiff
path: root/client/js
diff options
context:
space:
mode:
Diffstat (limited to 'client/js')
-rw-r--r--client/js/app.js29
-rwxr-xr-xclient/js/controllers/home/home.js1
-rw-r--r--client/js/controllers/image/image.js3
-rw-r--r--client/js/controllers/image/upload.js60
-rw-r--r--client/js/controllers/login.js16
-rw-r--r--client/js/controllers/status.js4
-rw-r--r--client/js/services/Compute.js10
-rw-r--r--client/js/services/Identity.js16
-rw-r--r--client/js/services/Image.js37
9 files changed, 135 insertions, 41 deletions
diff --git a/client/js/app.js b/client/js/app.js
index a26e0ec..e911050 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
@@ -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: '/'
});
}]);
diff --git a/client/js/controllers/home/home.js b/client/js/controllers/home/home.js
index ec6fb6e..10142c9 100755
--- 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/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/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 f9d1df4..73e5d86 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,19 @@ 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 +58,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..d6c9fed 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);
+
+ $.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){
+ /* result.then(function (response){
callback(parseUploadImageAnswer(response, false));
},function(response){
callback(parseUploadImageAnswer(response, true));
- });
+ });*/