Several updates on tagslist logic.

This commit is contained in:
Mateus Machado Luna 2019-10-10 12:03:17 -03:00
parent 2325215f05
commit b1511ce926
16 changed files with 125 additions and 73 deletions

View File

@ -7,8 +7,8 @@
:key="index" :key="index"
attached attached
closable closable
@close="removeMetaQuery(filterTag.filterId, filterTag.value, filterTag.singleValue)"> @close="removeMetaQuery(filterTag)">
{{ filterTag.singleValue != undefined ? filterTag.singleValue : filterTag.value }} {{ filterTag.singleLabel != undefined ? filterTag.singleLabel : filterTag.label }}
</b-tag> </b-tag>
<button <button
@click="clearAllFilters()" @click="clearAllFilters()"
@ -19,7 +19,7 @@
</div> </div>
</template> </template>
<script> <script>
import { mapGetters, mapActions } from 'vuex'; import { mapGetters } from 'vuex';
export default { export default {
name: 'FiltersTagsList', name: 'FiltersTagsList',
@ -31,9 +31,9 @@
let tags = this.getFilterTags(); let tags = this.getFilterTags();
let flattenTags = []; let flattenTags = [];
for (let tag of tags) { for (let tag of tags) {
if (Array.isArray(tag.value)) { if (Array.isArray(tag.label)) {
for (let valueTag of tag.value) for (let i = 0; i < tag.label.length; i++)
flattenTags.push({filterId: tag.filterId, value: tag, singleValue: valueTag}); flattenTags.push({filterId: tag.filterId, label: tag.label, singleLabel: tag.label[i], value: tag.value[i], taxonomy: tag.taxonomy, metadatumId: tag.metadatumId});
} else { } else {
flattenTags.push(tag); flattenTags.push(tag);
} }
@ -43,22 +43,30 @@
}, },
methods: { methods: {
...mapGetters('search',[ ...mapGetters('search',[
'getPostQuery',
'getFilterTags' 'getFilterTags'
]), ]),
...mapActions('metadata',[ removeMetaQuery({ filterId, value, singleLabel, label, taxonomy, metadatumId }) {
'fetchMetadatum' if (singleLabel != undefined)
]), this.$eventBusSearch.removeMetaFromFilterTag({
removeMetaQuery(filterId, value, singleValue) { filterId: filterId,
if (singleValue != undefined) singleLabel: singleLabel,
this.$eventBusSearch.removeMetaFromFilterTag({ filterId: filterId, singleValue: singleValue }); value: value,
taxonomy: taxonomy,
metadatumId: metadatumId
});
else else
this.$eventBusSearch.removeMetaFromFilterTag({ filterId: filterId, value: value }); this.$eventBusSearch.removeMetaFromFilterTag({
filterId: filterId,
label: label,
value: value,
taxonomy: taxonomy,
metadatumId: metadatumId
});
}, },
clearAllFilters() { clearAllFilters() {
// this.$eventBusSearch.clearAllFilters(); // this.$eventBusSearch.clearAllFilters();
for (let tag of this.filterTags) { for (let tag of this.filterTags) {
this.removeMetaQuery(tag.filterId, tag.value, tag.singleValue); this.removeMetaQuery(tag);
} }
} }
} }

View File

@ -113,15 +113,14 @@
if (this.metadatumType === 'Tainacan\\Metadata_Types\\Relationship') { if (this.metadatumType === 'Tainacan\\Metadata_Types\\Relationship') {
axios.get('/items/' + metadata.value) axios.get('/items/' + metadata.value + '?fetch_only=title,thumbnail')
.then( res => { .then( res => {
let item = res.data; let item = res.data;
this.results = item.title; this.results = item.title;
this.label = item.title; this.label = item.title;
this.selected = item.title; this.selected = item.title;
this.$emit( 'sendValuesToTags', this.label); this.$emit( 'sendValuesToTags', { label: this.label, value: this.results });
}) })
.catch(error => { .catch(error => {
this.$console.log(error); this.$console.log(error);
@ -131,7 +130,7 @@
this.label = metadata.value; this.label = metadata.value;
this.selected = metadata.value; this.selected = metadata.value;
this.$emit( 'sendValuesToTags', metadata.value); this.$emit( 'sendValuesToTags', { label: this.label, value: this.results });
} }
} else { } else {
return false; return false;

View File

@ -117,7 +117,7 @@
} }
} }
this.$emit( 'sendValuesToTags', onlyLabels.length ? onlyLabels : this.selected); this.$emit( 'sendValuesToTags', { label: onlyLabels.length ? onlyLabels : this.selected, value: this.selected });
}, },
selectedValues() { selectedValues() {
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) ) if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )

