diff --git a/.gitignore b/.gitignore index 3a845afe..598cc5c4 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ /*/bin /*/gen /*/target +/*/build /*/*.iml /out /.idea diff --git a/docs-web/src/main/webapp/src/app/docs/app.js b/docs-web/src/main/webapp/src/app/docs/app.js index 348478f7..78b3a362 100644 --- a/docs-web/src/main/webapp/src/app/docs/app.js +++ b/docs-web/src/main/webapp/src/app/docs/app.js @@ -125,6 +125,14 @@ angular.module('docs', } } }) + .state('document.default.file', { + url: '/file/:fileId', + views: { + 'file': { + controller: 'FileView' + } + } + }) .state('document.add', { url: '/add', views: { diff --git a/docs-web/src/main/webapp/src/app/docs/controller/DocumentDefault.js b/docs-web/src/main/webapp/src/app/docs/controller/DocumentDefault.js index 463073ff..a5b270da 100644 --- a/docs-web/src/main/webapp/src/app/docs/controller/DocumentDefault.js +++ b/docs-web/src/main/webapp/src/app/docs/controller/DocumentDefault.js @@ -3,9 +3,77 @@ /** * Document default controller. */ -angular.module('docs').controller('DocumentDefault', function($scope, $state, Restangular) { +angular.module('docs').controller('DocumentDefault', function($scope, $state, Restangular, $upload) { // Load app data Restangular.one('app').get().then(function(data) { $scope.app = data; }); + + /** + * Load unlinked files. + */ + $scope.loadFiles = function() { + Restangular.one('file').getList('list').then(function (data) { + $scope.files = data.files; + // TODO Keep currently uploading files + }); + }; + $scope.loadFiles(); + + /** + * 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 + }) + .progress(function (e) { + newfile.progress = parseInt(100.0 * e.loaded / e.total); + }) + .success(function (data) { + newfile.id = data.id; + }); + }; + + /** + * Navigate to the selected file. + */ + $scope.openFile = function (file) { + $state.transitionTo('document.default.file', { fileId: file.id }) + }; + + /** + * Delete a file. + */ + $scope.deleteFile = function (file) { + Restangular.one('file', file.id).remove().then(function () { + $scope.loadFiles(); + }); + }; }); \ No newline at end of file diff --git a/docs-web/src/main/webapp/src/app/docs/controller/FileModalView.js b/docs-web/src/main/webapp/src/app/docs/controller/FileModalView.js index fd457072..e2b95384 100644 --- a/docs-web/src/main/webapp/src/app/docs/controller/FileModalView.js +++ b/docs-web/src/main/webapp/src/app/docs/controller/FileModalView.js @@ -4,6 +4,8 @@ * File modal view controller. */ angular.module('docs').controller('FileModalView', function($rootScope, $modalInstance, $scope, $state, $stateParams, Restangular) { + var view = $stateParams.id ? 'document.view.file' : 'document.default.file'; + // Load files Restangular.one('file').getList('list', { id: $stateParams.id }).then(function(data) { $scope.files = data.files; @@ -24,7 +26,7 @@ angular.module('docs').controller('FileModalView', function($rootScope, $modalIn if (value.id == $stateParams.fileId) { var next = $scope.files[key + 1]; if (next) { - $state.transitionTo('document.view.file', { id: $stateParams.id, fileId: next.id }); + $state.transitionTo(view, { id: $stateParams.id, fileId: next.id }); } } }); @@ -38,7 +40,7 @@ angular.module('docs').controller('FileModalView', function($rootScope, $modalIn if (value.id == $stateParams.fileId) { var previous = $scope.files[key - 1]; if (previous) { - $state.transitionTo('document.view.file', { id: $stateParams.id, fileId: previous.id }); + $state.transitionTo(view, { id: $stateParams.id, fileId: previous.id }); } } }); @@ -72,7 +74,7 @@ angular.module('docs').controller('FileModalView', function($rootScope, $modalIn // Close the modal when the user exits this state var off = $rootScope.$on('$stateChangeStart', function(event, toState) { if (!$modalInstance.closed) { - if (toState.name == 'document.view.file') { + if (toState.name == view) { $modalInstance.close(); } else { $modalInstance.dismiss(); diff --git a/docs-web/src/main/webapp/src/app/docs/controller/FileView.js b/docs-web/src/main/webapp/src/app/docs/controller/FileView.js index 8f99710a..e98780c1 100644 --- a/docs-web/src/main/webapp/src/app/docs/controller/FileView.js +++ b/docs-web/src/main/webapp/src/app/docs/controller/FileView.js @@ -16,6 +16,10 @@ angular.module('docs').controller('FileView', function($modal, $state, $statePar modal.closed = true; }, function() { modal.closed = true; - $state.transitionTo('document.view', { id: $stateParams.id }); + if ($stateParams.id) { + $state.transitionTo('document.view', { id: $stateParams.id }); + } else { + $state.transitionTo('document.default'); + } }); }); \ 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 603b6b35..156339e5 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,14 +5,40 @@ {{ app.document_count }} document{{ app.document_count > 1 ? 's' : '' }} in the database - - -
+
+

+ Uploading... +

+
+ +
+
+
+ +

+ + Drag & drop files here to upload +

+ + +
+ +