This repository has been archived by the owner on Jan 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added QueryStringService and filter-field directive to replace the qu…
…ery string logic in the controller
- Loading branch information
Showing
5 changed files
with
47 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
app.directive('filterField', function () { | ||
return { | ||
restrict: 'E', | ||
scope: { | ||
filters: '=', | ||
field: '@' | ||
}, | ||
template: '<input type="search" class="form-control" placeholder="filter" ng-model="filters[field]" ng-model-options="{ debounce: 250 }" ng-change="doFilter()">', | ||
controller: function ($scope, $location) { | ||
$scope.doFilter = function () { | ||
// update the query string | ||
if ($scope.filters[$scope.field] != '') { | ||
$location.search($scope.field, $scope.filters[$scope.field]); | ||
} else { | ||
// remove from query string if empty | ||
$location.search($scope.field, null); | ||
} | ||
} | ||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
|
||
// This service reads data from the query string into a filter object. | ||
app.service('QueryStringService', function ($location) { | ||
|
||
this.getFilters = function(filterObj) { | ||
var qs = $location.search(); | ||
for (var param in filterObj) { | ||
if (param in qs) { | ||
filterObj[param] = qs[param]; | ||
} | ||
} | ||
return filterObj; | ||
}; | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters