diff --git a/app/components/table-filters/pablo-number-range.js b/app/components/table-filters/pablo-number-range.js index 1dc7ad5..4ab2d4b 100644 --- a/app/components/table-filters/pablo-number-range.js +++ b/app/components/table-filters/pablo-number-range.js @@ -26,26 +26,24 @@ export default Component.extend({ init: function init() { this._super(); this.set('error', ''); - Ember.defineProperty(this, 'lower_bound', Ember.computed.alias(`filters.${this.get('key')}_gteq`)); - Ember.defineProperty(this, 'upper_bound', Ember.computed.alias(`filters.${this.get('key')}_lteq`)); + const isInclusive = this.get('inclusive'); + Ember.defineProperty(this, 'lower_bound', + Ember.computed.alias(`filters.${this.get('key')}${isInclusive ? '_gteq' : '_gt'}`)); + Ember.defineProperty(this, 'upper_bound', + Ember.computed.alias(`filters.${this.get('key')}${isInclusive ? '_lteq' : '_lt'}`)); }, actions: { toggle_inclusive() { this.set('inclusive', !this.get('inclusive')); const isInclusive = this.get('inclusive'); - var lbc = this.get('lower_bound_candidate'); - var hbc = this.get('upper_bound_candidate'); - if (!isInclusive) { - lbc++; - hbc--; - } else { - lbc-- - hbc++ - } + Ember.defineProperty(this, 'lower_bound', + Ember.computed.alias(`filters.${this.get('key')}${isInclusive ? '_gteq' : '_gt'}`)); + Ember.defineProperty(this, 'upper_bound', + Ember.computed.alias(`filters.${this.get('key')}${isInclusive ? '_lteq' : '_lt'}`)); - this.set(`lower_bound_candidate`, lbc); - this.set(`upper_bound_candidate`, hbc); + delete this.filters[`${this.get('key')}${isInclusive ? '_gt' : '_gteq'}`]; + delete this.filters[`${this.get('key')}${isInclusive ? '_lt' : '_lteq'}`]; }, set_filter: function set_filter(key, value) { this.set('error', ''); @@ -53,7 +51,7 @@ export default Component.extend({ let hbc = this.get('upper_bound_candidate'); if (hbc < lbc) { - this.set('error', t('number.range.lower_larger_than_upper_error', {lower: lbc, upper: hbc})); + this.set('error', t('number.range.lower_larger_than_upper_error', { lower: lbc, upper: hbc })); console.log(this.error); } else { this.set('lower_bound', lbc || ''); @@ -65,9 +63,9 @@ export default Component.extend({ } }, clear_filters: function clear_filters() { - this.set('lower_bound', ''); this.set('inclusive', true); this.set('error', ''); + this.set('lower_bound', ''); this.set('upper_bound', ''); this.set('lower_bound_candidate', '1'); this.set('upper_bound_candidate', '3'); diff --git a/tests/dummy/app/templates/table-filters/test1.emblem b/tests/dummy/app/templates/table-filters/test1.emblem index cad9005..2f12cb7 100644 --- a/tests/dummy/app/templates/table-filters/test1.emblem +++ b/tests/dummy/app/templates/table-filters/test1.emblem @@ -28,7 +28,7 @@ table.ui.celled.striped.compact.table.sortable button.ui.mini.primary.button{action 'set_filter_target_date_this_week'}= t 'date.this_week' ' button.ui.mini.primary.button{action 'set_filter_target_date_next_fifteen_weeks'} Nu ↔ 15 weken - = filter.pablo-number-range key='pablos' inclusive=true + = filter.pablo-number-range key='pablos' inclusive=false = filter.number-range key='age' inclusive=true = filter.dropdown-select-multiple key='dropdown_select_multiple_ids_in' options=scenario_classification_objects labelPath='grumpy' = filter.select-multiple key='select_multiple_modal_ids_in' options=scenario_classification_objects valueKey='id' textKey='grumpy'