Fixes queries for relationship value on frontend.
This commit is contained in:
parent
cd66f78e27
commit
2e8cd4fd86
|
@ -110,53 +110,71 @@ export const filter_type_mixin = {
|
|||
},
|
||||
getValuesRelationship(collectionTarget, search, isRepositoryLevel, valuesToIgnore, offset, number, isInCheckboxModal, getSelected = '0') {
|
||||
|
||||
const source = axios.CancelToken.source();
|
||||
if (search || this.facetsFromItemSearch && this.facetsFromItemSearch.length > 0) {
|
||||
|
||||
let currentQuery = JSON.parse(JSON.stringify(this.query));
|
||||
if (currentQuery.fetch_only != undefined) {
|
||||
delete currentQuery.fetch_only;
|
||||
// for (let key of Object.keys(currentQuery.fetch_only)) {
|
||||
// if (currentQuery.fetch_only[key] == null)
|
||||
// delete currentQuery.fetch_only[key];
|
||||
// }
|
||||
}
|
||||
let query_items = { 'current_query': currentQuery };
|
||||
const source = axios.CancelToken.source();
|
||||
|
||||
let url = '';
|
||||
if (isRepositoryLevel || this.filter.collection_id == 'filter_in_repository')
|
||||
url = '/facets/' + this.filter.metadatum.metadatum_id + `?getSelected=${getSelected}&`;
|
||||
else
|
||||
url = '/collection/' + this.filter.collection_id + '/facets/' + this.filter.metadatum.metadatum_id + `?getSelected=${getSelected}&`;
|
||||
let currentQuery = JSON.parse(JSON.stringify(this.query));
|
||||
if (currentQuery.fetch_only != undefined) {
|
||||
delete currentQuery.fetch_only;
|
||||
// for (let key of Object.keys(currentQuery.fetch_only)) {
|
||||
// if (currentQuery.fetch_only[key] == null)
|
||||
// delete currentQuery.fetch_only[key];
|
||||
// }
|
||||
}
|
||||
let query_items = { 'current_query': currentQuery };
|
||||
|
||||
if(offset != undefined && number != undefined){
|
||||
url += `offset=${offset}&number=${number}`;
|
||||
} else {
|
||||
url += `nopaging=1`
|
||||
}
|
||||
let url = '';
|
||||
if (isRepositoryLevel || this.filter.collection_id == 'filter_in_repository')
|
||||
url = '/facets/' + this.filter.metadatum.metadatum_id + `?getSelected=${getSelected}&`;
|
||||
else
|
||||
url = '/collection/' + this.filter.collection_id + '/facets/' + this.filter.metadatum.metadatum_id + `?getSelected=${getSelected}&`;
|
||||
|
||||
if(search){
|
||||
url += `&search=${search}`;
|
||||
}
|
||||
if(offset != undefined && number != undefined){
|
||||
url += `offset=${offset}&number=${number}`;
|
||||
} else {
|
||||
url += `nopaging=1`
|
||||
}
|
||||
|
||||
this.isLoadingOptions = true;
|
||||
if(search){
|
||||
url += `&search=${search}`;
|
||||
}
|
||||
|
||||
return new Object ({
|
||||
request:
|
||||
axios.tainacan.get(url + '&fetch_only=thumbnail,title,id&' + qs.stringify(query_items))
|
||||
.then(res => {
|
||||
this.isLoadingOptions = false;
|
||||
this.prepareOptionsForRelationship(res.data, search, valuesToIgnore, isInCheckboxModal);
|
||||
})
|
||||
.catch((thrown) => {
|
||||
if (axios.isCancel(thrown)) {
|
||||
console.log('Request canceled: ', thrown.message);
|
||||
} else {
|
||||
this.isLoadingOptions = true;
|
||||
|
||||
return new Object ({
|
||||
request:
|
||||
axios.tainacan.get(url + '&fetch_only=thumbnail,title,id&' + qs.stringify(query_items))
|
||||
.then(res => {
|
||||
this.isLoadingOptions = false;
|
||||
reject(thrown);
|
||||
}
|
||||
}),
|
||||
source: source
|
||||
});
|
||||
|
||||
if (res.data.values)
|
||||
this.prepareOptionsForRelationship(res.data.values, search, valuesToIgnore, isInCheckboxModal);
|
||||
else
|
||||
this.prepareOptionsForRelationship(res.data, search, valuesToIgnore, isInCheckboxModal);
|
||||
})
|
||||
.catch((thrown) => {
|
||||
if (axios.isCancel(thrown)) {
|
||||
console.log('Request canceled: ', thrown.message);
|
||||
} else {
|
||||
this.isLoadingOptions = false;
|
||||
reject(thrown);
|
||||
}
|
||||
}),
|
||||
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);
|
||||
|
|
|
@ -163,8 +163,10 @@
|
|||
|
||||
axios.get('/collection/' + collectionTarget + '/items?' + query)
|
||||
.then( res => {
|
||||
for (let item of res.data) {
|
||||
instance.selected.push({ label: item.title, value: item.id, img: item.thumbnail.thumbnail[0] });
|
||||
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 => {
|
||||
|
|
|
@ -27,8 +27,10 @@
|
|||
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) {
|
||||
this.selected.push({ label: item.title, value: item.id, img: '' });
|
||||
if (res.data.items) {
|
||||
for (let item of res.data.items) {
|
||||
this.selected.push({ label: item.title, value: item.id, img: '' });
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
|
@ -115,8 +117,11 @@
|
|||
this.loading = false;
|
||||
this.options = [];
|
||||
let result = res.data;
|
||||
for (let item of result) {
|
||||
this.options.push({ label: item.title, value: item.id })
|
||||
|
||||
if (result.items) {
|
||||
for (let item of result.items) {
|
||||
this.options.push({ label: item.title, value: item.id })
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue