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 b46b1efeb..510942ea4 100644 --- a/src/views/admin/components/filter-types/dates-intersection/TainacanFilterDatesIntersection.vue +++ b/src/views/admin/components/filter-types/dates-intersection/TainacanFilterDatesIntersection.vue @@ -185,10 +185,15 @@ let dateInit = this.dateInit.getUTCFullYear() + '-' + ('00' + (this.dateInit.getUTCMonth() + 1)).slice(-2) + '-' + ('00' + this.dateInit.getUTCDate()).slice(-2); - let dateEnd = this.dateEnd.getUTCFullYear() + '-' + - ('00' + (this.dateEnd.getUTCMonth() + 1)).slice(-2) + '-' + - ('00' + this.dateEnd.getUTCDate()).slice(-2); - values = [ dateInit, dateEnd ]; + + if ( this.dateEnd !== null ) { + let dateEnd = this.dateEnd.getUTCFullYear() + '-' + + ('00' + (this.dateEnd.getUTCMonth() + 1)).slice(-2) + '-' + + ('00' + this.dateEnd.getUTCDate()).slice(-2); + values = [ dateInit, dateEnd ]; + } else { + values = [ dateInit ]; + } } if ( this.filterTypeOptions.accept_date_interval !== 'yes' ) { 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 4e87802d4..9ad373a71 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 @@ -116,6 +116,13 @@ class Dates_Intersection_Interval_Helper { ) { $filter_arguments['label'] = $filter_arguments['label'][0] . ' - ' . $filter_arguments['label'][1]; } + if ( + isset( $filter_arguments['filter'] ) && + isset( $filter_arguments['filter']['metadatum'] ) && + isset( $filter_arguments['filter']['metadatum']['metadatum_name'] ) + ) { + $filter_arguments['filter']['name'] = $filter_arguments['filter']['metadatum']['metadatum_name']; + } if ( isset( $filter_arguments['filter'] ) && isset( $filter_arguments['filter']['filter_type_options'] ) && diff --git a/src/views/admin/components/filter-types/numerics-intersection/TainacanFilterNumericsIntersection.vue b/src/views/admin/components/filter-types/numerics-intersection/TainacanFilterNumericsIntersection.vue index 5981bd661..f2e1dfcb8 100644 --- a/src/views/admin/components/filter-types/numerics-intersection/TainacanFilterNumericsIntersection.vue +++ b/src/views/admin/components/filter-types/numerics-intersection/TainacanFilterNumericsIntersection.vue @@ -101,7 +101,7 @@ compare: this.filterTypeOptions.first_comparator, metadatum_id: this.metadatumId, collection_id: this.collectionId, - value: this.filterTypeOptions.accept_numeric_interval === 'yes' ? values : values[0] + value: values[0] }); this.$emit('input', { filter: 'intersection', @@ -109,7 +109,8 @@ compare: this.filterTypeOptions.second_comparator, metadatum_id: this.filterTypeOptions.secondary_filter_metadatum_id, collection_id: this.collectionId, - value: this.filterTypeOptions.accept_numeric_interval === 'yes' ? values : values[0] + value: values[0], + secondary: true }); } else { // Much more complicated logic to be implemented in the future. See #889 diff --git a/src/views/admin/components/filter-types/numerics-intersection/class-tainacan-numerics-intersection.php b/src/views/admin/components/filter-types/numerics-intersection/class-tainacan-numerics-intersection.php index 6ab929e7e..3451cf38d 100644 --- a/src/views/admin/components/filter-types/numerics-intersection/class-tainacan-numerics-intersection.php +++ b/src/views/admin/components/filter-types/numerics-intersection/class-tainacan-numerics-intersection.php @@ -127,6 +127,13 @@ class Numerics_Intersection_Interval_Helper { ) { $filter_arguments['label'] = $filter_arguments['label'][0] . ' - ' . $filter_arguments['label'][1]; } + if ( + isset( $filter_arguments['filter'] ) && + isset( $filter_arguments['filter']['metadatum'] ) && + isset( $filter_arguments['filter']['metadatum']['metadatum_name'] ) + ) { + $filter_arguments['filter']['name'] = $filter_arguments['filter']['metadatum']['metadatum_name']; + } if ( isset( $filter_arguments['filter'] ) && isset( $filter_arguments['filter']['filter_type_options'] ) && diff --git a/src/views/admin/components/search/filters-tags-list.vue b/src/views/admin/components/search/filters-tags-list.vue index 6f1e2159e..c80ecab41 100644 --- a/src/views/admin/components/search/filters-tags-list.vue +++ b/src/views/admin/components/search/filters-tags-list.vue @@ -113,7 +113,8 @@ taxonomy: tag.taxonomy, metadatumName: this.getMetadatumName(tag), metadatumId: tag.metadatumId, - argType: tag.argType + argType: tag.argType, + secondaryMetadatumId: tag.secondaryMetadatumId }); } } else { @@ -124,11 +125,12 @@ taxonomy: tag.taxonomy, metadatumName: this.getMetadatumName(tag), metadatumId: tag.metadatumId, - argType: tag.argType + argType: tag.argType, + secondaryMetadatumId: tag.secondaryMetadatumId }); } }); - + return flattenTags; } }, @@ -168,7 +170,7 @@ ...mapGetters('search',[ 'getFilterTags' ]), - removeMetaQuery({ filterId, value, singleLabel, label, taxonomy, metadatumId, metadatumName, argType }) { + removeMetaQuery({ filterId, value, singleLabel, label, taxonomy, metadatumId, metadatumName, argType, secondaryMetadatumId }) { this.$eventBusSearch.resetPageOnStore(); this.$eventBusSearch.removeMetaFromFilterTag({ filterId: filterId, @@ -178,7 +180,8 @@ taxonomy: taxonomy, metadatumId: metadatumId, metadatumName:metadatumName, - argType: argType + argType: argType, + secondaryMetadatumId: secondaryMetadatumId }); }, clearAllFilters() { diff --git a/src/views/admin/js/event-bus-search.js b/src/views/admin/js/event-bus-search.js index a9ba28c88..3147d51dc 100644 --- a/src/views/admin/js/event-bus-search.js +++ b/src/views/admin/js/event-bus-search.js @@ -29,7 +29,7 @@ export default { this.updateURLQueries(); }, removeMetaFromFilterTag(filterTag) { - + if (filterTag.singleLabel != undefined || filterTag.label != undefined) { if (filterTag.argType !== 'postin') { @@ -39,7 +39,8 @@ export default { label: filterTag.singleLabel ? filterTag.singleLabel : filterTag.label, isMultiValue: filterTag.singleLabel ? false : true, taxonomy: filterTag.taxonomy, - value: filterTag.value + value: filterTag.value, + secondaryMetadatumId: filterTag.secondaryMetadatumId }); } else { app.config.globalProperties.$store.dispatch('search/removeMetaQuery', { @@ -47,7 +48,8 @@ export default { label: filterTag.singleLabel ? filterTag.singleLabel : filterTag.label, isMultiValue: filterTag.singleLabel ? false : true, metadatum_id: filterTag.metadatumId, - value: filterTag.value + value: filterTag.value, + secondaryMetadatumId: filterTag.secondaryMetadatumId }); } } else { diff --git a/src/views/admin/js/store/modules/search/mutations.js b/src/views/admin/js/store/modules/search/mutations.js index fe1d2baec..f53eacec2 100644 --- a/src/views/admin/js/store/modules/search/mutations.js +++ b/src/views/admin/js/store/modules/search/mutations.js @@ -91,13 +91,27 @@ export const removeMetaQuery = ( state, filter ) => { let index = state.postquery.metaquery.findIndex( item => item.key == filter.metadatum_id); - if (index >= 0) { + if ( index >= 0 ) { if (!filter.isMultiValue && Array.isArray(state.postquery.metaquery[index].value) && state.postquery.metaquery[index].value.length > 1) { let otherIndex = state.postquery.metaquery[index].value.findIndex(item => item == filter.value); - if (otherIndex >= 0) + if ( otherIndex >= 0 ) state.postquery.metaquery[index].value.splice(otherIndex, 1) } else state.postquery.metaquery.splice(index, 1); + console.log(filter) + // Handles removing metaqueries from secondary filter metadata + if ( filter.secondaryMetadatumId ) { + let secondaryIndex = state.postquery.metaquery.findIndex( item => item.key == filter.secondaryMetadatumId); + + if ( secondaryIndex >= 0 ) { + if ( !filter.isMultiValue && Array.isArray(state.postquery.metaquery[secondaryIndex].value) && state.postquery.metaquery[secondaryIndex].value.length > 1 ) { + let otherSecondaryIndex = state.postquery.metaquery[secondaryIndex].value.findIndex(item => item == filter.value); + if ( otherSecondaryIndex >= 0 ) + state.postquery.metaquery[secondaryIndex].value.splice(otherSecondaryIndex, 1) + } else + state.postquery.metaquery.splice(secondaryIndex, 1); + } + } } }; @@ -188,7 +202,8 @@ export const setFilterTags = ( state, filterArguments ) => { ) ? aFilterArgument.metadatum.metadata_type_object.options.taxonomy : '', argType: aFilterArgument.arg_type ? aFilterArgument.arg_type : '', metadatumId: (aFilterArgument.filter && aFilterArgument.metadatum.metadatum_id) ? aFilterArgument.metadatum.metadatum_id : (aFilterArgument.metadatum.id || ''), - metadatumName: (aFilterArgument.filter && aFilterArgument.filter.name) ? aFilterArgument.filter.name : (aFilterArgument.metadatum.name || '') + metadatumName: (aFilterArgument.filter && aFilterArgument.filter.name) ? aFilterArgument.filter.name : (aFilterArgument.metadatum.name || ''), + secondaryMetadatumId: (aFilterArgument.filter && aFilterArgument.filter.filter_type_options && aFilterArgument.filter.filter_type_options.secondary_filter_metadatum_id) ? aFilterArgument.filter.filter_type_options.secondary_filter_metadatum_id : '', } }); state.filter_tags = filterTags;