View File

@ -167,7 +167,10 @@
} }
if (metadata.value[0] != undefined && metadata.value[1] != undefined) if (metadata.value[0] != undefined && metadata.value[1] != undefined)
this.$emit( 'sendValuesToTags', this.parseDateToNavigatorLanguage(metadata.value[0]) + ' - ' + this.parseDateToNavigatorLanguage(metadata.value[1])); this.$emit('sendValuesToTags', {
label: this.parseDateToNavigatorLanguage(metadata.value[0]) + ' - ' + this.parseDateToNavigatorLanguage(metadata.value[1]),
value: [metadata.value[0], metadata.value[1]]
});
} else { } else {
return false; return false;
@ -272,7 +275,10 @@
}); });
if (values[0] != undefined && values[1] != undefined) if (values[0] != undefined && values[1] != undefined)
this.$emit( 'sendValuesToTags', this.parseDateToNavigatorLanguage(values[0]) + ' - ' + this.parseDateToNavigatorLanguage(values[1])); this.$emit( 'sendValuesToTags', {
label: this.parseDateToNavigatorLanguage(values[0]) + ' - ' + this.parseDateToNavigatorLanguage(values[1]),
value: [ values[0], values[1] ]
});
} }
} }
} }

View File

@ -166,7 +166,10 @@
this.value = new Date(textValue); this.value = new Date(textValue);
this.$emit('sendValuesToTags', this.comparator + ' ' + moment(this.value, moment.ISO_8601).format(this.dateFormat)); this.$emit('sendValuesToTags', {
label: this.comparator + ' ' + moment(this.value, moment.ISO_8601).format(this.dateFormat),
value: this.value
});
} }
} else { } else {
@ -226,7 +229,10 @@
collection_id: this.collectionId, collection_id: this.collectionId,
value: valueQuery value: valueQuery
}); });
this.$emit('sendValuesToTags', this.comparator + ' ' + moment(this.value, moment.ISO_8601).format(this.dateFormat)); this.$emit('sendValuesToTags', {
label: this.comparator + ' ' + moment(this.value, moment.ISO_8601).format(this.dateFormat),
value: valueQuery
});
}, },
onChangeComparator(newComparator) { onChangeComparator(newComparator) {

View File

@ -25,7 +25,7 @@ export const filterTypeMixin = {
this.metadatumType = this.filter.metadatum.metadata_type_object.className ? this.filter.metadatum.metadata_type_object.className : this.metadatumType; this.metadatumType = this.filter.metadatum.metadata_type_object.className ? this.filter.metadatum.metadata_type_object.className : this.metadatumType;
}, },
mounted() { mounted() {
this.$eventBusSearch.$on('removeFromFilterTag', this.cleanFromTags );
}, },
methods: { methods: {
cleanFromTags(filterTag) { cleanFromTags(filterTag) {
@ -35,7 +35,7 @@ export const filterTypeMixin = {
}, },
beforeDestroy() { beforeDestroy() {
this.$eventBusSearch.$off('removeFromFilterTag', this.cleanFromTags); this.$eventBusSearch.$off('removeFromFilterTag', this.cleanFromTags);
}, }
}; };
export const dynamicFilterTypeMixin = { export const dynamicFilterTypeMixin = {
@ -43,14 +43,9 @@ export const dynamicFilterTypeMixin = {
return { return {
thumbPlaceholderPath: tainacan_plugin.base_url + '/admin/images/placeholder_square.png', thumbPlaceholderPath: tainacan_plugin.base_url + '/admin/images/placeholder_square.png',
getOptionsValuesCancel: undefined, getOptionsValuesCancel: undefined,
isLoadingOptions: false isLoadingOptions: false,
} }
}, },
mounted() {
// We listen to event, but reload event if hasFiltered is negative, as
// an empty query also demands filters reloading.
this.$eventBusSearch.$on('hasFiltered', this.reloadOptionsDueToFiltering);
},
computed: { computed: {
facetsFromItemSearch() { facetsFromItemSearch() {
return this.getFacets(); return this.getFacets();
@ -344,17 +339,10 @@ export const dynamicFilterTypeMixin = {
} }
} }
}, },
reloadOptionsDueToFiltering() {
if (typeof this.loadOptions === "function")
this.loadOptions(true);
}
}, },
beforeDestroy() { beforeDestroy() {
// Cancels previous Request // Cancels previous Request
if (this.getOptionsValuesCancel != undefined) if (this.getOptionsValuesCancel != undefined)
this.getOptionsValuesCancel.cancel('Facet search Canceled.'); this.getOptionsValuesCancel.cancel('Facet search Canceled.');
this.$eventBusSearch.$off('hasFiltered', this.reloadOptionsDueToFiltering);
}, },
}; };

