Fixes queries for relationship value on frontend.

This commit is contained in:
Mateus Machado Luna 2019-02-27 14:34:03 -03:00
parent cd66f78e27
commit 2e8cd4fd86
5 changed files with 76 additions and 51 deletions

View File

@ -110,6 +110,8 @@ export const filter_type_mixin = {
},
getValuesRelationship(collectionTarget, search, isRepositoryLevel, valuesToIgnore, offset, number, isInCheckboxModal, getSelected = '0') {
if (search || this.facetsFromItemSearch && this.facetsFromItemSearch.length > 0) {
const source = axios.CancelToken.source();
let currentQuery = JSON.parse(JSON.stringify(this.query));
@ -145,6 +147,10 @@ export const filter_type_mixin = {
axios.tainacan.get(url + '&fetch_only=thumbnail,title,id&' + qs.stringify(query_items))
.then(res => {
this.isLoadingOptions = false;
if (res.data.values)
this.prepareOptionsForRelationship(res.data.values, search, valuesToIgnore, isInCheckboxModal);
else
this.prepareOptionsForRelationship(res.data, search, valuesToIgnore, isInCheckboxModal);
})
.catch((thrown) => {
@ -157,6 +163,18 @@ export const filter_type_mixin = {
}),
source: source
});
} else {
let callback = new Promise((resolve) => {
for (const facet in this.facetsFromItemSearch) {
if (facet == this.filter.id) {
this.prepareOptionsForRelationship(this.facetsFromItemSearch[facet], search, valuesToIgnore, isInCheckboxModal);
}
}
});
return new Object ({
request: callback
});
}
},
prepareOptionsForPlainText(metadata, search, valuesToIgnore, isInCheckboxModal) {
@ -224,7 +242,7 @@ export const filter_type_mixin = {
let sResults = [];
let opts = [];
if (res.data.length > 0) {
if (items.length > 0) {
for (let item of items) {
if (valuesToIgnore != undefined && valuesToIgnore.length > 0) {
let indexToIgnore = valuesToIgnore.findIndex(value => value == item.value);

View File

@ -163,9 +163,11 @@
axios.get('/collection/' + collectionTarget + '/items?' + query)
.then( res => {
if (res.data.items) {
for (let item of res.data) {
instance.selected.push({ label: item.title, value: item.id, img: item.thumbnail.thumbnail[0] });
}
}
})
.catch(error => {
this.$console.log(error);

View File

@ -27,9 +27,11 @@
let query = qs.stringify({ postin: ( Array.isArray( this.metadatum.value ) ) ? this.metadatum.value : [ this.metadatum.value ] });
axios.get('/collection/'+collectionId+'/items?' + query + '&nopaging=1')
.then( res => {
for (let item of res.data) {
if (res.data.items) {
for (let item of res.data.items) {
this.selected.push({ label: item.title, value: item.id, img: '' });
}
}
})
.catch(error => {
this.$console.log(error);
@ -115,9 +117,12 @@
this.loading = false;
this.options = [];
let result = res.data;
for (let item of result) {
if (result.items) {
for (let item of result.items) {
this.options.push({ label: item.title, value: item.id })
}
}
})
.catch(error => {
this.$console.log(error);

View File

@ -123,7 +123,7 @@ registerBlockType('tainacan/collections-carousel', {
return tainacan.get(`/collection/${collectionID}/items?perpage=3&paged=1&orderby=date`)
.then(response => {
return response.data;
return response.data.items;
})
.catch(error => {
console.error(error);

View File

@ -137,7 +137,7 @@ registerBlockType('tainacan/items-grid', {
if(collectionID) {
return tainacan.get(`/collection/${collectionID}/items?${query}`)
.then(response => {
return response.data;
return response.data.items;
})
.catch(error => {
console.error(error);
@ -145,7 +145,7 @@ registerBlockType('tainacan/items-grid', {
} else {
return tainacan.get(`/items?${query}`)
.then(response => {
return response.data;
return response.data.items;
})
.catch(error => {
console.error(error);