From 333422c48f84bb3290769f34be3f9d97b80fe525 Mon Sep 17 00:00:00 2001 From: Francois Zaninotto Date: Wed, 2 Sep 2015 13:25:54 +0200 Subject: [PATCH] Fix bug where filters are freezed when url changes --- .../ng-admin/Crud/filter/maFilter.js | 3 +-- .../Crud/list/ListLayoutController.js | 22 ++++++++++++++----- .../ng-admin/Crud/list/listLayout.html | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/javascripts/ng-admin/Crud/filter/maFilter.js b/src/javascripts/ng-admin/Crud/filter/maFilter.js index de04c524..bcbee482 100644 --- a/src/javascripts/ng-admin/Crud/filter/maFilter.js +++ b/src/javascripts/ng-admin/Crud/filter/maFilter.js @@ -32,11 +32,10 @@ function maFilterDirective(FieldViewConfiguration) { scope: { filters: '=', datastore: '&', - values: '&', + values: '=', removeFilter: '&' }, link: function(scope) { - scope.values = scope.values(); scope.datastore = scope.datastore(); scope.removeFilter = scope.removeFilter(); scope.shouldFilter = () => Object.keys(scope.filters).length; diff --git a/src/javascripts/ng-admin/Crud/list/ListLayoutController.js b/src/javascripts/ng-admin/Crud/list/ListLayoutController.js index c28a6474..d42d256e 100644 --- a/src/javascripts/ng-admin/Crud/list/ListLayoutController.js +++ b/src/javascripts/ng-admin/Crud/list/ListLayoutController.js @@ -10,11 +10,23 @@ var ListLayoutController = function ($scope, $stateParams, $state, $location, $t this.batchActions = view.batchActions(); this.loadingPage = false; this.search = $location.search().search ? JSON.parse($location.search().search) : {}; - $scope.$watch(() => this.search, _.debounce((newValues, oldValues) => { - if (newValues != oldValues) { - this.updateFilters(); - } - }, 500), true); + // since search isn't a $stateParam of the listLayout state, + // the controller doesn't change when the search changes + // so we must update filter values manually when the location changes + $scope.$watch( + () => $location.search() && $location.search().search, + newValues => this.search = $location.search().search ? JSON.parse($location.search().search) : {} + ); + // apply filters when filter values change + $scope.$watch( + () => this.search, + _.debounce((newValues, oldValues) => { + if (newValues != oldValues) { + this.updateFilters(); + } + }, 500), + true + ); this.filters = view.filters(); this.enabledFilters = this.filters.filter(filter => { if (filter.pinned()) return true; diff --git a/src/javascripts/ng-admin/Crud/list/listLayout.html b/src/javascripts/ng-admin/Crud/list/listLayout.html index e2a1a7a8..4bfadae1 100644 --- a/src/javascripts/ng-admin/Crud/list/listLayout.html +++ b/src/javascripts/ng-admin/Crud/list/listLayout.html @@ -14,7 +14,7 @@

{{ ::llCtrl.view.description() }}

- +