View File

@ -87,7 +87,7 @@
}); });
if (values[0] != undefined && values[1] != undefined) if (values[0] != undefined && values[1] != undefined)
this.$emit('sendValuesToTags', values[0] + ' - ' + values[1]); this.$emit('sendValuesToTags', { label: values[0] + ' - ' + values[1], value: values });
}, },
selectedValues(){ selectedValues(){
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) ) if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
@ -102,7 +102,7 @@
} }
if (metaquery.value[0] != undefined && metaquery.value[1] != undefined) if (metaquery.value[0] != undefined && metaquery.value[1] != undefined)
this.$emit( 'sendValuesToTags', this.valueInit + ' - ' + this.valueEnd); this.$emit('sendValuesToTags', { label: this.valueInit + ' - ' + this.valueEnd, value: metaquery.values });
} else { } else {
return false; return false;

View File

@ -72,7 +72,7 @@
if (values[0] != undefined && values[1] != undefined) { if (values[0] != undefined && values[1] != undefined) {
let labelValue = this.filterTypeOptions.intervals[this.selectedInterval].label + (this.filterTypeOptions.showIntervalOnTag ? `(${values[0]}-${values[1]})` : ''); let labelValue = this.filterTypeOptions.intervals[this.selectedInterval].label + (this.filterTypeOptions.showIntervalOnTag ? `(${values[0]}-${values[1]})` : '');
this.$emit( 'sendValuesToTags', labelValue); this.$emit('sendValuesToTags', { label: labelValue, value: values });
} }
}, },
selectedValues(){ selectedValues(){
@ -97,7 +97,7 @@
); );
let labelValue = this.filterTypeOptions.intervals[this.selectedInterval].label + (this.filterTypeOptions.showIntervalOnTag ? `(${this.valueInit}-${this.valueEnd})` : ''); let labelValue = this.filterTypeOptions.intervals[this.selectedInterval].label + (this.filterTypeOptions.showIntervalOnTag ? `(${this.valueInit}-${this.valueEnd})` : '');
this.$emit( 'sendValuesToTags', labelValue); this.$emit('sendValuesToTags', { label: labelValue, value: [ this.valueInit, this.valueEnd ] });
} else { } else {
return false; return false;
} }

View File

