From 80a2e0d055158aafdda3ff26de187758503e6d40 Mon Sep 17 00:00:00 2001 From: jendib Date: Fri, 27 Mar 2015 23:03:55 +0100 Subject: [PATCH] Drag & drop files to documents --- .../src/app/docs/controller/DocumentView.js | 47 +++++++++++++++- .../src/partial/docs/document.default.html | 2 +- .../src/partial/docs/document.view.html | 55 ++++++++++++------- docs-web/src/main/webapp/src/style/main.less | 4 ++ 4 files changed, 87 insertions(+), 21 deletions(-) diff --git a/docs-web/src/main/webapp/src/app/docs/controller/DocumentView.js b/docs-web/src/main/webapp/src/app/docs/controller/DocumentView.js index a16203ca..a3908957 100644 --- a/docs-web/src/main/webapp/src/app/docs/controller/DocumentView.js +++ b/docs-web/src/main/webapp/src/app/docs/controller/DocumentView.js @@ -3,7 +3,7 @@ /** * Document view controller. */ -angular.module('docs').controller('DocumentView', function ($scope, $state, $stateParams, $location, $dialog, $modal, Restangular) { +angular.module('docs').controller('DocumentView', function ($scope, $state, $stateParams, $location, $dialog, $modal, Restangular, $upload) { // Load data from server Restangular.one('document', $stateParams.id).get().then(function(data) { $scope.document = data; @@ -34,6 +34,7 @@ angular.module('docs').controller('DocumentView', function ($scope, $state, $sta $scope.loadFiles = function () { Restangular.one('file').getList('list', { id: $stateParams.id }).then(function (data) { $scope.files = data.files; + // TODO Keep currently uploading files }); }; $scope.loadFiles(); @@ -141,4 +142,48 @@ angular.module('docs').controller('DocumentView', function ($scope, $state, $sta } }); }; + + /** + * File has been drag & dropped. + * @param files + */ + $scope.fileDropped = function(files) { + if (files && files.length) { + for (var i = 0; i < files.length; i++) { + var file = files[i]; + $scope.uploadFile(file); + } + } + }; + + /** + * Uppload a file. + * @param file + */ + $scope.uploadFile = function(file) { + // Add the uploading file to the UI + var newfile = { + progress: 0, + name: file.name, + create_date: new Date().getTime(), + mimetype: file.type + }; + $scope.files.push(newfile); + + // Upload the file + $upload.upload({ + method: 'PUT', + url: '../api/file', + file: file, + fields: { + id: $stateParams.id + } + }) + .progress(function (e) { + newfile.progress = parseInt(100.0 * e.loaded / e.total); + }) + .success(function (data) { + newfile.id = data.id; + }); + }; }); \ No newline at end of file diff --git a/docs-web/src/main/webapp/src/partial/docs/document.default.html b/docs-web/src/main/webapp/src/partial/docs/document.default.html index 156339e5..c34bcca1 100644 --- a/docs-web/src/main/webapp/src/partial/docs/document.default.html +++ b/docs-web/src/main/webapp/src/partial/docs/document.default.html @@ -5,7 +5,7 @@ {{ app.document_count }} document{{ app.document_count > 1 ? 's' : '' }} in the database -
diff --git a/docs-web/src/main/webapp/src/partial/docs/document.view.html b/docs-web/src/main/webapp/src/partial/docs/document.view.html index 85a8137b..4257b645 100644 --- a/docs-web/src/main/webapp/src/partial/docs/document.view.html +++ b/docs-web/src/main/webapp/src/partial/docs/document.view.html @@ -32,25 +32,42 @@

- -
-
-
- - - -
-
-
-
-
- -
-
-
-
-
-
+ +
+
+
+
+ + + +
+
+
+
+
+ +
+
+
+
+ +
+

+ Uploading... +

+
+ +
+
+
+ +

+ + Drag & drop files here to upload +

+
+
\ No newline at end of file diff --git a/docs-web/src/main/webapp/src/style/main.less b/docs-web/src/main/webapp/src/style/main.less index b0f2966b..788c4514 100644 --- a/docs-web/src/main/webapp/src/style/main.less +++ b/docs-web/src/main/webapp/src/style/main.less @@ -162,4 +162,8 @@ input[readonly].share-link { .row { margin: 0; padding: 0 } .navbar-nav.navbar-right:last-child { margin-right: auto; +} + +.bg-success { + background-color: #dff0d8; } \ No newline at end of file