From 0d4643cc93660a30e0383b9f3bf8045a11059749 Mon Sep 17 00:00:00 2001 From: jendib Date: Sat, 28 Mar 2015 00:09:28 +0100 Subject: [PATCH] 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 -