Skip to content

Commit

Permalink
Merge pull request #1366 from marmelab/fix-pinned-filter-initialization
Browse files Browse the repository at this point in the history
[RFR] Update filters on view initialization
  • Loading branch information
Kmaschta authored Sep 29, 2017
2 parents 3828607 + 234d4aa commit eb8b125
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
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

0 comments on commit eb8b125

Please sign in to comment.