From d5851b71b829d10e6cebf868038aa7da66b82e6f Mon Sep 17 00:00:00 2001 From: Mateus Machado Luna Date: Mon, 7 Oct 2019 12:44:01 -0300 Subject: [PATCH] Moves responsability of sending value to tag from each filter to parent component. --- .../filter-types/autocomplete/Autocomplete.vue | 10 ++-------- src/classes/filter-types/checkbox/Checkbox.vue | 10 ++-------- .../custom-interval/CustomInterval.vue | 16 ++++------------ src/classes/filter-types/date/Date.vue | 10 ++-------- .../numeric-interval/NumericInterval.vue | 16 ++++------------ .../NumericListInterval.vue | 10 ++-------- src/classes/filter-types/numeric/Numeric.vue | 13 +++---------- src/classes/filter-types/selectbox/Selectbox.vue | 8 ++------ src/classes/filter-types/taginput/Taginput.vue | 10 ++-------- .../filter-types/tainacan-filter-item.vue | 15 ++++++++++++--- src/classes/filter-types/taxonomy/Checkbox.vue | 14 ++++---------- src/classes/filter-types/taxonomy/Taginput.vue | 14 ++++---------- 12 files changed, 43 insertions(+), 103 deletions(-) diff --git a/src/classes/filter-types/autocomplete/Autocomplete.vue b/src/classes/filter-types/autocomplete/Autocomplete.vue index 16163baca..8d0775f31 100644 --- a/src/classes/filter-types/autocomplete/Autocomplete.vue +++ b/src/classes/filter-types/autocomplete/Autocomplete.vue @@ -155,10 +155,7 @@ instance.label = item.title; instance.selected = item.title; - this.$eventBusSearch.$emit( 'sendValuesToTags', { - filterId: instance.filter.id, - value: instance.label - }); + this.$emit( 'sendValuesToTags', instance.label); }) .catch(error => { this.$console.log(error); @@ -168,10 +165,7 @@ instance.label = metadata.value; instance.selected = metadata.value; - this.$eventBusSearch.$emit( 'sendValuesToTags', { - filterId: instance.filter.id, - value: metadata.value - }); + this.$emit( 'sendValuesToTags', metadata.value); } } else { return false; diff --git a/src/classes/filter-types/checkbox/Checkbox.vue b/src/classes/filter-types/checkbox/Checkbox.vue index 7868fa088..4c46cd3d8 100644 --- a/src/classes/filter-types/checkbox/Checkbox.vue +++ b/src/classes/filter-types/checkbox/Checkbox.vue @@ -153,10 +153,7 @@ } } - this.$eventBusSearch.$emit( 'sendValuesToTags', { - filterId: this.filter.id, - value: onlyLabels.length ? onlyLabels : this.selected, - }); + this.$emit( 'sendValuesToTags', onlyLabels.length ? onlyLabels : this.selected); }, selectedValues() { if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) ) @@ -220,10 +217,7 @@ value: this.selected }); - this.$eventBusSearch.$emit( 'sendValuesToTags', { - filterId: this.filter.id, - value: this.selected - }); + this.$emit( 'sendValuesToTags', this.selected); this.selectedValues(); } diff --git a/src/classes/filter-types/custom-interval/CustomInterval.vue b/src/classes/filter-types/custom-interval/CustomInterval.vue index 65db3d7ba..baafa0dec 100644 --- a/src/classes/filter-types/custom-interval/CustomInterval.vue +++ b/src/classes/filter-types/custom-interval/CustomInterval.vue @@ -193,12 +193,8 @@ this.isValid = true; } - if (metadata.value[0] != undefined && metadata.value[1] != undefined) { - this.$eventBusSearch.$emit( 'sendValuesToTags', { - filterId: this.filter.id, - value: this.parseDateToNavigatorLanguage(metadata.value[0]) + ' - ' + this.parseDateToNavigatorLanguage(metadata.value[1]) - }); - } + if (metadata.value[0] != undefined && metadata.value[1] != undefined) + this.$emit( 'sendValuesToTags', this.parseDateToNavigatorLanguage(metadata.value[0]) + ' - ' + this.parseDateToNavigatorLanguage(metadata.value[1])); } else { return false; @@ -302,12 +298,8 @@ value: values }); - if (values[0] != undefined && values[1] != undefined) { - this.$eventBusSearch.$emit( 'sendValuesToTags', { - filterId: this.filter.id, - value: this.parseDateToNavigatorLanguage(values[0]) + ' - ' + this.parseDateToNavigatorLanguage(values[1]) - }); - } + if (values[0] != undefined && values[1] != undefined) + this.$emit( 'sendValuesToTags', this.parseDateToNavigatorLanguage(values[0]) + ' - ' + this.parseDateToNavigatorLanguage(values[1])); } }, beforeDestroy() { diff --git a/src/classes/filter-types/date/Date.vue b/src/classes/filter-types/date/Date.vue index 1447a2a32..6a4cd5331 100644 --- a/src/classes/filter-types/date/Date.vue +++ b/src/classes/filter-types/date/Date.vue @@ -196,10 +196,7 @@ this.value = new Date(textValue); - this.$eventBusSearch.$emit( 'sendValuesToTags', { - filterId: this.filter.id, - value: this.comparator + ' ' + moment(this.value, moment.ISO_8601).format(this.dateFormat) - }); + this.$emit('sendValuesToTags', this.comparator + ' ' + moment(this.value, moment.ISO_8601).format(this.dateFormat)); } } else { @@ -261,10 +258,7 @@ collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id, value: valueQuery }); - this.$eventBusSearch.$emit( 'sendValuesToTags', { - filterId: this.filter.id, - value: this.comparator + ' ' + moment(this.value, moment.ISO_8601).format(this.dateFormat) - }); + this.$emit('sendValuesToTags', this.comparator + ' ' + moment(this.value, moment.ISO_8601).format(this.dateFormat)); }, onChangeComparator(newComparator) { diff --git a/src/classes/filter-types/numeric-interval/NumericInterval.vue b/src/classes/filter-types/numeric-interval/NumericInterval.vue index 4fbbaf3bc..37db5600b 100644 --- a/src/classes/filter-types/numeric-interval/NumericInterval.vue +++ b/src/classes/filter-types/numeric-interval/NumericInterval.vue @@ -98,12 +98,8 @@ value: values }); - if (values[0] != undefined && values[1] != undefined) { - this.$eventBusSearch.$emit( 'sendValuesToTags', { - filterId: this.filter.id, - value: values[0] + ' - ' + values[1] - }); - } + if (values[0] != undefined && values[1] != undefined) + this.$emit('sendValuesToTags', values[0] + ' - ' + values[1]); }, selectedValues(){ if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) ) @@ -117,12 +113,8 @@ this.valueEnd = metaquery.value[1]; } - if (metaquery.value[0] != undefined && metaquery.value[1] != undefined) { - this.$eventBusSearch.$emit( 'sendValuesToTags', { - filterId: this.filter.id, - value: this.valueInit + ' - ' + this.valueEnd - }); - } + if (metaquery.value[0] != undefined && metaquery.value[1] != undefined) + this.$emit( 'sendValuesToTags', this.valueInit + ' - ' + this.valueEnd); } else { return false; diff --git a/src/classes/filter-types/numeric-list-interval/NumericListInterval.vue b/src/classes/filter-types/numeric-list-interval/NumericListInterval.vue index 5871e9d49..a057ac0e7 100644 --- a/src/classes/filter-types/numeric-list-interval/NumericListInterval.vue +++ b/src/classes/filter-types/numeric-list-interval/NumericListInterval.vue @@ -85,10 +85,7 @@ if (values[0] != undefined && values[1] != undefined) { let labelValue = this.filterTypeOptions.intervals[this.selectedInterval].label + (this.filterTypeOptions.showIntervalOnTag ? `(${values[0]}-${values[1]})` : ''); - this.$eventBusSearch.$emit( 'sendValuesToTags', { - filterId: this.filter.id, - value: labelValue - }); + this.$emit( 'sendValuesToTags', labelValue); } }, selectedValues(){ @@ -113,10 +110,7 @@ ); let labelValue = this.filterTypeOptions.intervals[this.selectedInterval].label + (this.filterTypeOptions.showIntervalOnTag ? `(${this.valueInit}-${this.valueEnd})` : ''); - this.$eventBusSearch.$emit( 'sendValuesToTags', { - filterId: this.filter.id, - value: labelValue - }); + this.$emit( 'sendValuesToTags', labelValue); } else { return false; } diff --git a/src/classes/filter-types/numeric/Numeric.vue b/src/classes/filter-types/numeric/Numeric.vue index 98a9fe910..6a02c8d21 100644 --- a/src/classes/filter-types/numeric/Numeric.vue +++ b/src/classes/filter-types/numeric/Numeric.vue @@ -147,12 +147,8 @@ if ( metadata.compare) this.comparator = metadata.compare; - if (this.value != undefined) { - this.$eventBusSearch.$emit( 'sendValuesToTags', { - filterId: this.filter.id, - value: this.comparator + ' ' + this.value - }); - } + if (this.value != undefined) + this.$emit('sendValuesToTags', this.comparator + ' ' + this.value); } else { return false; @@ -193,10 +189,7 @@ type: 'NUMERIC' }); - this.$eventBusSearch.$emit( 'sendValuesToTags', { - filterId: this.filter.id, - value: this.comparator + ' ' + this.value - }); + this.$emit('sendValuesToTags', this.comparator + ' ' + this.value); }, onChangeComparator(newComparator) { diff --git a/src/classes/filter-types/selectbox/Selectbox.vue b/src/classes/filter-types/selectbox/Selectbox.vue index 83d4c0048..74c2b240a 100644 --- a/src/classes/filter-types/selectbox/Selectbox.vue +++ b/src/classes/filter-types/selectbox/Selectbox.vue @@ -78,12 +78,8 @@ mixins: [filter_type_mixin], watch: { selected(value) { - if (value) { - this.$eventBusSearch.$emit( 'sendValuesToTags', { - filterId: this.filter.id, - value: value - }); - } + if (value) + this.$emit('sendValuesToTags', value); } }, computed: { diff --git a/src/classes/filter-types/taginput/Taginput.vue b/src/classes/filter-types/taginput/Taginput.vue index 3092219e2..90a75f6c8 100644 --- a/src/classes/filter-types/taginput/Taginput.vue +++ b/src/classes/filter-types/taginput/Taginput.vue @@ -110,10 +110,7 @@ value: values }); - this.$eventBusSearch.$emit( 'sendValuesToTags', { - filterId: this.filter.id, - value: labels - }); + this.$emit( 'sendValuesToTags', labels); } }, methods: { @@ -205,10 +202,7 @@ value: values }); - this.$eventBusSearch.$emit( 'sendValuesToTags', { - filterId: this.filter.id, - value: labels - }); + this.$emit( 'sendValuesToTags', labels); } } } diff --git a/src/classes/filter-types/tainacan-filter-item.vue b/src/classes/filter-types/tainacan-filter-item.vue index 6d99a9e2a..48f40abbf 100644 --- a/src/classes/filter-types/tainacan-filter-item.vue +++ b/src/classes/filter-types/tainacan-filter-item.vue @@ -39,7 +39,8 @@ :filter="filter" :query="query" :is-repository-level="isRepositoryLevel" - @input="listen( $event )"/> + @input="onInput" + @sendValuesToTags="onSendValuesToTags"/> @@ -60,8 +61,16 @@ } }, methods: { - listen( inputEvent ){ - this.$eventBusSearch.$emit( 'input', ( inputEvent.metadatum_id ) ? inputEvent : inputEvent.detail[0] ); + onInput(inputEvent){ + this.$eventBusSearch.$emit( + 'input', ( inputEvent.metadatum_id ) ? inputEvent : inputEvent.detail[0] + ); + }, + onSendValuesToTags(values) { + this.$eventBusSearch.$emit('sendValuesToTags', { + filterId: this.filter.id, + value: values + }); } } } diff --git a/src/classes/filter-types/taxonomy/Checkbox.vue b/src/classes/filter-types/taxonomy/Checkbox.vue index b42accd31..edce1a215 100644 --- a/src/classes/filter-types/taxonomy/Checkbox.vue +++ b/src/classes/filter-types/taxonomy/Checkbox.vue @@ -58,7 +58,7 @@ this.type = this.filter.metadatum.metadata_type; this.loadOptions(); - this.$eventBusSearch.$on('removeFromFilterTag', this.cleanSearchFromTag); + this.$eventBusSearch.$on('removeFromFilterTag', this.cleanSearchFromTags); if (this.isUsingElasticSearch) this.$eventBusSearch.$on('isLoadingItems', this.updatesIsLoading); @@ -254,10 +254,7 @@ } } - this.$eventBusSearch.$emit("sendValuesToTags", { - filterId: this.filter.id, - value: onlyLabels - }); + this.$emit("sendValuesToTags", onlyLabels); }, openCheckboxModal(parent) { this.$buefy.modal.open({ @@ -283,7 +280,7 @@ trapFocus: true }); }, - cleanSearchFromTag(filterTag) { + cleanSearchFromTags(filterTag) { if (filterTag.filterId == this.filter.id) { let selectedOption = this.options.find(option => option.label == filterTag.singleValue); @@ -304,10 +301,7 @@ terms: this.selected }); - this.$eventBusSearch.$emit( 'sendValuesToTags', { - filterId: this.filter.id, - value: this.selected - }); + this.$emit( 'sendValuesToTags', this.selected); this.selectedValues(); } diff --git a/src/classes/filter-types/taxonomy/Taginput.vue b/src/classes/filter-types/taxonomy/Taginput.vue index 255b5eb7f..a1d681c2c 100644 --- a/src/classes/filter-types/taxonomy/Taginput.vue +++ b/src/classes/filter-types/taxonomy/Taginput.vue @@ -57,7 +57,7 @@ this.selectedValues( metadatum.metadata_type_options.taxonomy_id ); }); - this.$eventBusSearch.$on('removeFromFilterTag', this.cleanSearchFromTag); + this.$eventBusSearch.$on('removeFromFilterTag', this.cleanSearchFromTags); }, data(){ return { @@ -101,10 +101,7 @@ terms: values }); - this.$eventBusSearch.$emit("sendValuesToTags", { - filterId: this.filter.id, - value: labels - }); + this.$emit("sendValuesToTags", labels); } }, methods: { @@ -185,7 +182,7 @@ this.$console.log(error); }); }, - cleanSearchFromTag(filterTag) { + cleanSearchFromTags(filterTag) { if (filterTag.filterId == this.filter.id) { @@ -209,10 +206,7 @@ collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id, terms: values }); - this.$eventBusSearch.$emit( 'sendValuesToTags', { - filterId: this.filter.id, - value: labels - }); + this.$emit( 'sendValuesToTags', labels); } } }