-
Notifications
You must be signed in to change notification settings - Fork 105
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
Refactor bhFilters with Filter Component (2653) #3107
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
angular.module('bhima.components') | ||
.component('bhFilter', { | ||
templateUrl : 'modules/templates/bhFilter.tmpl.html', | ||
controller : bhFilterController, | ||
bindings : { | ||
filter : '<', | ||
onRemove : '&', | ||
} | ||
, | ||
}); | ||
|
||
function bhFilterController() { | ||
const $ctrl = this; | ||
const DEFAULT_FILTER_COMPARITOR = ':'; | ||
|
||
$ctrl.$onInit = function onInit() { | ||
// fill in label details required by the template | ||
$ctrl.filter = $ctrl.filter || {}; | ||
$ctrl.filter.comparitorLabel = $ctrl.filter._comparitor || DEFAULT_FILTER_COMPARITOR; | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<span data="filter"> | ||
<span class="label" ng-class="{ 'label-primary' : $ctrl.filter._isDefault, 'label-emphasize' : !$ctrl.filter._isDefault }"> | ||
<i class="fa fa-filter"></i> | ||
|
||
<span translate>{{$ctrl.filter._label}}</span> | ||
<span>{{$ctrl.filter.comparitorLabel}}</span> | ||
<span>{{$ctrl.filter.displayValue}}</span> | ||
|
||
<!-- optional close button, displayed if this is not a default filter --> | ||
<a | ||
href | ||
ng-if="!$ctrl.filter._isDefault" | ||
ng-click="$ctrl.onRemove({ filter: $ctrl.filter._key })" | ||
class="filter-text-link"> | ||
|
||
<i class="fa fa-close"></i> | ||
</a> | ||
</span> | ||
</span> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,31 +7,18 @@ | |
<!-- | ||
TODO: these should be a custom CSS class. Label is just too small! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a big deal, but this comment really applies to the component's HTML, not the outside template. It should probably be removed or placed there. |
||
--> | ||
<span class="label label-emphasize"> | ||
<i class="fa fa-filter"></i> | ||
<span translate>{{filter._label}}</span> {{ filter._comparitor ? " " + filter._comparitor : ":" }} | ||
{{ filter.displayValue }} | ||
</span> | ||
<bh-filter filter="filter"></bh-filter> | ||
</li> | ||
</ul> | ||
|
||
<!-- Separator between filter types --> | ||
<div ng-if="$ctrl.filters.defaultFilters.length && $ctrl.filters.customFilters.length" style="display : inline-block; width : 1px; height: 25px; vertical-align : top; background-color : #ccc;"></div> | ||
|
||
<ul ng-if="$ctrl.filters.customFilters.length" class="list-inline filter-list" data-bh-filter-bar-custom-filters> | ||
|
||
<li ng-repeat="filter in $ctrl.filters.customFilters"> | ||
<span class="label label-primary"> | ||
<i class="fa fa-filter"></i> | ||
<span translate>{{filter._label}}</span> | ||
{{ filter._comparitor ? " " + filter._comparitor : ":" }} | ||
{{ filter.displayValue }} | ||
|
||
<a ng-if="!filter.isDefault" href ng-click="$ctrl.onRemoveFilter({ filter : filter._key })" | ||
style="color:#fff; margin-left:5px;"> | ||
<i class="fa fa-close"></i> | ||
</a> | ||
|
||
</span> | ||
<!-- on-remove is passing an object containing 'locals' (variables) as part of the Angular --> | ||
<!-- component callback structure - these methods are not directly called but are wrapper methods --> | ||
<bh-filter filter="filter" on-remove="$ctrl.onRemoveFilter({ filter: filter})"></bh-filter> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very clean 👍 |
||
</li> | ||
</ul> |
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.
Sweet 👍