From 0a4895367a694709ae45274000539170c80dabb7 Mon Sep 17 00:00:00 2001 From: Steven Fountain Date: Thu, 30 Aug 2018 19:13:40 +0100 Subject: [PATCH 1/2] feat(filters): implement bhFilter component This commit introduces the new `bhFilter` component that is responsible for renering a `filter` object passed from `bhFilters`. This component significantly cleans up the markup and will allow developers to use one off filters without including the full filters bar component. Usage: ```html ``` --- client/src/css/structure.css | 5 +++++ client/src/js/components/bhFilter.js | 21 +++++++++++++++++++ .../src/modules/templates/bhFilter.tmpl.html | 19 +++++++++++++++++ .../src/modules/templates/bhFilters.tmpl.html | 21 ++++--------------- 4 files changed, 49 insertions(+), 17 deletions(-) create mode 100644 client/src/js/components/bhFilter.js create mode 100644 client/src/modules/templates/bhFilter.tmpl.html diff --git a/client/src/css/structure.css b/client/src/css/structure.css index 0f62de597d..2042f97af7 100644 --- a/client/src/css/structure.css +++ b/client/src/css/structure.css @@ -931,6 +931,11 @@ a[disabled] { padding-left : 5px; } +.filter-text-link { + color: #fff; + margin-left: 5px; +} + .strike { text-decoration : line-through; } diff --git a/client/src/js/components/bhFilter.js b/client/src/js/components/bhFilter.js new file mode 100644 index 0000000000..c54c7f891a --- /dev/null +++ b/client/src/js/components/bhFilter.js @@ -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; + }; +} diff --git a/client/src/modules/templates/bhFilter.tmpl.html b/client/src/modules/templates/bhFilter.tmpl.html new file mode 100644 index 0000000000..c72f0b392a --- /dev/null +++ b/client/src/modules/templates/bhFilter.tmpl.html @@ -0,0 +1,19 @@ + + + + + {{$ctrl.filter._label}} + {{$ctrl.filter.comparitorLabel}} + {{$ctrl.filter.displayValue}} + + + + + + + + diff --git a/client/src/modules/templates/bhFilters.tmpl.html b/client/src/modules/templates/bhFilters.tmpl.html index 082ada5c62..a42eff8ff6 100644 --- a/client/src/modules/templates/bhFilters.tmpl.html +++ b/client/src/modules/templates/bhFilters.tmpl.html @@ -7,11 +7,7 @@ - - - {{filter._label}} {{ filter._comparitor ? " " + filter._comparitor : ":" }} - {{ filter.displayValue }} - + @@ -19,19 +15,10 @@
From 7479b84f3af3cad0a41e6ee22657325697bc710a Mon Sep 17 00:00:00 2001 From: Steven Fountain Date: Thu, 30 Aug 2018 19:20:38 +0100 Subject: [PATCH 2/2] chore(filters): lint issues on bhFilters ctrl This commit resolve `bhFilters` controller lint issues updating the code to repository standards. --- client/src/js/components/bhFilters.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/client/src/js/components/bhFilters.js b/client/src/js/components/bhFilters.js index b9afc34906..4c985ec935 100644 --- a/client/src/js/components/bhFilters.js +++ b/client/src/js/components/bhFilters.js @@ -1,22 +1,22 @@ angular.module('bhima.components') -.component('bhFilters', { - templateUrl : 'modules/templates/bhFilters.tmpl.html', - controller : bhFiltersController, - bindings : { - filters : '<', - onRemoveFilter : '&', // fires to remove the filter - }, -}); + .component('bhFilters', { + templateUrl : 'modules/templates/bhFilters.tmpl.html', + controller : bhFiltersController, + bindings : { + filters : '<', + onRemoveFilter : '&', + }, + }); bhFiltersController.$inject = ['$filter']; function bhFiltersController($filter) { - var $ctrl = this; + const $ctrl = this; // formats the $viewValue according to any filters passed in $ctrl.$onChanges = function onChanges(changes) { if (!changes.filters) { return; } - var filters = changes.filters.currentValue; + const filters = changes.filters.currentValue; if (!filters) { return; }