diff --git a/src/views/admin/components/filter-types/date/FormDate.vue b/src/views/admin/components/filter-types/date/FormDate.vue index d23c3a073..eaf9498cf 100644 --- a/src/views/admin/components/filter-types/date/FormDate.vue +++ b/src/views/admin/components/filter-types/date/FormDate.vue @@ -14,7 +14,7 @@ v-model="comparators" :native-value="comparatorKey" :disabled="comparators.indexOf(comparatorKey) >= 0 && comparators.length <= 1" - name="metadata_type_relationship[display_related_item_metadata]" + name="date_filter_options[comparators]" @update:model-value="emitValues()"> @@ -41,41 +41,40 @@ created() { this.comparators = ( this.modelValue && this.modelValue.comparators ) ? this.modelValue.comparators : [ '=', '!=', '>', '>=', '<', '<=' ]; this.comparatorsObject = { - '=': { - symbol: '=', - label: this.$i18n.get('is_equal_to'), - enabled: this.comparators.indexOf('=') < 0 ? 'no' : 'yes' - }, - '!=': { - symbol: '≠', - label: this.$i18n.get('is_not_equal_to'), - enabled: this.comparators.indexOf('!=') < 0 ? 'no' : 'yes' - }, - '>': { - symbol: '>', - label: this.$i18n.get('after'), - enabled: this.comparators.indexOf('>') < 0 ? 'no' : 'yes' - }, - '>=': { - symbol: '≥', - label: this.$i18n.get('after_or_on_day'), - enabled: this.comparators.indexOf('>=') < 0 ? 'no' : 'yes' - }, - '<': { - symbol: '<', - label: this.$i18n.get('before'), - enabled: this.comparators.indexOf('<') < 0 ? 'no' : 'yes' - }, - '<=': { - symbol: '≤', - label: this.$i18n.get('before_or_on_day'), - enabled: this.comparators.indexOf('<=') < 0 ? 'no' : 'yes' - } - }; + '=': { + symbol: '=', + label: this.$i18n.get('is_equal_to'), + enabled: this.comparators.indexOf('=') < 0 ? 'no' : 'yes' + }, + '!=': { + symbol: '≠', + label: this.$i18n.get('is_not_equal_to'), + enabled: this.comparators.indexOf('!=') < 0 ? 'no' : 'yes' + }, + '>': { + symbol: '>', + label: this.$i18n.get('greater_than'), + enabled: this.comparators.indexOf('>') < 0 ? 'no' : 'yes' + }, + '>=': { + symbol: '≥', + label: this.$i18n.get('greater_than_or_equal_to'), + enabled: this.comparators.indexOf('>=') < 0 ? 'no' : 'yes' + }, + '<': { + symbol: '<', + label: this.$i18n.get('less_than'), + enabled: this.comparators.indexOf('<') < 0 ? 'no' : 'yes' + }, + '<=': { + symbol: '≤', + label: this.$i18n.get('less_than_or_equal_to'), + enabled: this.comparators.indexOf('<=') < 0 ? 'no' : 'yes' + } + }; }, methods: { emitValues() { - console.log(this.comparators) this.$emit('update:model-value', { comparators: this.comparators }); } } diff --git a/src/views/admin/components/filter-types/date/class-tainacan-date.php b/src/views/admin/components/filter-types/date/class-tainacan-date.php index 255fc6988..34f5b3eed 100644 --- a/src/views/admin/components/filter-types/date/class-tainacan-date.php +++ b/src/views/admin/components/filter-types/date/class-tainacan-date.php @@ -87,6 +87,11 @@ class Date extends Filter_Type { 'comparators' => __('"Comparators" array is required', 'tainacan') ]; + if ( count( $this->get_option('comparators') ) < 1 ) + return [ + 'comparators' => __('At least one comparator should be provided', 'tainacan') + ]; + return true; } diff --git a/src/views/admin/components/filter-types/numeric/FormNumeric.vue b/src/views/admin/components/filter-types/numeric/FormNumeric.vue index 6a41fcb94..dcbd67780 100644 --- a/src/views/admin/components/filter-types/numeric/FormNumeric.vue +++ b/src/views/admin/components/filter-types/numeric/FormNumeric.vue @@ -13,7 +13,7 @@ + @update:model-value="emitValues()"> @@ -70,7 +70,7 @@ name="max_options" type="number" step="1" - @update:model-value="onUpdateStep" /> + @update:model-value="emitValues()" /> + + +
+ + + +
+
@@ -102,15 +122,50 @@ data() { return { step: [Number, String], - showEditStepOptions: false + showEditStepOptions: false, + comparatorsObject: Object, + comparators: Array } }, created() { this.step = this.modelValue && this.modelValue.step ? this.modelValue.step : 1; + this.comparators = ( this.modelValue && this.modelValue.comparators ) ? this.modelValue.comparators : [ '=', '!=', '>', '>=', '<', '<=' ]; + this.comparatorsObject = { + '=': { + symbol: '=', + label: this.$i18n.get('is_equal_to'), + enabled: this.comparators.indexOf('=') < 0 ? 'no' : 'yes' + }, + '!=': { + symbol: '≠', + label: this.$i18n.get('is_not_equal_to'), + enabled: this.comparators.indexOf('!=') < 0 ? 'no' : 'yes' + }, + '>': { + symbol: '>', + label: this.$i18n.get('after'), + enabled: this.comparators.indexOf('>') < 0 ? 'no' : 'yes' + }, + '>=': { + symbol: '≥', + label: this.$i18n.get('after_or_on_day'), + enabled: this.comparators.indexOf('>=') < 0 ? 'no' : 'yes' + }, + '<': { + symbol: '<', + label: this.$i18n.get('before'), + enabled: this.comparators.indexOf('<') < 0 ? 'no' : 'yes' + }, + '<=': { + symbol: '≤', + label: this.$i18n.get('before_or_on_day'), + enabled: this.comparators.indexOf('<=') < 0 ? 'no' : 'yes' + } + }; }, methods: { - onUpdateStep(modelValue) { - this.$emit('update:model-value', { step: modelValue }); + emitValues() { + this.$emit('update:model-value', { step: this.step, comparators: this.comparators }); } } } diff --git a/src/views/admin/components/filter-types/numeric/TainacanFilterNumeric.vue b/src/views/admin/components/filter-types/numeric/TainacanFilterNumeric.vue index 4d6a77ea2..25ca61d2a 100644 --- a/src/views/admin/components/filter-types/numeric/TainacanFilterNumeric.vue +++ b/src/views/admin/components/filter-types/numeric/TainacanFilterNumeric.vue @@ -1,6 +1,7 @@ - - =  {{ $i18n.get('is_equal_to') }} - - - ≠  {{ $i18n.get('is_not_equal_to') }} - - - >  {{ $i18n.get('greater_than') }} - - - ≥  {{ $i18n.get('greater_than_or_equal_to') }} - - - <  {{ $i18n.get('less_than') }} - - - ≤  {{ $i18n.get('less_than_or_equal_to') }} - + - ': 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]; } }