-
Notifications
You must be signed in to change notification settings - Fork 104
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
Feature: ui grid filtering #507
Merged
sfount
merged 3 commits into
IMA-WorldHealth:master
from
jniles:feature-ui-grid-filtering
Jun 21, 2016
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,58 @@ | ||
angular.module('bhima.components') | ||
.component('bhFiltersApplied', { | ||
templateUrl : 'partials/templates/bhFiltersApplied.tmpl.html', | ||
controller : bhFiltersAppliedController, | ||
bindings: { | ||
filters: '=' | ||
filters: '<', | ||
onRemoveFilter: '&' // fires to remove the filter | ||
} | ||
}); | ||
|
||
bhFiltersAppliedController.$inject = [ '$scope', '$filter' ]; | ||
|
||
/** | ||
* @class bhFiltersApplied | ||
* | ||
* @description | ||
* The bhFiltersApplied directive watches the component boundary for changes in | ||
* the filters passed in. Filters appear as a list of JSON objects, with a | ||
* similar API to ui grid. At minimum, they must contain: | ||
* 1. displayName (this will be passed through $translate as the column name) | ||
* 2. value | ||
* They can optionally contain: | ||
* 1. comparitor (usually ">", "<", etc) | ||
* 2. filter (an angular or custom filter to apply to the value) | ||
* | ||
* When the filters change, the values are re-digested. Each filter also has an | ||
* "X" button, which simply calls `onRemoveFilter()`. It is up to the parent | ||
* controller to determine what should happen in this case. | ||
* | ||
* @example | ||
* var filters = [ | ||
* { displayName : 'SOME.COLUMN', value: 5 }, | ||
* { displayName : 'SOME.DATE.COLUMN', value : '06/12/1993', filter: 'moment' } | ||
* ]; | ||
* | ||
* // in the HTML, it will look something like: | ||
* // <bh-filters-applied | ||
* // filters="SomeCtrl.filters" | ||
* // on-remove-filter="SomeCtrl.removeFilter"> | ||
* // </bh-filters-applied> | ||
*/ | ||
function bhFiltersAppliedController($scope, $filter) { | ||
|
||
$scope.$watch('$ctrl.filters', formatViewValues); | ||
|
||
// formats the viewValue according to any filters passed in | ||
function formatViewValues(filters) { | ||
if (!filters) { return; } | ||
|
||
filters.forEach(function (filter) { | ||
if (filter.ngFilter) { | ||
filter.viewValue = $filter(filter.ngFilter)(filter.value); | ||
} else { | ||
filter.viewValue = filter.value; | ||
} | ||
}); | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you leave a quick comment explaining what this directive does?
Just to make sure I have it straight
A very short reasoning behind the $watch may be useful for the next developer working on filters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'll do that in a second and ping you back when it is complete.