Uses include instead of multiple request for terms on taxonomy taginput.

This commit is contained in:
Mateus Machado Luna 2019-10-23 11:27:46 -03:00
parent 044b808019
commit 6249886f29
1 changed files with 18 additions and 16 deletions

View File

@ -38,7 +38,7 @@
<script>
import qs from 'qs';
import { tainacan as axios, all } from '../../../js/axios/axios';
import { tainacan as axios } from '../../../js/axios/axios';
import { filterTypeMixin, dynamicFilterTypeMixin } from '../filter-types-mixin';
export default {
@ -58,6 +58,9 @@
this.updateSelectedValues();
}
},
mounted() {
this.updateSelectedValues();
},
data(){
return {
results:'',
@ -151,20 +154,19 @@
});
},
getTerms(metadata) {
let promises = [];
for (let id of metadata.terms) {
//getting a specific value from api, does not need be in facets api
promises.push(
axios.get('/taxonomy/' + this.taxonomyId + '/terms/' + id + '?order=asc' )
let params = {
'include': metadata.terms,
'order': 'asc'
};
return axios.get('/taxonomy/' + this.taxonomyId + '/terms/?' + qs.stringify(params) )
.then( res => {
this.selected.push({ label: res.data.name, value: res.data.id });
this.selected = res.data.map(term => { return { label: term.name, value: term.id } });
})
.catch(error => {
this.$console.log(error);
})
);
}
return all(promises);
}
}
}