, >=, <, <=
}
},
- computed: {
- comparatorSymbol() {
- switch(this.comparator) {
- case '=': return '=';
- case '!=': return '≠';
- case '>': return '>';
- case '>=': return '≥';
- case '<': return '<';
- case '<=': return '≤';
- default: return '';
- }
- }
- },
watch: {
'query': {
handler() {
@@ -110,6 +66,41 @@
deep: true
}
},
+ created() {
+ this.comparatorsObject = {
+ '=': {
+ symbol: '=',
+ label: this.$i18n.get('is_equal_to'),
+ enabled: this.filterTypeOptions.comparators.indexOf('=') < 0 ? 'no' : 'yes'
+ },
+ '!=': {
+ symbol: '≠',
+ label: this.$i18n.get('is_not_equal_to'),
+ enabled: this.filterTypeOptions.comparators.indexOf('!=') < 0 ? 'no' : 'yes'
+ },
+ '>': {
+ symbol: '>',
+ label: this.$i18n.get('greater_than'),
+ enabled: this.filterTypeOptions.comparators.indexOf('>') < 0 ? 'no' : 'yes'
+ },
+ '>=': {
+ symbol: '≥',
+ label: this.$i18n.get('greater_than_or_equal_to'),
+ enabled: this.filterTypeOptions.comparators.indexOf('>=') < 0 ? 'no' : 'yes'
+ },
+ '<': {
+ symbol: '<',
+ label: this.$i18n.get('less_than'),
+ enabled: this.filterTypeOptions.comparators.indexOf('<') < 0 ? 'no' : 'yes'
+ },
+ '<=': {
+ symbol: '≤',
+ label: this.$i18n.get('less_than_or_equal_to'),
+ enabled: this.filterTypeOptions.comparators.indexOf('<=') < 0 ? 'no' : 'yes'
+ },
+ };
+ this.comparator = this.filterTypeOptions.comparators[0];
+ },
mounted() {
this.updateSelectedValues();
},
diff --git a/src/views/admin/components/filter-types/numeric/class-tainacan-numeric.php b/src/views/admin/components/filter-types/numeric/class-tainacan-numeric.php
index b973d8460..e5bb818c7 100644
--- a/src/views/admin/components/filter-types/numeric/class-tainacan-numeric.php
+++ b/src/views/admin/components/filter-types/numeric/class-tainacan-numeric.php
@@ -16,7 +16,8 @@ class Numeric extends Filter_Type {
$this->set_form_component('tainacan-filter-form-numeric');
$this->set_use_max_options(false);
$this->set_default_options([
- 'step' => 1
+ 'step' => 1,
+ 'comparators' => [ '=', '!=', '>', '>=', '<', '<=' ]
]);
$this->set_preview_template('
@@ -77,6 +78,10 @@ class Numeric extends Filter_Type {
'step' => [
'title' => __( 'Step', 'tainacan' ),
'description' => __( 'The amount to be increased or decreased when clicking on the filter control buttons. This also defines whether the input accepts decimal numbers.', 'tainacan' ),
+ ],
+ 'comparators' => [
+ 'title' => __( 'Enabled comparators', 'tainacan' ),
+ 'description' => __( 'A list of comparators to be available in the filter, such as equal, greater than, smaller than, etc.', 'tainacan' ),
]
];
}
@@ -89,13 +94,24 @@ class Numeric extends Filter_Type {
if ( !in_array($filter->get_status(), apply_filters('tainacan-status-require-validation', ['publish','future','private'])) )
return true;
- if ( empty($this->get_option('step')) ) {
- return [
+ $errors = [];
+
+ if ( empty($this->get_option('step')) )
+ $errors[] = [
'step' => __('"Step" value is required','tainacan')
];
- }
- return true;
+ if ( empty($this->get_option('comparators')) )
+ $errors[] = [
+ 'comparators' => __('"Comparators" array is required', 'tainacan')
+ ];
+
+ if ( count( $this->get_option('comparators') ) < 1 )
+ $errors[] = [
+ 'comparators' => __('At least one comparator should be provided', 'tainacan')
+ ];
+
+ return count($errors) ? $errors : true;
}
}
@@ -134,6 +150,8 @@ class Numeric_Helper {
case '<=':
$filter_arguments['label'] = '≤ ' . $filter_arguments['label'][0];
break;
+ default:
+ $filter_arguments['label'] = $filter_arguments['label'][0];
}
}