@ -118,7 +118,7 @@
this.comparator = metadata.compare; this.comparator = metadata.compare;
if (this.value != undefined) if (this.value != undefined)
this.$emit('sendValuesToTags', this.comparator + ' ' + this.value); this.$emit('sendValuesToTags', { label: this.comparator + ' ' + this.value, value: this.value });
} else { } else {
return false; return false;
@ -157,7 +157,7 @@
type: 'NUMERIC' type: 'NUMERIC'
}); });
this.$emit('sendValuesToTags', this.comparator + ' ' + this.value); this.$emit('sendValuesToTags', { label: this.comparator + ' ' + this.value, value: this.value });
}, },
onChangeComparator(newComparator) { onChangeComparator(newComparator) {

View File

@ -38,7 +38,7 @@
watch: { watch: {
selected(value) { selected(value) {
if (value) if (value)
this.$emit('sendValuesToTags', value); this.$emit('sendValuesToTags', { label: value, value: value });
} }
}, },
computed: { computed: {

View File

@ -34,11 +34,11 @@
<div :id="'filter-input-id-' + filter.id"> <div :id="'filter-input-id-' + filter.id">
<component <component
:is="filter.filter_type_object.component" :is="filter.filter_type_object.component"
:key="reloadDueFiltering"
:filter="filter" :filter="filter"
:query="query" :query="query"
:is-repository-level="isRepositoryLevel" :is-repository-level="isRepositoryLevel"
:is-loading-items.sync="isLoadingItems" :is-loading-items.sync="isLoadingItems"
:is-using-elastic-search="isUsingElasticSearch"
@input="onInput" @input="onInput"
@sendValuesToTags="onSendValuesToTags"/> @sendValuesToTags="onSendValuesToTags"/>
</div> </div>
@ -59,6 +59,7 @@
return { return {
isLoadingItems: Boolean, isLoadingItems: Boolean,
isUsingElasticSearch: tainacan_plugin.wp_elasticpress == "1" ? true : false, isUsingElasticSearch: tainacan_plugin.wp_elasticpress == "1" ? true : false,
reloadOptionsDueFiltering: Boolean
} }
}, },
mounted() { mounted() {
@ -67,21 +68,36 @@
this.isLoadingOptions = isLoadingItems; this.isLoadingOptions = isLoadingItems;
}); });
} }
this.$eventBusSearch.$on('removeFromFilterTag', this.cleanFromTags );
// We listen to event, but reload event if hasFiltered is negative, as
// an empty query also demands filters reloading.
this.$eventBusSearch.$on('hasFiltered', this.reloadFilter);
}, },
methods: { methods: {
onInput(inputEvent){ onInput(inputEvent){
this.$eventBusSearch.$emit('input', inputEvent); this.$eventBusSearch.$emit('input', inputEvent);
}, },
onSendValuesToTags(values) { onSendValuesToTags($event) {
this.$eventBusSearch.$emit('sendValuesToTags', { this.$eventBusSearch.$emit('sendValuesToTags', {
filterId: this.filter.id, filterId: this.filter.id,
value: values label: $event.label,
value: $event.value,
taxonomy: $event.taxonomy,
metadatumId: this.filter.metadatum_id
}); });
} },
}, reloadFilter() {
this.reloadDueFiltering = !this.reloadDueFiltering;
},
cleanFromTags() {
},
},
beforeDestroy() { beforeDestroy() {
if (this.isUsingElasticSearch) if (this.isUsingElasticSearch)
this.$eventBusSearch.$off('isLoadingItems'); this.$eventBusSearch.$off('isLoadingItems');
this.$eventBusSearch.$off('hasFiltered', this.reloadFilter);
this.$eventBusSearch.$off('removeFromFilterTag', this.cleanFromTags);
} }
} }
</script> </script>

View File

@ -223,7 +223,7 @@
} }
} }
this.$emit("sendValuesToTags", onlyLabels); this.$emit('sendValuesToTags', { label: onlyLabels, taxonomy: this.taxonomy, value: this.selected });
}, },
openCheckboxModal(parent) { openCheckboxModal(parent) {
this.$buefy.modal.open({ this.$buefy.modal.open({

View File

@ -154,7 +154,7 @@
terms: values terms: values
}); });
this.$emit("sendValuesToTags", labels); this.$emit('sendValuesToTags', { label: labels, taxonomy: this.taxonomy, value: values });
}, },
getTerm( taxonomy, id ){ getTerm( taxonomy, id ){
//getting a specific value from api, does not need be in fecat api //getting a specific value from api, does not need be in fecat api
@ -190,7 +190,7 @@
collection_id: this.collectionId, collection_id: this.collectionId,
terms: values terms: values
}); });
this.$emit( 'sendValuesToTags', labels); this.$emit('sendValuesToTags', { label: labels, taxonomy: this.taxonomy });
} }
} }
} }

View File

