From ebf478d5ff7ade98fb5b7dd78fb9512e1288c638 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Mon, 3 Jun 2024 15:53:13 -0300 Subject: [PATCH] Adds option to display the filter as a range instead of one date. #887. --- .../TainacanFilterDateInterval.vue | 30 ++++++++++++- .../FormDatesIntersection.vue | 25 ++++++++++- .../TainacanFilterDatesIntersection.vue | 44 ++++++++++++++++--- .../class-tainacan-dates-intersection.php | 12 ++++- 4 files changed, 100 insertions(+), 11 deletions(-) diff --git a/src/views/admin/components/filter-types/date-interval/TainacanFilterDateInterval.vue b/src/views/admin/components/filter-types/date-interval/TainacanFilterDateInterval.vue index 1a4e4b1b5..79c9ddb0a 100644 --- a/src/views/admin/components/filter-types/date-interval/TainacanFilterDateInterval.vue +++ b/src/views/admin/components/filter-types/date-interval/TainacanFilterDateInterval.vue @@ -3,7 +3,7 @@

diff --git a/src/views/admin/components/filter-types/dates-intersection/FormDatesIntersection.vue b/src/views/admin/components/filter-types/dates-intersection/FormDatesIntersection.vue index 346b90b3a..19a9b7e0c 100644 --- a/src/views/admin/components/filter-types/dates-intersection/FormDatesIntersection.vue +++ b/src/views/admin/components/filter-types/dates-intersection/FormDatesIntersection.vue @@ -69,6 +69,24 @@ + +   + + + + @@ -94,7 +112,8 @@ secondDateMetadatumName: String, firstComparator: String, secondComparator: String, - comparatorsObject: {} + comparatorsObject: {}, + acceptDateInterval: String } }, watch: { @@ -110,6 +129,7 @@ this.secondDateMetadatumName = this.modelValue && this.modelValue.secondary_filter_metadatum_name ? this.modelValue.secondary_filter_metadatum_name : ''; this.firstComparator = this.modelValue && this.modelValue.first_comparator ? this.modelValue.first_comparator : '>='; this.secondComparator = this.modelValue && this.modelValue.second_comparator ? this.modelValue.second_comparator : '<='; + this.acceptDateInterval = this.modelValue && this.modelValue.accept_date_interval ? this.modelValue.accept_date_interval : 'no'; this.loading = true; this.fetchMetadata(); @@ -168,7 +188,8 @@ first_comparator: this.firstComparator, second_comparator: this.secondComparator, secondary_filter_metadatum_id: this.secondDateMetadatumId, - secondary_filter_metadatum_name: this.secondDateMetadatumName + secondary_filter_metadatum_name: this.secondDateMetadatumName, + accept_date_interval: this.acceptDateInterval }); }, setErrorsAttributes( type, message ) { diff --git a/src/views/admin/components/filter-types/dates-intersection/TainacanFilterDatesIntersection.vue b/src/views/admin/components/filter-types/dates-intersection/TainacanFilterDatesIntersection.vue index cd9a67aa6..b43d7a002 100644 --- a/src/views/admin/components/filter-types/dates-intersection/TainacanFilterDatesIntersection.vue +++ b/src/views/admin/components/filter-types/dates-intersection/TainacanFilterDatesIntersection.vue @@ -3,7 +3,7 @@

{{ $i18n.get('label_until') }}

@@ -92,13 +122,13 @@ // only validate if the first value is higher than first validadeValues: _.debounce( function (){ - if (this.dateInit === undefined) + if ( this.dateInit === undefined ) this.dateInit = new Date(); - if (this.dateEnd === undefined) + if ( this.dateEnd === undefined ) this.dateEnd = new Date(); - if (this.dateInit > this.dateEnd) { + if ( this.filterTypeOptions.accept_date_interval === 'yes' && this.dateInit > this.dateEnd ) { this.showErrorMessage(); return } @@ -162,7 +192,7 @@ compare: this.filterTypeOptions.first_comparator, metadatum_id: this.metadatumId, collection_id: this.collectionId, - value: values + value: this.filterTypeOptions.accept_date_interval === 'yes' ? values : values[0] }); this.$emit('input', { filter: 'intersection', @@ -170,7 +200,7 @@ compare: this.filterTypeOptions.second_comparator, metadatum_id: this.filterTypeOptions.secondary_filter_metadatum_id, collection_id: this.collectionId, - value: values + value: this.filterTypeOptions.accept_date_interval === 'yes' ? values : values[0] }); } } diff --git a/src/views/admin/components/filter-types/dates-intersection/class-tainacan-dates-intersection.php b/src/views/admin/components/filter-types/dates-intersection/class-tainacan-dates-intersection.php index eb43af28e..59860e686 100644 --- a/src/views/admin/components/filter-types/dates-intersection/class-tainacan-dates-intersection.php +++ b/src/views/admin/components/filter-types/dates-intersection/class-tainacan-dates-intersection.php @@ -18,7 +18,8 @@ class Dates_Intersection extends Filter_Type { 'secondary_filter_metadatum_id' => '', 'secondary_filter_metadatum_name' => '', 'first_comparator' => '>=', - 'second_comparator' => '<=' + 'second_comparator' => '<=', + 'accept_date_interval' => 'no' ]); $this->set_use_max_options(false); $this->set_preview_template(' @@ -69,6 +70,10 @@ class Dates_Intersection extends Filter_Type { 'second_comparator' => [ 'title' => __( 'Second comparator', 'tainacan' ), 'description' => __( 'Comparator to be used for checking the second metadata value.', 'tainacan' ), + ], + 'accept_date_interval' => [ + 'title' => __( 'Accept date interval', 'tainacan' ), + 'description' => __( 'If checked, the filter will accept date intervals as values.', 'tainacan' ), ] ]; } @@ -99,6 +104,11 @@ class Dates_Intersection extends Filter_Type { 'second_comparator' => __('The second comparator is required.','tainacan') ]; + if ( empty($this->get_option('accept_date_interval')) ) + $errors[] = [ + 'accept_date_interval' => __('The filter should define if it accepts date interval.','tainacan') + ]; + return count($errors) > 0 ? $errors : true; }