inclusive: change operator instead of lower/upper limits

This commit is contained in:
Pablo Bañales
2018-11-27 11:50:23 -03:00
parent 82451218be
commit 32bf998a65
2 changed files with 14 additions and 16 deletions
@@ -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');
@@ -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 &harr; 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'