@ -17,13 +17,10 @@ export default {
created() { created() {
this.$on('input', data => { this.$on('input', data => {
this.$store.dispatch('search/setPage', 1); this.$store.dispatch('search/setPage', 1);
if (data.taxonomy) if (data.taxonomy)
this.add_taxquery(data); this.addTaxquery(data);
else else
this.add_metaquery(data); this.addMetaquery(data);
this.updateURLQueries();
}); });
this.$on('sendValuesToTags', data => { this.$on('sendValuesToTags', data => {
@ -173,24 +170,38 @@ export default {
this.$store.dispatch('search/set_advanced_query', data); this.$store.dispatch('search/set_advanced_query', data);
this.updateURLQueries(); this.updateURLQueries();
}, },
add_metaquery( data ){ addMetaquery( data ){
if ( data && data.collection_id ){ if ( data && data.collection_id ){
this.$store.dispatch('search/add_metaquery', data ); this.$store.dispatch('search/add_metaquery', data );
} }
},
removeMetaQuery(query) {
this.$store.dispatch('search/remove_metaquery', query );
this.updateURLQueries(); this.updateURLQueries();
}, },
removeMetaFromFilterTag(filterTag) { addTaxquery( data ){
this.$emit('removeFromFilterTag', filterTag);
if (filterTag.singleValue == undefined)
this.$store.dispatch('search/removeFilterTag', filterTag);
},
add_taxquery( data ){
if ( data && data.collection_id ){ if ( data && data.collection_id ){
this.$store.dispatch('search/add_taxquery', data ); this.$store.dispatch('search/add_taxquery', data );
} }
this.updateURLQueries();
},
removeMetaFromFilterTag(filterTag) {
if (filterTag.singleLabel != undefined) {
if (filterTag.taxonomy)
this.$store.dispatch('search/remove_taxquery', {
filterId: filterTag.filterId,
label: filterTag.singleLabel,
taxonomy: filterTag.taxonomy,
value: filterTag.value
});
else
this.$store.dispatch('search/remove_metaquery', {
filterId: filterTag.filterId,
label: filterTag.singleLabel,
metadatum_id: filterTag.metadatumId,
value: filterTag.value
});
}
this.updateURLQueries();
}, },
addFetchOnly( metadatum, ignorePrefs, metadatumIDs ){ addFetchOnly( metadatum, ignorePrefs, metadatumIDs ){

View File

@ -50,6 +50,10 @@ export const remove_metaquery = ( { commit }, filter ) => {
commit('removeMetaQuery', filter ); commit('removeMetaQuery', filter );
}; };
export const remove_taxquery = ( { commit }, filter ) => {
commit('removeTaxQuery', filter );
};
// Pagination queries // Pagination queries
export const setTotalItems = ({ commit }, total ) => { export const setTotalItems = ({ commit }, total ) => {
commit('setTotalItems', total); commit('setTotalItems', total);

View File

@ -96,15 +96,29 @@ export const removeMetaQuery = ( state, filter ) => {
let index = state.postquery.metaquery.findIndex( item => item.key == filter.metadatum_id); let index = state.postquery.metaquery.findIndex( item => item.key == filter.metadatum_id);
if (index >= 0) { if (index >= 0) {
state.postquery.metaquery.splice(index, 1); if (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)
state.postquery.metaquery[index].value.splice(otherIndex, 1)
} else
state.postquery.metaquery.splice(index, 1);
} }
}; };
export const removeTaxQuery = ( state, filter ) => { export const removeTaxQuery = ( state, filter ) => {
let index = state.postquery.taxquery.findIndex( item => item.taxonomy == filter.taxonomy); state.postquery.taxquery = ( ! state.postquery.taxquery ) ? [] : state.postquery.taxquery;
let index = state.postquery.taxquery.findIndex( item => item.taxonomy == filter.taxonomy);
if (index >= 0) { if (index >= 0) {
state.postquery.taxquery.splice(index, 1); if (Array.isArray(state.postquery.taxquery[index].terms) && state.postquery.taxquery[index].terms.length > 1) {
let otherIndex = state.postquery.taxquery[index].terms.findIndex(item => item == filter.value);
if (otherIndex >= 0)
state.postquery.taxquery[index].terms.splice(otherIndex, 1)
} else
state.postquery.taxquery.splice(index, 1);
} }
}; };