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 -
+ Uploading... +
+ ++ + Drag & drop files here to upload +
+