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] Update filters on view initialization #1366

Merged
merged 1 commit into from
Sep 29, 2017
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
4 changes: 4 additions & 0 deletions src/javascripts/ng-admin/Crud/list/ListLayoutController.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export default class ListLayoutController {
$scope.selection = [];
}

if(this.hasFilters){
this.updateFilters();
}

$scope.$on('$destroy', this.destroy.bind(this));
}

Expand Down
38 changes: 37 additions & 1 deletion src/javascripts/test/unit/Crud/list/ListLayoutControllerSpec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,42 @@
/*global describe,it,expect,beforeEach*/
import ListLayoutController, {getCurrentSearchParam} from '../../../../ng-admin/Crud/list/ListLayoutController'

describe('ListLayoutController', function () {
var getCurrentSearchParam = require('../../../../ng-admin/Crud/list/ListLayoutController').getCurrentSearchParam;
describe('constructor', () => {
it('should update filters if initialized with any', () => {
spyOn(ListLayoutController.prototype, 'updateFilters');
spyOn(ListLayoutController, 'getCurrentSearchParam')
.and.returnValue({});

const $scope = {
$watch: () => {},
$on: () => {},
};

const $location = {
path: () => '/my_entity',
search: () => '',
};

const view = {
getEntity: () => 'my_entity',
batchActions: () => [],
actions: () => [],
filters: () => [{
my_column: 17,
pinned: () => true,
}],
};

const listLayoutController = new ListLayoutController(
$scope, null, null, $location, null, view, null
);

expect(ListLayoutController.prototype.updateFilters)
.toHaveBeenCalled();
});
});


describe('getCurrentSearchParam', function () {
it('should return search url parameter mapped by filter', function () {
Expand Down