From 50e36a66d9f6bbcf64b9594871a7d87df37bde01 Mon Sep 17 00:00:00 2001 From: ThieryMichel Date: Mon, 4 May 2015 16:55:33 +0200 Subject: [PATCH 1/8] save filter page and sort in state when going from list to edit/create/delete/batchdelete page --- .../Crud/button/maBatchDeleteButton.js | 15 +++++++--- .../ng-admin/Crud/button/maCreateButton.js | 12 ++++++-- .../ng-admin/Crud/button/maDeleteButton.js | 13 ++++++-- .../ng-admin/Crud/button/maEditButton.js | 14 ++++++--- .../ng-admin/Crud/button/maListButton.js | 14 ++++++--- .../Crud/delete/BatchDeleteController.js | 20 +++++++++++-- .../ng-admin/Crud/delete/DeleteController.js | 30 ++++++++++++++----- .../ng-admin/Crud/form/FormController.js | 5 ++-- src/javascripts/ng-admin/Crud/routing.js | 22 +++++++++++++- 9 files changed, 113 insertions(+), 32 deletions(-) diff --git a/src/javascripts/ng-admin/Crud/button/maBatchDeleteButton.js b/src/javascripts/ng-admin/Crud/button/maBatchDeleteButton.js index ea6a0e54..1a201d05 100644 --- a/src/javascripts/ng-admin/Crud/button/maBatchDeleteButton.js +++ b/src/javascripts/ng-admin/Crud/button/maBatchDeleteButton.js @@ -3,7 +3,7 @@ define(function () { 'use strict'; - function maBatchDeleteButtonDirective($state) { + function maBatchDeleteButtonDirective($state, $stateParams) { return { restrict: 'E', scope: { @@ -17,9 +17,16 @@ define(function () { $scope.gotoBatchDelete = function () { var entity = $scope.entity(); var ids = $scope.selection().map(function(entry) { - return entry.identifierValue + return entry.identifierValue; + }); + $state.go('batchDelete', { + ids: ids, + entity: entity.name(), + page: $stateParams.page, + search: $stateParams.search, + sortField: $stateParams.sortField, + sortDir: $stateParams.sortDir }); - $state.go('batchDelete', { ids: ids, entity: entity.name() }); }; }, template: @@ -30,7 +37,7 @@ define(function () { }; } - maBatchDeleteButtonDirective.$inject = ['$state']; + maBatchDeleteButtonDirective.$inject = ['$state', '$stateParams']; return maBatchDeleteButtonDirective; }); diff --git a/src/javascripts/ng-admin/Crud/button/maCreateButton.js b/src/javascripts/ng-admin/Crud/button/maCreateButton.js index 7f81c5e3..16ee26dd 100644 --- a/src/javascripts/ng-admin/Crud/button/maCreateButton.js +++ b/src/javascripts/ng-admin/Crud/button/maCreateButton.js @@ -3,7 +3,7 @@ define(function () { 'use strict'; - function maCreateButtonDirective($state) { + function maCreateButtonDirective($state, $stateParams) { return { restrict: 'E', scope: { @@ -15,7 +15,13 @@ define(function () { scope.label = scope.label || 'Create'; scope.gotoCreate = function () { - $state.go($state.get('create'), { 'entity': scope.entity().name() }); + $state.go($state.get('create'), { + entity: scope.entity().name(), + page: $stateParams.page, + search: $stateParams.search, + sortField: $stateParams.sortField, + sortDir: $stateParams.sortDir + }); }; }, template: @@ -25,7 +31,7 @@ define(function () { }; } - maCreateButtonDirective.$inject = ['$state']; + maCreateButtonDirective.$inject = ['$state', '$stateParams']; return maCreateButtonDirective; }); diff --git a/src/javascripts/ng-admin/Crud/button/maDeleteButton.js b/src/javascripts/ng-admin/Crud/button/maDeleteButton.js index 0bd79fb2..742ff08d 100644 --- a/src/javascripts/ng-admin/Crud/button/maDeleteButton.js +++ b/src/javascripts/ng-admin/Crud/button/maDeleteButton.js @@ -3,7 +3,7 @@ define(function () { 'use strict'; - function maDeleteButtonDirective($state) { + function maDeleteButtonDirective($state, $stateParams) { return { restrict: 'E', scope: { @@ -16,7 +16,14 @@ define(function () { scope.label = scope.label || 'Delete'; scope.gotoDelete = function () { - $state.go($state.get('delete'), { entity: scope.entity().name(), id: scope.entry().identifierValue }); + $state.go($state.get('delete'), { + entity: scope.entity().name(), + id: scope.entry().identifierValue, + page: $stateParams.page, + search: $stateParams.search, + sortField: $stateParams.sortField, + sortDir: $stateParams.sortDir + }); }; }, template: @@ -27,7 +34,7 @@ define(function () { }; } - maDeleteButtonDirective.$inject = ['$state']; + maDeleteButtonDirective.$inject = ['$state', '$stateParams']; return maDeleteButtonDirective; }); diff --git a/src/javascripts/ng-admin/Crud/button/maEditButton.js b/src/javascripts/ng-admin/Crud/button/maEditButton.js index 42460655..4d4569e6 100644 --- a/src/javascripts/ng-admin/Crud/button/maEditButton.js +++ b/src/javascripts/ng-admin/Crud/button/maEditButton.js @@ -3,7 +3,7 @@ define(function () { 'use strict'; - function maEditButtonDirective($state) { + function maEditButtonDirective($state, $stateParams) { return { restrict: 'E', scope: { @@ -14,9 +14,15 @@ define(function () { }, link: function (scope) { scope.label = scope.label || 'Edit'; - scope.gotoEdit = function () { - $state.go($state.get('edit'), { entity: scope.entity().name(), id: scope.entry().identifierValue }); + $state.go($state.get('edit'), { + entity: scope.entity().name(), + id: scope.entry().identifierValue, + page: $stateParams.page, + search: $stateParams.search, + sortField: $stateParams.sortField, + sortDir: $stateParams.sortDir + }); }; }, template: @@ -26,7 +32,7 @@ define(function () { }; } - maEditButtonDirective.$inject = ['$state']; + maEditButtonDirective.$inject = ['$state', '$stateParams']; return maEditButtonDirective; }); diff --git a/src/javascripts/ng-admin/Crud/button/maListButton.js b/src/javascripts/ng-admin/Crud/button/maListButton.js index ff00000f..057c0ecd 100644 --- a/src/javascripts/ng-admin/Crud/button/maListButton.js +++ b/src/javascripts/ng-admin/Crud/button/maListButton.js @@ -5,11 +5,11 @@ define(function () { /** * Link to list - * + * * Usage: * */ - function maListButtonDirective($state) { + function maListButtonDirective($state, $stateParams) { return { restrict: 'E', scope: { @@ -21,7 +21,13 @@ define(function () { scope.label = scope.label || 'List'; scope.gotoList = function () { - $state.go($state.get('list'), { 'entity': scope.entity().name() }); + $state.go($state.get('list'), { + entity: scope.entity().name(), + search: $stateParams.search, + page: $stateParams.page, + sortDir: $stateParams.sortDir, + sortField: $stateParams.sortField + }); }; }, template: @@ -31,7 +37,7 @@ define(function () { }; } - maListButtonDirective.$inject = ['$state']; + maListButtonDirective.$inject = ['$state', '$stateParams']; return maListButtonDirective; }); diff --git a/src/javascripts/ng-admin/Crud/delete/BatchDeleteController.js b/src/javascripts/ng-admin/Crud/delete/BatchDeleteController.js index 35937302..5925bbcc 100644 --- a/src/javascripts/ng-admin/Crud/delete/BatchDeleteController.js +++ b/src/javascripts/ng-admin/Crud/delete/BatchDeleteController.js @@ -4,6 +4,7 @@ define(function () { 'use strict'; var BatchDeleteController = function ($scope, $state, $stateParams, $location, $window, WriteQueries, notification, view) { + this.$scope = $scope; this.$state = $state; this.$stateParams = $stateParams; @@ -27,10 +28,16 @@ define(function () { BatchDeleteController.prototype.batchDelete = function () { var notification = this.notification, $state = this.$state, - entityName = this.entity.name(); + _this = this; this.WriteQueries.batchDelete(this.view, this.entityIds).then(function () { - $state.go($state.get('list'), { 'entity': entityName }); + $state.go($state.get('list'), { + entity: _this.entity.name(), + page: _this.$stateParams.page, + search: _this.$stateParams.search, + sortField: _this.$stateParams.sortField, + sortDir: _this.$stateParams.sortDir + }); notification.log('Elements successfully deleted.', { addnCls: 'humane-flatty-success' }); }, function (response) { // @TODO: share this method when splitting controllers @@ -44,7 +51,13 @@ define(function () { }; BatchDeleteController.prototype.back = function () { - this.$window.history.back(); + this.$state.go(this.$state.get('list'), { + entity: this.entity.name(), + page: this.$stateParams.page, + search: this.$stateParams.search, + sortField: this.$stateParams.sortField, + sortDir: this.$stateParams.sortDir + }); }; BatchDeleteController.prototype.destroy = function () { @@ -58,5 +71,6 @@ define(function () { BatchDeleteController.$inject = ['$scope', '$state', '$stateParams', '$location', '$window', 'WriteQueries', 'notification', 'view']; + return BatchDeleteController; }); diff --git a/src/javascripts/ng-admin/Crud/delete/DeleteController.js b/src/javascripts/ng-admin/Crud/delete/DeleteController.js index 6e1eaad6..b9b6104e 100644 --- a/src/javascripts/ng-admin/Crud/delete/DeleteController.js +++ b/src/javascripts/ng-admin/Crud/delete/DeleteController.js @@ -3,9 +3,10 @@ define(function () { 'use strict'; - var DeleteController = function ($scope, $location, WriteQueries, notification, params, view, entry) { + var DeleteController = function ($scope, $state, $stateParams, WriteQueries, notification, params, view, entry) { this.$scope = $scope; - this.$location = $location; + this.$state = $state; + this.$stateParams = $stateParams; this.WriteQueries = WriteQueries; this.entityLabel = params.entity; this.entityId = params.id; @@ -23,11 +24,16 @@ define(function () { DeleteController.prototype.deleteOne = function () { var notification = this.notification, - $location = this.$location, - entityLabel = this.entityLabel; + $state = this.$state, _this = this; this.WriteQueries.deleteOne(this.view, this.entityId).then(function () { - $location.path(entityLabel + '/list'); + $state.go($state.get('list'), { + entity: _this.entity.name(), + page: _this.$stateParams.page, + search: _this.$stateParams.search, + sortField: _this.$stateParams.sortField, + sortDir: _this.$stateParams.sortDir + }); notification.log('Element successfully deleted.', { addnCls: 'humane-flatty-success' }); }, function (response) { // @TODO: share this method when splitting controllers @@ -41,18 +47,26 @@ define(function () { }; DeleteController.prototype.back = function () { - this.$location.path(this.entityLabel + '/edit/' + this.entityId); + this.$state.go(this.$state.get('edit'), { + entity: this.entity.name(), + id: this.entityId, + page: this.$stateParams.page, + search: this.$stateParams.search, + sortField: this.$stateParams.sortField, + sortDir: this.$stateParams.sortDir + }); }; DeleteController.prototype.destroy = function () { this.$scope = undefined; - this.$location = undefined; this.WriteQueries = undefined; + this.$state = undefined; + this.$stateParams = undefined; this.view = undefined; this.entity = undefined; }; - DeleteController.$inject = ['$scope', '$location', 'WriteQueries', 'notification', 'params', 'view', 'entry']; + DeleteController.$inject = ['$scope', '$state', '$stateParams', 'WriteQueries', 'notification', 'params', 'view', 'entry']; return DeleteController; }); diff --git a/src/javascripts/ng-admin/Crud/form/FormController.js b/src/javascripts/ng-admin/Crud/form/FormController.js index 5ccc5cea..815c35cd 100644 --- a/src/javascripts/ng-admin/Crud/form/FormController.js +++ b/src/javascripts/ng-admin/Crud/form/FormController.js @@ -3,11 +3,12 @@ define(function () { 'use strict'; - var FormController = function ($scope, $state, WriteQueries, Configuration, + var FormController = function ($scope, $state, $stateParams, WriteQueries, Configuration, progression, notification, view, dataStore) { this.$scope = $scope; this.$state = $state; + this.$statePar = $state; this.WriteQueries = WriteQueries; this.dataStore = dataStore; this.progression = progression; @@ -131,7 +132,7 @@ define(function () { this.entity = undefined; }; - FormController.$inject = ['$scope', '$state', 'WriteQueries', 'NgAdminConfiguration', 'progression', 'notification', 'view', 'dataStore']; + FormController.$inject = ['$scope', '$state', '$stateParams', 'WriteQueries', 'NgAdminConfiguration', 'progression', 'notification', 'view', 'dataStore']; return FormController; }); diff --git a/src/javascripts/ng-admin/Crud/routing.js b/src/javascripts/ng-admin/Crud/routing.js index 302042fd..386dca37 100644 --- a/src/javascripts/ng-admin/Crud/routing.js +++ b/src/javascripts/ng-admin/Crud/routing.js @@ -157,6 +157,8 @@ define(function (require) { params: { entity: null, id: null, + page: null, + search: null, sortField: null, sortDir: null }, @@ -246,6 +248,12 @@ define(function (require) { controller: 'FormController', controllerAs: 'formController', templateProvider: templateProvider('CreateView', createTemplate), + params: { + page: null, + search: null, + sortField: null, + sortDir: null + }, resolve: { dataStore: dataStoreProvider(), view: viewProvider('CreateView'), @@ -295,6 +303,8 @@ define(function (require) { params: { entity: null, id: null, + page: null, + search: null, sortField: null, sortDir: null }, @@ -384,6 +394,12 @@ define(function (require) { controller: 'DeleteController', controllerAs: 'deleteController', templateProvider: templateProvider('DeleteView', deleteTemplate), + params: { + page: null, + search: null, + sortField: null, + sortDir: null + }, resolve: { view: viewProvider('DeleteView'), params: ['$stateParams', function ($stateParams) { @@ -404,7 +420,11 @@ define(function (require) { templateProvider: templateProvider('BatchDeleteView', batchDeleteTemplate), params: { entity: null, - ids: [] + ids: [], + page: null, + search: null, + sortField: null, + sortDir: null }, resolve: { view: viewProvider('BatchDeleteView'), From 042bea52a09cfa5881033764b8d7df5a509c0003 Mon Sep 17 00:00:00 2001 From: ThieryMichel Date: Tue, 5 May 2015 11:15:35 +0200 Subject: [PATCH 2/8] save search state for show view --- src/javascripts/ng-admin/Crud/button/maShowButton.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/javascripts/ng-admin/Crud/button/maShowButton.js b/src/javascripts/ng-admin/Crud/button/maShowButton.js index d2a82727..1056553c 100644 --- a/src/javascripts/ng-admin/Crud/button/maShowButton.js +++ b/src/javascripts/ng-admin/Crud/button/maShowButton.js @@ -16,7 +16,14 @@ define(function () { scope.label = scope.label || 'Show'; scope.gotoShow = function () { - $state.go($state.get('show'), { entity: scope.entity().name(), id: scope.entry().identifierValue }); + $state.go($state.get('show'), { + entity: scope.entity().name(), + id: scope.entry().identifierValue, + page: $state.params.page, + search: $state.params.search, + sortField: $state.params.sortField, + sortDir: $state.params.sortDir + }); }; }, template: From dd4a1973a90bafe14e6538a01ba4cbb1dfcb1ceb Mon Sep 17 00:00:00 2001 From: ThieryMichel Date: Tue, 5 May 2015 11:23:37 +0200 Subject: [PATCH 3/8] use $state.params instead of $stateParams when appropriate --- .../Crud/button/maBatchDeleteButton.js | 12 ++++---- .../ng-admin/Crud/button/maCreateButton.js | 12 ++++---- .../ng-admin/Crud/button/maDeleteButton.js | 12 ++++---- .../ng-admin/Crud/button/maEditButton.js | 12 ++++---- .../ng-admin/Crud/button/maListButton.js | 12 ++++---- .../Crud/delete/BatchDeleteController.js | 29 +++++++------------ .../ng-admin/Crud/delete/DeleteController.js | 22 +++++++------- 7 files changed, 51 insertions(+), 60 deletions(-) diff --git a/src/javascripts/ng-admin/Crud/button/maBatchDeleteButton.js b/src/javascripts/ng-admin/Crud/button/maBatchDeleteButton.js index 1a201d05..72155eea 100644 --- a/src/javascripts/ng-admin/Crud/button/maBatchDeleteButton.js +++ b/src/javascripts/ng-admin/Crud/button/maBatchDeleteButton.js @@ -3,7 +3,7 @@ define(function () { 'use strict'; - function maBatchDeleteButtonDirective($state, $stateParams) { + function maBatchDeleteButtonDirective($state) { return { restrict: 'E', scope: { @@ -22,10 +22,10 @@ define(function () { $state.go('batchDelete', { ids: ids, entity: entity.name(), - page: $stateParams.page, - search: $stateParams.search, - sortField: $stateParams.sortField, - sortDir: $stateParams.sortDir + page: $state.params.page, + search: $state.params.search, + sortField: $state.params.sortField, + sortDir: $state.params.sortDir }); }; }, @@ -37,7 +37,7 @@ define(function () { }; } - maBatchDeleteButtonDirective.$inject = ['$state', '$stateParams']; + maBatchDeleteButtonDirective.$inject = ['$state']; return maBatchDeleteButtonDirective; }); diff --git a/src/javascripts/ng-admin/Crud/button/maCreateButton.js b/src/javascripts/ng-admin/Crud/button/maCreateButton.js index 16ee26dd..0f29ff3f 100644 --- a/src/javascripts/ng-admin/Crud/button/maCreateButton.js +++ b/src/javascripts/ng-admin/Crud/button/maCreateButton.js @@ -3,7 +3,7 @@ define(function () { 'use strict'; - function maCreateButtonDirective($state, $stateParams) { + function maCreateButtonDirective($state) { return { restrict: 'E', scope: { @@ -17,10 +17,10 @@ define(function () { scope.gotoCreate = function () { $state.go($state.get('create'), { entity: scope.entity().name(), - page: $stateParams.page, - search: $stateParams.search, - sortField: $stateParams.sortField, - sortDir: $stateParams.sortDir + page: $state.params.page, + search: $state.params.search, + sortField: $state.params.sortField, + sortDir: $state.params.sortDir }); }; }, @@ -31,7 +31,7 @@ define(function () { }; } - maCreateButtonDirective.$inject = ['$state', '$stateParams']; + maCreateButtonDirective.$inject = ['$state']; return maCreateButtonDirective; }); diff --git a/src/javascripts/ng-admin/Crud/button/maDeleteButton.js b/src/javascripts/ng-admin/Crud/button/maDeleteButton.js index 742ff08d..90ab0f41 100644 --- a/src/javascripts/ng-admin/Crud/button/maDeleteButton.js +++ b/src/javascripts/ng-admin/Crud/button/maDeleteButton.js @@ -3,7 +3,7 @@ define(function () { 'use strict'; - function maDeleteButtonDirective($state, $stateParams) { + function maDeleteButtonDirective($state) { return { restrict: 'E', scope: { @@ -19,10 +19,10 @@ define(function () { $state.go($state.get('delete'), { entity: scope.entity().name(), id: scope.entry().identifierValue, - page: $stateParams.page, - search: $stateParams.search, - sortField: $stateParams.sortField, - sortDir: $stateParams.sortDir + page: $state.params.page, + search: $state.params.search, + sortField: $state.params.sortField, + sortDir: $state.params.sortDir }); }; }, @@ -34,7 +34,7 @@ define(function () { }; } - maDeleteButtonDirective.$inject = ['$state', '$stateParams']; + maDeleteButtonDirective.$inject = ['$state']; return maDeleteButtonDirective; }); diff --git a/src/javascripts/ng-admin/Crud/button/maEditButton.js b/src/javascripts/ng-admin/Crud/button/maEditButton.js index 4d4569e6..88b8bffe 100644 --- a/src/javascripts/ng-admin/Crud/button/maEditButton.js +++ b/src/javascripts/ng-admin/Crud/button/maEditButton.js @@ -3,7 +3,7 @@ define(function () { 'use strict'; - function maEditButtonDirective($state, $stateParams) { + function maEditButtonDirective($state) { return { restrict: 'E', scope: { @@ -18,10 +18,10 @@ define(function () { $state.go($state.get('edit'), { entity: scope.entity().name(), id: scope.entry().identifierValue, - page: $stateParams.page, - search: $stateParams.search, - sortField: $stateParams.sortField, - sortDir: $stateParams.sortDir + page: $state.params.page, + search: $state.params.search, + sortField: $state.params.sortField, + sortDir: $state.params.sortDir }); }; }, @@ -32,7 +32,7 @@ define(function () { }; } - maEditButtonDirective.$inject = ['$state', '$stateParams']; + maEditButtonDirective.$inject = ['$state']; return maEditButtonDirective; }); diff --git a/src/javascripts/ng-admin/Crud/button/maListButton.js b/src/javascripts/ng-admin/Crud/button/maListButton.js index 057c0ecd..b7683aa3 100644 --- a/src/javascripts/ng-admin/Crud/button/maListButton.js +++ b/src/javascripts/ng-admin/Crud/button/maListButton.js @@ -9,7 +9,7 @@ define(function () { * Usage: * */ - function maListButtonDirective($state, $stateParams) { + function maListButtonDirective($state) { return { restrict: 'E', scope: { @@ -23,10 +23,10 @@ define(function () { scope.gotoList = function () { $state.go($state.get('list'), { entity: scope.entity().name(), - search: $stateParams.search, - page: $stateParams.page, - sortDir: $stateParams.sortDir, - sortField: $stateParams.sortField + search: $state.params.search, + page: $state.params.page, + sortDir: $state.params.sortDir, + sortField: $state.params.sortField }); }; }, @@ -37,7 +37,7 @@ define(function () { }; } - maListButtonDirective.$inject = ['$state', '$stateParams']; + maListButtonDirective.$inject = ['$state']; return maListButtonDirective; }); diff --git a/src/javascripts/ng-admin/Crud/delete/BatchDeleteController.js b/src/javascripts/ng-admin/Crud/delete/BatchDeleteController.js index 5925bbcc..e70869de 100644 --- a/src/javascripts/ng-admin/Crud/delete/BatchDeleteController.js +++ b/src/javascripts/ng-admin/Crud/delete/BatchDeleteController.js @@ -3,18 +3,15 @@ define(function () { 'use strict'; - var BatchDeleteController = function ($scope, $state, $stateParams, $location, $window, WriteQueries, notification, view) { + var BatchDeleteController = function ($scope, $state, WriteQueries, notification, view) { this.$scope = $scope; this.$state = $state; - this.$stateParams = $stateParams; - this.$location = $location; - this.$window = $window; this.WriteQueries = WriteQueries; this.notification = notification; this.view = view; this.entity = view.getEntity(); - this.entityIds = $stateParams.ids; + this.entityIds = $state.params.ids; this.selection = []; // fixme: query db to get selection this.title = view.title(); this.description = view.description(); @@ -33,10 +30,10 @@ define(function () { this.WriteQueries.batchDelete(this.view, this.entityIds).then(function () { $state.go($state.get('list'), { entity: _this.entity.name(), - page: _this.$stateParams.page, - search: _this.$stateParams.search, - sortField: _this.$stateParams.sortField, - sortDir: _this.$stateParams.sortDir + page: _this.$state.params.page, + search: _this.$state.params.search, + sortField: _this.$state.params.sortField, + sortDir: _this.$state.params.sortDir }); notification.log('Elements successfully deleted.', { addnCls: 'humane-flatty-success' }); }, function (response) { @@ -53,24 +50,20 @@ define(function () { BatchDeleteController.prototype.back = function () { this.$state.go(this.$state.get('list'), { entity: this.entity.name(), - page: this.$stateParams.page, - search: this.$stateParams.search, - sortField: this.$stateParams.sortField, - sortDir: this.$stateParams.sortDir + page: this.$state.params.page, + search: this.$state.params.search, + sortField: this.$state.params.sortField, + sortDir: this.$state.params.sortDir }); }; BatchDeleteController.prototype.destroy = function () { this.$scope = undefined; this.$state = undefined; - this.$stateParams = undefined; - this.$location = undefined; - this.$window = undefined; this.WriteQueries = undefined; }; - BatchDeleteController.$inject = ['$scope', '$state', '$stateParams', '$location', '$window', 'WriteQueries', 'notification', 'view']; - + BatchDeleteController.$inject = ['$scope', '$state', 'WriteQueries', 'notification', 'view']; return BatchDeleteController; }); diff --git a/src/javascripts/ng-admin/Crud/delete/DeleteController.js b/src/javascripts/ng-admin/Crud/delete/DeleteController.js index b9b6104e..53d9fba4 100644 --- a/src/javascripts/ng-admin/Crud/delete/DeleteController.js +++ b/src/javascripts/ng-admin/Crud/delete/DeleteController.js @@ -3,10 +3,9 @@ define(function () { 'use strict'; - var DeleteController = function ($scope, $state, $stateParams, WriteQueries, notification, params, view, entry) { + var DeleteController = function ($scope, $state, WriteQueries, notification, params, view, entry) { this.$scope = $scope; this.$state = $state; - this.$stateParams = $stateParams; this.WriteQueries = WriteQueries; this.entityLabel = params.entity; this.entityId = params.id; @@ -29,10 +28,10 @@ define(function () { this.WriteQueries.deleteOne(this.view, this.entityId).then(function () { $state.go($state.get('list'), { entity: _this.entity.name(), - page: _this.$stateParams.page, - search: _this.$stateParams.search, - sortField: _this.$stateParams.sortField, - sortDir: _this.$stateParams.sortDir + page: _this.$state.params.page, + search: _this.$state.params.search, + sortField: _this.$state.params.sortField, + sortDir: _this.$state.params.sortDir }); notification.log('Element successfully deleted.', { addnCls: 'humane-flatty-success' }); }, function (response) { @@ -50,10 +49,10 @@ define(function () { this.$state.go(this.$state.get('edit'), { entity: this.entity.name(), id: this.entityId, - page: this.$stateParams.page, - search: this.$stateParams.search, - sortField: this.$stateParams.sortField, - sortDir: this.$stateParams.sortDir + page: this.$state.params.page, + search: this.$state.params.search, + sortField: this.$state.params.sortField, + sortDir: this.$state.params.sortDir }); }; @@ -61,12 +60,11 @@ define(function () { this.$scope = undefined; this.WriteQueries = undefined; this.$state = undefined; - this.$stateParams = undefined; this.view = undefined; this.entity = undefined; }; - DeleteController.$inject = ['$scope', '$state', '$stateParams', 'WriteQueries', 'notification', 'params', 'view', 'entry']; + DeleteController.$inject = ['$scope', '$state', 'WriteQueries', 'notification', 'params', 'view', 'entry']; return DeleteController; }); From b847bea26b6457fad10c130e018a77563b85667e Mon Sep 17 00:00:00 2001 From: ThieryMichel Date: Mon, 11 May 2015 09:42:06 +0200 Subject: [PATCH 4/8] code review --- .../Crud/delete/BatchDeleteController.js | 12 +++++----- .../ng-admin/Crud/delete/DeleteController.js | 23 ++++++++++--------- .../ng-admin/Crud/form/FormController.js | 5 ++-- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/javascripts/ng-admin/Crud/delete/BatchDeleteController.js b/src/javascripts/ng-admin/Crud/delete/BatchDeleteController.js index e70869de..ea596505 100644 --- a/src/javascripts/ng-admin/Crud/delete/BatchDeleteController.js +++ b/src/javascripts/ng-admin/Crud/delete/BatchDeleteController.js @@ -25,15 +25,15 @@ define(function () { BatchDeleteController.prototype.batchDelete = function () { var notification = this.notification, $state = this.$state, - _this = this; + entityName = this.entity.name(); this.WriteQueries.batchDelete(this.view, this.entityIds).then(function () { $state.go($state.get('list'), { - entity: _this.entity.name(), - page: _this.$state.params.page, - search: _this.$state.params.search, - sortField: _this.$state.params.sortField, - sortDir: _this.$state.params.sortDir + entity: entityName, + page: $state.params.page, + search: $state.params.search, + sortField: $state.params.sortField, + sortDir: $state.params.sortDir }); notification.log('Elements successfully deleted.', { addnCls: 'humane-flatty-success' }); }, function (response) { diff --git a/src/javascripts/ng-admin/Crud/delete/DeleteController.js b/src/javascripts/ng-admin/Crud/delete/DeleteController.js index 53d9fba4..d2af11dc 100644 --- a/src/javascripts/ng-admin/Crud/delete/DeleteController.js +++ b/src/javascripts/ng-admin/Crud/delete/DeleteController.js @@ -23,15 +23,15 @@ define(function () { DeleteController.prototype.deleteOne = function () { var notification = this.notification, - $state = this.$state, _this = this; + $state = this.$state, entityName = this.entity.name(); this.WriteQueries.deleteOne(this.view, this.entityId).then(function () { $state.go($state.get('list'), { - entity: _this.entity.name(), - page: _this.$state.params.page, - search: _this.$state.params.search, - sortField: _this.$state.params.sortField, - sortDir: _this.$state.params.sortDir + entity: entityName, + page: $state.params.page, + search: $state.params.search, + sortField: $state.params.sortField, + sortDir: $state.params.sortDir }); notification.log('Element successfully deleted.', { addnCls: 'humane-flatty-success' }); }, function (response) { @@ -46,13 +46,14 @@ define(function () { }; DeleteController.prototype.back = function () { - this.$state.go(this.$state.get('edit'), { + var $state = this.$state; + $state.go($state.get('edit'), { entity: this.entity.name(), id: this.entityId, - page: this.$state.params.page, - search: this.$state.params.search, - sortField: this.$state.params.sortField, - sortDir: this.$state.params.sortDir + page: $state.params.page, + search: $state.params.search, + sortField: $state.params.sortField, + sortDir: $state.params.sortDir }); }; diff --git a/src/javascripts/ng-admin/Crud/form/FormController.js b/src/javascripts/ng-admin/Crud/form/FormController.js index 815c35cd..5ccc5cea 100644 --- a/src/javascripts/ng-admin/Crud/form/FormController.js +++ b/src/javascripts/ng-admin/Crud/form/FormController.js @@ -3,12 +3,11 @@ define(function () { 'use strict'; - var FormController = function ($scope, $state, $stateParams, WriteQueries, Configuration, + var FormController = function ($scope, $state, WriteQueries, Configuration, progression, notification, view, dataStore) { this.$scope = $scope; this.$state = $state; - this.$statePar = $state; this.WriteQueries = WriteQueries; this.dataStore = dataStore; this.progression = progression; @@ -132,7 +131,7 @@ define(function () { this.entity = undefined; }; - FormController.$inject = ['$scope', '$state', '$stateParams', 'WriteQueries', 'NgAdminConfiguration', 'progression', 'notification', 'view', 'dataStore']; + FormController.$inject = ['$scope', '$state', 'WriteQueries', 'NgAdminConfiguration', 'progression', 'notification', 'view', 'dataStore']; return FormController; }); From 48fdb3b83d0e70b1a98bbe412b3dce456d7ddacb Mon Sep 17 00:00:00 2001 From: ThieryMichel Date: Mon, 11 May 2015 09:42:37 +0200 Subject: [PATCH 5/8] pass $state.params in list only if it is the same entity --- .../ng-admin/Crud/button/maListButton.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/javascripts/ng-admin/Crud/button/maListButton.js b/src/javascripts/ng-admin/Crud/button/maListButton.js index b7683aa3..6b2ed382 100644 --- a/src/javascripts/ng-admin/Crud/button/maListButton.js +++ b/src/javascripts/ng-admin/Crud/button/maListButton.js @@ -19,15 +19,18 @@ define(function () { }, link: function (scope) { scope.label = scope.label || 'List'; + var parentEntityName = scope.$parent.entity ? scope.$parent.entity.name() : null; + var entityName = scope.entity().name(); + + var params = { + entity: entityName + }; + if (entityName === parentEntityName) { + angular.extend(params, $state.params); + } scope.gotoList = function () { - $state.go($state.get('list'), { - entity: scope.entity().name(), - search: $state.params.search, - page: $state.params.page, - sortDir: $state.params.sortDir, - sortField: $state.params.sortField - }); + $state.go($state.get('list'), params); }; }, template: From 298a48160c1da8339efaafc59285f60df6c33280 Mon Sep 17 00:00:00 2001 From: ThieryMichel Date: Tue, 12 May 2015 11:20:01 +0200 Subject: [PATCH 6/8] add test --- src/javascripts/test/e2e/ListViewSpec.js | 44 ++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/javascripts/test/e2e/ListViewSpec.js b/src/javascripts/test/e2e/ListViewSpec.js index 7eff3ac9..77fbbce0 100644 --- a/src/javascripts/test/e2e/ListViewSpec.js +++ b/src/javascripts/test/e2e/ListViewSpec.js @@ -29,4 +29,48 @@ xdescribe('ListView', function () { }); }); }); + + describe('ma-list-button', function () { + var listUrl; + + beforeEach(function() { + listUrl = encodeURI(browser.baseUrl + '/#/comments/list?search={"post_id":"9"}&page=1'); + browser.get(listUrl); + }); + + it('should restore the list with filter when used from edit', function () { + browser.executeScript('window.scrollTo(810, 481)').then(function () { + $$('ma-edit-button a').then(function (elements) { + expect(elements[0].getText()).toBe(' Edit'); + elements[0].click(); + expect(browser.getCurrentUrl()).toBe(browser.baseUrl + '/#/comments/edit/2'); + $$('ma-list-button a').then(function (elements) { + elements[0].click(); + expect(browser.getCurrentUrl()).toBe(listUrl); + }); + }); + }); + }); + + it('should restore the list with filter when used from delete', function () { + browser.get(listUrl); + browser.executeScript('window.scrollTo(810, 481)').then(function () { + + $$('ma-delete-button a').then(function (elements) { + expect(elements[0].getText()).toBe(' Delete'); + elements[0].click(); + expect(browser.getCurrentUrl()).toBe(browser.baseUrl + '/#/comments/delete/2'); + $$('button.btn-default').then(function (elements) { + elements[0].click(); + expect(browser.getCurrentUrl()).toBe(browser.baseUrl + '/#/comments/edit/2'); + + $$('ma-list-button a').then(function (elements) { + elements[0].click(); + expect(browser.getCurrentUrl()).toBe(listUrl); + }); + }); + }); + }); + }); + }); }); From 0a59a961f295f3a1b88052fd0295ad0db4a0a6a2 Mon Sep 17 00:00:00 2001 From: ThieryMichel Date: Mon, 18 May 2015 15:10:13 +0200 Subject: [PATCH 7/8] code review --- .../Crud/button/maBatchDeleteButton.js | 11 ++++------ .../ng-admin/Crud/button/maCreateButton.js | 8 +------ .../ng-admin/Crud/button/maDeleteButton.js | 10 +++------ .../ng-admin/Crud/button/maEditButton.js | 11 ++++------ .../ng-admin/Crud/button/maShowButton.js | 11 ++++------ .../Crud/delete/BatchDeleteController.js | 21 +++++++------------ .../ng-admin/Crud/delete/DeleteController.js | 21 +++++++------------ 7 files changed, 31 insertions(+), 62 deletions(-) diff --git a/src/javascripts/ng-admin/Crud/button/maBatchDeleteButton.js b/src/javascripts/ng-admin/Crud/button/maBatchDeleteButton.js index 72155eea..09c8b021 100644 --- a/src/javascripts/ng-admin/Crud/button/maBatchDeleteButton.js +++ b/src/javascripts/ng-admin/Crud/button/maBatchDeleteButton.js @@ -19,14 +19,11 @@ define(function () { var ids = $scope.selection().map(function(entry) { return entry.identifierValue; }); - $state.go('batchDelete', { + + $state.go('batchDelete', angular.extend({ ids: ids, - entity: entity.name(), - page: $state.params.page, - search: $state.params.search, - sortField: $state.params.sortField, - sortDir: $state.params.sortDir - }); + entity: $scope.entity().name() + }, $state.params)); }; }, template: diff --git a/src/javascripts/ng-admin/Crud/button/maCreateButton.js b/src/javascripts/ng-admin/Crud/button/maCreateButton.js index 0f29ff3f..f5db381a 100644 --- a/src/javascripts/ng-admin/Crud/button/maCreateButton.js +++ b/src/javascripts/ng-admin/Crud/button/maCreateButton.js @@ -15,13 +15,7 @@ define(function () { scope.label = scope.label || 'Create'; scope.gotoCreate = function () { - $state.go($state.get('create'), { - entity: scope.entity().name(), - page: $state.params.page, - search: $state.params.search, - sortField: $state.params.sortField, - sortDir: $state.params.sortDir - }); + $state.go($state.get('create'), angular.extend({entity: scope.entity().name()}, $state.params)); }; }, template: diff --git a/src/javascripts/ng-admin/Crud/button/maDeleteButton.js b/src/javascripts/ng-admin/Crud/button/maDeleteButton.js index 90ab0f41..53e561c1 100644 --- a/src/javascripts/ng-admin/Crud/button/maDeleteButton.js +++ b/src/javascripts/ng-admin/Crud/button/maDeleteButton.js @@ -16,14 +16,10 @@ define(function () { scope.label = scope.label || 'Delete'; scope.gotoDelete = function () { - $state.go($state.get('delete'), { + $state.go($state.get('delete'), angular.extend({ entity: scope.entity().name(), - id: scope.entry().identifierValue, - page: $state.params.page, - search: $state.params.search, - sortField: $state.params.sortField, - sortDir: $state.params.sortDir - }); + id: scope.entry().identifierValue + }, $state.params)); }; }, template: diff --git a/src/javascripts/ng-admin/Crud/button/maEditButton.js b/src/javascripts/ng-admin/Crud/button/maEditButton.js index 88b8bffe..8bfefdbe 100644 --- a/src/javascripts/ng-admin/Crud/button/maEditButton.js +++ b/src/javascripts/ng-admin/Crud/button/maEditButton.js @@ -15,14 +15,11 @@ define(function () { link: function (scope) { scope.label = scope.label || 'Edit'; scope.gotoEdit = function () { - $state.go($state.get('edit'), { + $state.go($state.get('edit'), + angular.extend({ entity: scope.entity().name(), - id: scope.entry().identifierValue, - page: $state.params.page, - search: $state.params.search, - sortField: $state.params.sortField, - sortDir: $state.params.sortDir - }); + id: scope.entry().identifierValue + }, $state.params)); }; }, template: diff --git a/src/javascripts/ng-admin/Crud/button/maShowButton.js b/src/javascripts/ng-admin/Crud/button/maShowButton.js index 1056553c..bd6563c1 100644 --- a/src/javascripts/ng-admin/Crud/button/maShowButton.js +++ b/src/javascripts/ng-admin/Crud/button/maShowButton.js @@ -16,14 +16,11 @@ define(function () { scope.label = scope.label || 'Show'; scope.gotoShow = function () { - $state.go($state.get('show'), { + $state.go($state.get('show'), + angular.extend({ entity: scope.entity().name(), - id: scope.entry().identifierValue, - page: $state.params.page, - search: $state.params.search, - sortField: $state.params.sortField, - sortDir: $state.params.sortDir - }); + id: scope.entry().identifierValue + }, $state.params)); }; }, template: diff --git a/src/javascripts/ng-admin/Crud/delete/BatchDeleteController.js b/src/javascripts/ng-admin/Crud/delete/BatchDeleteController.js index ea596505..33243b33 100644 --- a/src/javascripts/ng-admin/Crud/delete/BatchDeleteController.js +++ b/src/javascripts/ng-admin/Crud/delete/BatchDeleteController.js @@ -28,13 +28,9 @@ define(function () { entityName = this.entity.name(); this.WriteQueries.batchDelete(this.view, this.entityIds).then(function () { - $state.go($state.get('list'), { - entity: entityName, - page: $state.params.page, - search: $state.params.search, - sortField: $state.params.sortField, - sortDir: $state.params.sortDir - }); + $state.go($state.get('list'), angular.extend({ + entity: entityName + }, $state.params)); notification.log('Elements successfully deleted.', { addnCls: 'humane-flatty-success' }); }, function (response) { // @TODO: share this method when splitting controllers @@ -48,13 +44,10 @@ define(function () { }; BatchDeleteController.prototype.back = function () { - this.$state.go(this.$state.get('list'), { - entity: this.entity.name(), - page: this.$state.params.page, - search: this.$state.params.search, - sortField: this.$state.params.sortField, - sortDir: this.$state.params.sortDir - }); + + this.$state.go(this.$state.get('list'), angular.extend({ + entity: this.entity().name() + }, this.$state.params)); }; BatchDeleteController.prototype.destroy = function () { diff --git a/src/javascripts/ng-admin/Crud/delete/DeleteController.js b/src/javascripts/ng-admin/Crud/delete/DeleteController.js index d2af11dc..049d78f2 100644 --- a/src/javascripts/ng-admin/Crud/delete/DeleteController.js +++ b/src/javascripts/ng-admin/Crud/delete/DeleteController.js @@ -26,13 +26,11 @@ define(function () { $state = this.$state, entityName = this.entity.name(); this.WriteQueries.deleteOne(this.view, this.entityId).then(function () { - $state.go($state.get('list'), { + + $state.go($state.get('list'), angular.extend({ entity: entityName, - page: $state.params.page, - search: $state.params.search, - sortField: $state.params.sortField, - sortDir: $state.params.sortDir - }); + id: this.entityId + }, $state.params)); notification.log('Element successfully deleted.', { addnCls: 'humane-flatty-success' }); }, function (response) { // @TODO: share this method when splitting controllers @@ -47,14 +45,11 @@ define(function () { DeleteController.prototype.back = function () { var $state = this.$state; - $state.go($state.get('edit'), { + + $state.go($state.get('edit'), angular.extend({ entity: this.entity.name(), - id: this.entityId, - page: $state.params.page, - search: $state.params.search, - sortField: $state.params.sortField, - sortDir: $state.params.sortDir - }); + id: this.entityId + }, $state.params)); }; DeleteController.prototype.destroy = function () { From 3c3245247e20e9f38df541c21be8aae31928eff3 Mon Sep 17 00:00:00 2001 From: ThieryMichel Date: Tue, 19 May 2015 14:11:24 +0200 Subject: [PATCH 8/8] skip test --- src/javascripts/test/e2e/ListViewSpec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/javascripts/test/e2e/ListViewSpec.js b/src/javascripts/test/e2e/ListViewSpec.js index 77fbbce0..39dd1bec 100644 --- a/src/javascripts/test/e2e/ListViewSpec.js +++ b/src/javascripts/test/e2e/ListViewSpec.js @@ -30,7 +30,7 @@ xdescribe('ListView', function () { }); }); - describe('ma-list-button', function () { + xdescribe('ma-list-button', function () { var listUrl; beforeEach(function() { @@ -38,7 +38,7 @@ xdescribe('ListView', function () { browser.get(listUrl); }); - it('should restore the list with filter when used from edit', function () { + xit('should restore the list with filter when used from edit', function () { browser.executeScript('window.scrollTo(810, 481)').then(function () { $$('ma-edit-button a').then(function (elements) { expect(elements[0].getText()).toBe(' Edit'); @@ -52,7 +52,7 @@ xdescribe('ListView', function () { }); }); - it('should restore the list with filter when used from delete', function () { + xit('should restore the list with filter when used from delete', function () { browser.get(listUrl); browser.executeScript('window.scrollTo(810, 481)').then(function () {