Adjustments to taxonomy checkbox filter.

This commit is contained in:
Mateus Machado Luna 2019-10-15 10:51:51 -03:00
parent 92f375d142
commit 19606a1a93
6 changed files with 20 additions and 46 deletions

View File

@ -70,7 +70,7 @@
this.loadOptions();
},
methods: {
loadOptions(skipSelected) {
loadOptions() {
let promise = null;
// Cancels previous Request
@ -82,27 +82,18 @@
else
promise = this.getValuesPlainText( this.metadatumId, null, this.isRepositoryLevel, [], 0, this.filter.max_options, false, '1' );
if (skipSelected != undefined && skipSelected == true) {
promise.request
.then(() => {
if (this.options.length > this.filter.max_options)
this.options.splice(this.filter.max_options);
}).catch((error) => {
this.$console.error(error);
});
} else {
promise.request
.then(() => {
promise.request
.then(() => {
this.selectedValues();
})
.catch( (error) => {
if (isCancel(error)) {
this.$console.log('Request canceled: ' + error.message);
this.selectedValues();
})
.catch( (error) => {
if (isCancel(error)) {
this.$console.log('Request canceled: ' + error.message);
this.selectedValues();
} else
this.$console.error( error );
});
}
} else
this.$console.error( error );
});
// Search Request Token for cancelling
this.getOptionsValuesCancel = promise.source;
},

View File

@ -57,8 +57,7 @@
data() {
return {
isLoadingItems: Boolean,
isUsingElasticSearch: tainacan_plugin.wp_elasticpress == "1" ? true : false,
reloadDueFiltering: Boolean
isUsingElasticSearch: tainacan_plugin.wp_elasticpress == "1" ? true : false
}
},
mounted() {
@ -67,9 +66,6 @@
this.isLoadingOptions = isLoadingItems;
});
}
// 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: {
onInput(inputEvent) {
@ -83,16 +79,11 @@
taxonomy: $event.taxonomy,
metadatumId: this.filter.metadatum_id
});
},
reloadFilter() {
this.reloadDueFiltering = !this.reloadDueFiltering;
}
},
beforeDestroy() {
if (this.isUsingElasticSearch)
this.$eventBusSearch.$off('isLoadingItems');
this.$eventBusSearch.$off('hasFiltered', this.reloadFilter);
}
}
</script>

View File

@ -87,7 +87,7 @@
...mapGetters('search', [
'getFacets'
]),
loadOptions(skipSelected) {
loadOptions() {
if (!this.isUsingElasticSearch) {
let promise = null;
const source = CancelToken.source();
@ -123,7 +123,7 @@
});
promise.request
.then((res) => {
this.prepareOptionsForTaxonomy(res.data.values ? res.data.values : res.data, skipSelected);
this.prepareOptionsForTaxonomy(res.data.values ? res.data.values : res.data);
this.isLoadingOptions = false;
})
.catch( error => {
@ -143,9 +143,9 @@
for (const facet in this.facetsFromItemSearch) {
if (facet == this.filter.id) {
if (Array.isArray(this.facetsFromItemSearch[facet]))
this.prepareOptionsForTaxonomy(this.facetsFromItemSearch[facet], skipSelected);
this.prepareOptionsForTaxonomy(this.facetsFromItemSearch[facet]);
else
this.prepareOptionsForTaxonomy(Object.values(this.facetsFromItemSearch[facet]), skipSelected);
this.prepareOptionsForTaxonomy(Object.values(this.facetsFromItemSearch[facet]));
}
}
}
@ -164,7 +164,6 @@
return false;
}
let onlyLabels = [];
for (let selected of this.selected) {
@ -257,7 +256,7 @@
trapFocus: true
});
},
prepareOptionsForTaxonomy(items, skipSelected) {
prepareOptionsForTaxonomy(items) {
if (items[0] != undefined) {
this.taxonomy = items[0].taxonomy;
@ -287,9 +286,7 @@
}
}
}
if (skipSelected == undefined || skipSelected == false) {
this.selectedValues();
}
this.selectedValues();
},
updatesIsLoading(isLoadingOptions) {
this.isLoadingOptions = isLoadingOptions;

View File

@ -127,7 +127,7 @@
return false;
this.taxonomy = 'tnc_tax_' + this.taxonomyId;
console.log(this.taxonomy)
let index = this.query.taxquery.findIndex(newMetadatum => newMetadatum.taxonomy == this.taxonomy );
if ( index >= 0){
let metadata = this.query.taxquery[ index ];
@ -171,13 +171,11 @@
getTerms(metadata) {
let promises = [];
for ( let id of metadata.terms ) {
console.log(id)
//getting a specific value from api, does not need be in facets api
promises.push(
axios.get('/taxonomy/' + this.taxonomyId + '/terms/' + id + '?order=asc' )
.then( res => {
this.selected.push({ label: res.data.name, value: res.data.id });
console.log("passei aqyui")
})
.catch(error => {
this.$console.log(error);

View File

@ -25,7 +25,6 @@ export default {
});
this.$on('sendValuesToTags', data => {
console.log(data)
this.$store.dispatch('search/addFilterTag', data);
});

View File

@ -160,14 +160,12 @@ export const setOrderByName = ( state, orderByName ) => {
export const addFilterTag = ( state, filterTag ) => {
state.filter_tags = ( ! state.filter_tags) ? [] : state.filter_tags;
console.log(state.filter_tags)
let index = state.filter_tags.findIndex( tag => tag.filterId == filterTag.filterId);
if (index >= 0)
Vue.set(state.filter_tags, index, filterTag);
else
state.filter_tags.push(filterTag);
console.log(state.filter_tags)
};
export const removeFilterTag = ( state, filterTag ) => {