Finish numeric_range_filter

This commit is contained in:
2018-11-28 11:38:43 -03:00
19 changed files with 207 additions and 12379 deletions
@@ -0,0 +1,76 @@
import Ember from 'ember';
import Component from '@ember/component';
export default Component.extend({
tagName: 'th',
classNames: ['filter', 'filter-pablo-number-range'],
classNameBindings: ['has_active_filter_value:active-filter'],
placeholder: '[ ... ]',
display_addition: '',
apply_filters: function apply_filters() { },
eager_filter: true,
has_active_filter_value: Ember.computed.or('lower_bound', 'upper_bound'),
lower_bound_candidate: '1',
upper_bound_candidate: '3',
filter_text: Ember.computed('{lower_bound,upper_bound,display_addition,inclusive}', function () {
var lower_limit, upper_limit, range, isInclusive;
isInclusive = this.get('inclusive');
lower_limit = this.get('lower_bound') || '-';
upper_limit = this.get('upper_bound') || '-';
range = isInclusive ? `[${lower_limit}, ${upper_limit}]` : `(${lower_limit}, ${upper_limit})`;
if (this.get('display_addition')) {
range += " " + this.get('display_addition');
}
return range;
}),
init: function init() {
this._super();
this.set('error', '');
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');
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'}`));
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', '');
let lbc = this.get('lower_bound_candidate');
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 }));
console.log(this.error);
} else {
this.set('lower_bound', lbc || '');
this.set('upper_bound', hbc || '');
this.$('.dropdown').dropdown('hide');
if (this.get('eager_filter')) {
return this.get('apply_filters')(this);
}
}
},
clear_filters: function clear_filters() {
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');
this.$('.dropdown').dropdown('hide');
return this.get('apply_filters')(this);
}
}
});
+1
View File
@@ -0,0 +1 @@
export { default } from 'ember-cli-dunlop/components/user-filters-manager';