Skip to content

Commit

Permalink
Fix bug where filters are freezed when url changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fzaninotto committed Sep 2, 2015
1 parent e60ea22 commit 333422c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/javascripts/ng-admin/Crud/filter/maFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 17 additions & 5 deletions src/javascripts/ng-admin/Crud/list/ListLayoutController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/javascripts/ng-admin/Crud/list/listLayout.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h1 compile="::llCtrl.view.title()">
<p class="lead" ng-if="::llCtrl.view.description()" compile="::llCtrl.view.description()">{{ ::llCtrl.view.description() }}</p>
</div>

<ma-filter ng-if="llCtrl.hasFilters" filters="llCtrl.enabledFilters" values="::llCtrl.search" datastore="::llCtrl.dataStore" remove-filter="::llCtrl.removeFilter"></ma-filter>
<ma-filter ng-if="llCtrl.hasFilters" filters="llCtrl.enabledFilters" values="llCtrl.search" datastore="::llCtrl.dataStore" remove-filter="::llCtrl.removeFilter"></ma-filter>

</div>
</div>
Expand Down

0 comments on commit 333422c

Please sign in to comment.