Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFR]remember list filter when navigating on same entity. #418

Merged
merged 8 commits into from
May 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/javascripts/ng-admin/Crud/button/maBatchDeleteButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ 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() });

$state.go('batchDelete', angular.extend({
ids: ids,
entity: $scope.entity().name()
}, $state.params));
};
},
template:
Expand Down
2 changes: 1 addition & 1 deletion src/javascripts/ng-admin/Crud/button/maCreateButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ define(function () {
scope.label = scope.label || 'Create';

scope.gotoCreate = function () {
$state.go($state.get('create'), { 'entity': scope.entity().name() });
$state.go($state.get('create'), angular.extend({entity: scope.entity().name()}, $state.params));
};
},
template:
Expand Down
5 changes: 4 additions & 1 deletion src/javascripts/ng-admin/Crud/button/maDeleteButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ 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'), angular.extend({
entity: scope.entity().name(),
id: scope.entry().identifierValue
}, $state.params));
};
},
template:
Expand Down
7 changes: 5 additions & 2 deletions src/javascripts/ng-admin/Crud/button/maEditButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ 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'),
angular.extend({
entity: scope.entity().name(),
id: scope.entry().identifierValue
}, $state.params));
};
},
template:
Expand Down
13 changes: 11 additions & 2 deletions src/javascripts/ng-admin/Crud/button/maListButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ define(function () {

/**
* Link to list
*
*
* Usage:
* <ma-list-button entity="entity" size="xs"></ma-list-button>
*/
Expand All @@ -19,9 +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() });
$state.go($state.get('list'), params);
};
},
template:
Expand Down
6 changes: 5 additions & 1 deletion src/javascripts/ng-admin/Crud/button/maShowButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ 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'),
angular.extend({
entity: scope.entity().name(),
id: scope.entry().identifierValue
}, $state.params));
};
},
template:
Expand Down
22 changes: 11 additions & 11 deletions src/javascripts/ng-admin/Crud/delete/BatchDeleteController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +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();
Expand All @@ -30,7 +28,9 @@ define(function () {
entityName = this.entity.name();

this.WriteQueries.batchDelete(this.view, this.entityIds).then(function () {
$state.go($state.get('list'), { 'entity': entityName });
$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
Expand All @@ -44,19 +44,19 @@ define(function () {
};

BatchDeleteController.prototype.back = function () {
this.$window.history.back();

this.$state.go(this.$state.get('list'), angular.extend({
entity: this.entity().name()
}, this.$state.params));
};

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;
});
24 changes: 16 additions & 8 deletions src/javascripts/ng-admin/Crud/delete/DeleteController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
define(function () {
'use strict';

var DeleteController = function ($scope, $location, WriteQueries, notification, params, view, entry) {
var DeleteController = function ($scope, $state, WriteQueries, notification, params, view, entry) {
this.$scope = $scope;
this.$location = $location;
this.$state = $state;
this.WriteQueries = WriteQueries;
this.entityLabel = params.entity;
this.entityId = params.id;
Expand All @@ -23,11 +23,14 @@ define(function () {

DeleteController.prototype.deleteOne = function () {
var notification = this.notification,
$location = this.$location,
entityLabel = this.entityLabel;
$state = this.$state, entityName = this.entity.name();

this.WriteQueries.deleteOne(this.view, this.entityId).then(function () {
$location.path(entityLabel + '/list');

$state.go($state.get('list'), angular.extend({
entity: entityName,
id: this.entityId
}, $state.params));
notification.log('Element successfully deleted.', { addnCls: 'humane-flatty-success' });
}, function (response) {
// @TODO: share this method when splitting controllers
Expand All @@ -41,18 +44,23 @@ define(function () {
};

DeleteController.prototype.back = function () {
this.$location.path(this.entityLabel + '/edit/' + this.entityId);
var $state = this.$state;

$state.go($state.get('edit'), angular.extend({
entity: this.entity.name(),
id: this.entityId
}, $state.params));
};

DeleteController.prototype.destroy = function () {
this.$scope = undefined;
this.$location = undefined;
this.WriteQueries = undefined;
this.$state = undefined;
this.view = undefined;
this.entity = undefined;
};

DeleteController.$inject = ['$scope', '$location', 'WriteQueries', 'notification', 'params', 'view', 'entry'];
DeleteController.$inject = ['$scope', '$state', 'WriteQueries', 'notification', 'params', 'view', 'entry'];

return DeleteController;
});
22 changes: 21 additions & 1 deletion src/javascripts/ng-admin/Crud/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ define(function (require) {
params: {
entity: null,
id: null,
page: null,
search: null,
sortField: null,
sortDir: null
},
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -295,6 +303,8 @@ define(function (require) {
params: {
entity: null,
id: null,
page: null,
search: null,
sortField: null,
sortDir: null
},
Expand Down Expand Up @@ -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) {
Expand All @@ -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'),
Expand Down
44 changes: 44 additions & 0 deletions src/javascripts/test/e2e/ListViewSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,48 @@ xdescribe('ListView', function () {
});
});
});

xdescribe('ma-list-button', function () {
var listUrl;

beforeEach(function() {
listUrl = encodeURI(browser.baseUrl + '/#/comments/list?search={"post_id":"9"}&page=1');
browser.get(listUrl);
});

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');
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);
});
});
});
});

xit('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);
});
});
});
});
});
});
});