From 0d4643cc93660a30e0383b9f3bf8045a11059749 Mon Sep 17 00:00:00 2001 From: jendib Date: Sat, 28 Mar 2015 00:09:28 +0100 Subject: [PATCH 1/2] File modal refactoring + orphan files selection --- docs-web/src/main/webapp/src/app/docs/app.js | 4 ++-- .../src/app/docs/controller/DocumentDefault.js | 5 ++++- .../webapp/src/app/docs/controller/FileModalView.js | 8 +++----- .../main/webapp/src/app/docs/controller/FileView.js | 6 +----- .../src/main/webapp/src/app/docs/controller/Tag.js | 6 +++--- .../webapp/src/partial/docs/document.default.html | 11 +++++++---- .../main/webapp/src/partial/docs/document.view.html | 2 +- docs-web/src/main/webapp/src/style/main.less | 13 +++++++++++++ 8 files changed, 34 insertions(+), 21 deletions(-) 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 78b3a362..4a88388a 100644 --- a/docs-web/src/main/webapp/src/app/docs/app.js +++ b/docs-web/src/main/webapp/src/app/docs/app.js @@ -134,7 +134,7 @@ angular.module('docs', } }) .state('document.add', { - url: '/add', + url: '/add?files', views: { 'document': { templateUrl: 'partial/docs/document.edit.html', @@ -143,7 +143,7 @@ angular.module('docs', } }) .state('document.edit', { - url: '/edit/:id', + url: '/edit/:id?files', views: { 'document': { templateUrl: 'partial/docs/document.edit.html', 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 a5b270da..00d6358c 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 @@ -71,9 +71,12 @@ angular.module('docs').controller('DocumentDefault', function($scope, $state, Re /** * Delete a file. */ - $scope.deleteFile = function (file) { + $scope.deleteFile = function ($event, file) { + $event.stopPropagation(); + Restangular.one('file', file.id).remove().then(function () { $scope.loadFiles(); }); + return false; }; }); \ 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 e2b95384..fd5f1b55 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,8 +4,6 @@ * 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; @@ -26,7 +24,7 @@ angular.module('docs').controller('FileModalView', function($rootScope, $modalIn if (value.id == $stateParams.fileId) { var next = $scope.files[key + 1]; if (next) { - $state.transitionTo(view, { id: $stateParams.id, fileId: next.id }); + $state.go('^.file', { id: $stateParams.id, fileId: next.id }); } } }); @@ -40,7 +38,7 @@ angular.module('docs').controller('FileModalView', function($rootScope, $modalIn if (value.id == $stateParams.fileId) { var previous = $scope.files[key - 1]; if (previous) { - $state.transitionTo(view, { id: $stateParams.id, fileId: previous.id }); + $state.go('^.file', { id: $stateParams.id, fileId: previous.id }); } } }); @@ -74,7 +72,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 == view) { + if (toState.name == $state.current.name) { $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 e98780c1..02c887d2 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,10 +16,6 @@ angular.module('docs').controller('FileView', function($modal, $state, $statePar modal.closed = true; }, function() { modal.closed = true; - if ($stateParams.id) { - $state.transitionTo('document.view', { id: $stateParams.id }); - } else { - $state.transitionTo('document.default'); - } + $state.go('^', { id: $stateParams.id }); }); }); \ No newline at end of file diff --git a/docs-web/src/main/webapp/src/app/docs/controller/Tag.js b/docs-web/src/main/webapp/src/app/docs/controller/Tag.js index d38c0ced..53b44ea1 100644 --- a/docs-web/src/main/webapp/src/app/docs/controller/Tag.js +++ b/docs-web/src/main/webapp/src/app/docs/controller/Tag.js @@ -3,9 +3,9 @@ /** * Tag controller. */ -angular.module('docs').controller('Tag', function($scope, $dialog, $state, Tag, Restangular) { +angular.module('docs').controller('Tag', function($scope, $dialog, Tag, Restangular) { $scope.tag = { name: '', color: '#3a87ad' }; - + // Retrieve tags Tag.tags().then(function(data) { $scope.tags = data.tags; @@ -14,7 +14,7 @@ angular.module('docs').controller('Tag', function($scope, $dialog, $state, Tag, // Retrieve tag stats Restangular.one('tag/stats').get().then(function(data) { $scope.stats = data.stats; - }) + }); /** * Returns total number of document from tag stats. 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 c34bcca1..e5b906f1 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,16 +5,19 @@ {{ 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 4257b645..da4a359d 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 @@ -35,7 +35,7 @@
-
+
diff --git a/docs-web/src/main/webapp/src/style/main.less b/docs-web/src/main/webapp/src/style/main.less index 788c4514..39551d4f 100644 --- a/docs-web/src/main/webapp/src/style/main.less +++ b/docs-web/src/main/webapp/src/style/main.less @@ -164,6 +164,19 @@ input[readonly].share-link { margin-right: auto; } +// Drag & drop related .bg-success { background-color: #dff0d8; +} + +.upload-zone { + min-height: 150px; +} + +.thumbnail-checked { + background-color: #dff0d8; +} + +.pointer { + cursor: pointer; } \ No newline at end of file From 5e3093d0d3b55566cdddfc7d513de83ddd94f83d Mon Sep 17 00:00:00 2001 From: jendib Date: Sat, 28 Mar 2015 18:02:21 +0100 Subject: [PATCH 2/2] Attach orphan files to a new document --- .../app/docs/controller/DocumentDefault.js | 14 +++++ .../src/app/docs/controller/DocumentEdit.js | 58 ++++++++++++------- .../src/partial/docs/document.default.html | 4 ++ .../src/partial/docs/document.edit.html | 5 +- 4 files changed, 58 insertions(+), 23 deletions(-) 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 00d6358c..9fefe384 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 @@ -79,4 +79,18 @@ angular.module('docs').controller('DocumentDefault', function($scope, $state, Re }); return false; }; + + /** + * Returns checked files. + */ + $scope.checkedFiles = function() { + return _.where($scope.files, { checked: true }); + }; + + /** + * Add a document with checked files. + */ + $scope.addDocument = function() { + $state.transitionTo('document.add', { files: _.pluck($scope.checkedFiles(), 'id') }); + }; }); \ No newline at end of file diff --git a/docs-web/src/main/webapp/src/app/docs/controller/DocumentEdit.js b/docs-web/src/main/webapp/src/app/docs/controller/DocumentEdit.js index 7aff1ac2..c0d7d4b3 100644 --- a/docs-web/src/main/webapp/src/app/docs/controller/DocumentEdit.js +++ b/docs-web/src/main/webapp/src/app/docs/controller/DocumentEdit.js @@ -6,7 +6,10 @@ angular.module('docs').controller('DocumentEdit', function($rootScope, $scope, $q, $http, $state, $stateParams, Restangular) { // Alerts $scope.alerts = []; - + + // Orphan files to add + $scope.orphanFiles = $stateParams.files ? $stateParams.files.split(',') : []; + /** * Close an alert. */ @@ -51,6 +54,8 @@ angular.module('docs').controller('DocumentEdit', function($rootScope, $scope, $ /** * Edit a document. + * Workflow: + * Edit/add the file -> upload local files -> attach orphan files -> redirect to edited document or stay if adding */ $scope.edit = function() { var promise = null; @@ -65,35 +70,44 @@ angular.module('docs').controller('DocumentEdit', function($rootScope, $scope, $ document.tags = _.pluck(document.tags, 'id'); if ($scope.isEdit()) { - promise = Restangular - .one('document', $stateParams.id) - .post('', document); + promise = Restangular.one('document', $stateParams.id).post('', document); } else { - promise = Restangular - .one('document') - .put(document); + promise = Restangular.one('document').put(document); } + + // Attach orphan files after edition + var attachOrphanFiles = function(data) { + var promises = []; + _.each($scope.orphanFiles, function(fileId) { + promises.push(Restangular.one('file/' + fileId).post('', { id: data.id })); + }); + $scope.orphanFiles = []; + return $q.all(promises); + }; // Upload files after edition promise.then(function(data) { $scope.fileProgress = 0; - // When all files upload are over, move on + // When all files upload are over, attach orphan files and move on var navigateNext = function() { - if ($scope.isEdit()) { - // Go back to the edited document - $scope.pageDocuments(); - $state.transitionTo('document.view', { id: $stateParams.id }); - } else { - // Reset the scope and stay here - var fileUploadCount = _.size($scope.newFiles); - $scope.alerts.unshift({ - type: 'success', - msg: 'Document successfully added (with ' + fileUploadCount + ' file' + (fileUploadCount > 1 ? 's' : '') + ')' - }); - $scope.resetForm(); - $scope.loadDocuments(); - } + attachOrphanFiles(data).then(function(resolve) { + if ($scope.isEdit()) { + // Go back to the edited document + $scope.pageDocuments(); + $state.transitionTo('document.view', { id: $stateParams.id }); + } else { + // Reset the scope and stay here + var fileUploadCount = _.size($scope.newFiles) + resolve.length; + $scope.alerts.unshift({ + type: 'success', + msg: 'Document successfully added (with ' + fileUploadCount + ' file' + (fileUploadCount > 1 ? 's' : '') + ')' + }); + + $scope.resetForm(); + $scope.loadDocuments(); + } + }); }; if (_.size($scope.newFiles) == 0) { 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 e5b906f1..1d0bbd2b 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 @@ -39,6 +39,10 @@

+
+ +
+
diff --git a/docs-web/src/main/webapp/src/partial/docs/document.edit.html b/docs-web/src/main/webapp/src/partial/docs/document.edit.html index 51b3d951..717fc3a5 100644 --- a/docs-web/src/main/webapp/src/partial/docs/document.edit.html +++ b/docs-web/src/main/webapp/src/partial/docs/document.edit.html @@ -37,10 +37,13 @@
-
+
+
+ + {{ orphanFiles.length }} file{{ orphanFiles.length > 1 ? 's' : '' }} +