Uses new fetch_preview_image_items on the carousel blocks. #504
This commit is contained in:
parent
7943102946
commit
64372dd448
|
@ -330,15 +330,17 @@ class REST_Terms_Controller extends REST_Controller {
|
|||
]);
|
||||
|
||||
$item_arr['total_children'] = count($children);
|
||||
if(isset($request['fetch_preview_image_items']) && $request['fetch_preview_image_items'] != 0) {
|
||||
$item_arr['preview_image_items'] = $this->get_preview_image_items($item, $request['fetch_preview_image_items']);
|
||||
}
|
||||
|
||||
} else {
|
||||
$attributes_to_filter = $request['fetch_only'];
|
||||
|
||||
$item_arr = $this->filter_object_by_attributes($item, $attributes_to_filter);
|
||||
}
|
||||
|
||||
if(isset($request['fetch_preview_image_items']) && $request['fetch_preview_image_items'] != 0) {
|
||||
$item_arr['preview_image_items'] = $this->get_preview_image_items($item, $request['fetch_preview_image_items']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this filter to add additional term_meta to the api response
|
||||
* Use the $request object to get the context of the request and other variables
|
||||
|
|
|
@ -71,7 +71,7 @@ export default function ({ attributes, setAttributes, className, isSelected, cli
|
|||
<a
|
||||
id={ isNaN(collection.id) ? collection.id : 'collection-id-' + collection.id }
|
||||
href={ collection.url }>
|
||||
{ !showCollectionThumbnail ?
|
||||
{ ( !showCollectionThumbnail && Array.isArray(collectionItems) ) ?
|
||||
<div class="collection-items-grid">
|
||||
<img
|
||||
src={ collectionItems[0] ? thumbHelper.getSrc(collectionItems[0]['thumbnail'], 'tainacan-medium', collectionItems[0]['document_mimetype']) :`${tainacan_blocks.base_url}/assets/images/placeholder_square.png` }
|
||||
|
@ -107,9 +107,9 @@ export default function ({ attributes, setAttributes, className, isSelected, cli
|
|||
);
|
||||
}
|
||||
|
||||
function setContent(){
|
||||
isLoading = true;
|
||||
function setContent() {
|
||||
|
||||
isLoading = true;
|
||||
setAttributes({
|
||||
isLoading: isLoading
|
||||
});
|
||||
|
@ -121,41 +121,20 @@ export default function ({ attributes, setAttributes, className, isSelected, cli
|
|||
|
||||
collections = [];
|
||||
|
||||
let endpoint = '/collections?'+ qs.stringify({ postin: selectedCollections.map((collection) => { return collection.id }), perpage: selectedCollections.length }) + '&fetch_only=name,url,thumbnail';
|
||||
let endpoint = '/collections?'+ qs.stringify({ postin: selectedCollections.map((collection) => { return collection.id }), perpage: selectedCollections.length, fetch_preview_image_items: showCollectionThumbnail ? 0 : 3 }) + '&fetch_only=name,url,thumbnail';
|
||||
tainacan.get(endpoint, { cancelToken: itemsRequestSource.token })
|
||||
.then(response => {
|
||||
|
||||
if (showCollectionThumbnail) {
|
||||
for (let collection of response.data) {
|
||||
collections.push(prepareItem(collection));
|
||||
}
|
||||
setAttributes({
|
||||
content: <div></div>,
|
||||
collections: collections,
|
||||
isLoading: false,
|
||||
itemsRequestSource: itemsRequestSource
|
||||
});
|
||||
} else {
|
||||
let promises = [];
|
||||
for (let collection of response.data) {
|
||||
promises.push(
|
||||
tainacan.get('/collection/' + collection.id + '/items?perpage=3&fetch_only=name,url,thumbnail')
|
||||
.then(response => { return({ collection: collection, collectionItems: response.data.items }) })
|
||||
.catch((error) => console.log(error))
|
||||
);
|
||||
}
|
||||
axios.all(promises).then((results) => {
|
||||
for (let result of results) {
|
||||
collections.push(prepareItem(result.collection, result.collectionItems));
|
||||
}
|
||||
setAttributes({
|
||||
content: <div></div>,
|
||||
collections: collections,
|
||||
isLoading: false,
|
||||
itemsRequestSource: itemsRequestSource
|
||||
});
|
||||
})
|
||||
}
|
||||
for (let collection of response.data)
|
||||
collections.push(prepareItem(collection, (!showCollectionThumbnail && collection.preview_image_items) ? collection.preview_image_items : []));
|
||||
|
||||
isLoading = false;
|
||||
setAttributes({
|
||||
content: <div></div>,
|
||||
collections: collections,
|
||||
isLoading: isLoading,
|
||||
itemsRequestSource: itemsRequestSource
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -43,12 +43,8 @@
|
|||
:
|
||||
`${tainacanBaseUrl}/assets/images/placeholder_square.png`)
|
||||
"
|
||||
:class="maxCollectionsPerScreen <= 4 ? 'swiper-lazy' : ''"
|
||||
:alt="collection.name ? collection.name : $root.__('Thumbnail', 'tainacan')">
|
||||
<span v-if="!hideName">{{ collection.name ? collection.name : '' }}</span>
|
||||
<div
|
||||
v-if="maxCollectionsPerScreen <= 4"
|
||||
class="swiper-lazy-preloader swiper-lazy-preloader-white"/>
|
||||
</a>
|
||||
<a
|
||||
v-else
|
||||
|
@ -299,43 +295,26 @@ export default {
|
|||
|
||||
this.collectionsRequestSource = axios.CancelToken.source();
|
||||
|
||||
let endpoint = '/collections?'+ qs.stringify({ postin: this.selectedCollections, perpage: this.selectedCollections.length }) + '&fetch_only=name,url,thumbnail';
|
||||
let endpoint = '/collections?'+ qs.stringify({ postin: this.selectedCollections, perpage: this.selectedCollections.length, fetch_preview_image_items: this.showCollectionThumbnail ? 0 : 3 }) + '&fetch_only=name,url,thumbnail';
|
||||
|
||||
this.tainacanAxios.get(endpoint, { cancelToken: this.collectionsRequestSource.token })
|
||||
.then(response => {
|
||||
|
||||
if (this.showCollectionThumbnail) {
|
||||
for (let collection of response.data)
|
||||
this.collections.push(collection);
|
||||
|
||||
this.isLoading = false;
|
||||
} else {
|
||||
let promises = [];
|
||||
for (let collection of response.data) {
|
||||
promises.push(
|
||||
this.tainacanAxios.get('/collection/' + collection.id + '/items?perpage=3&fetch_only=name,url,thumbnail')
|
||||
.then(response => { return({ collectionId: collection.id, collectionItems: response.data.items }) })
|
||||
);
|
||||
this.collections.push(collection);
|
||||
}
|
||||
axios.all(promises).then((results) => {
|
||||
for (let result of results) {
|
||||
this.collectionItems[result.collectionId] = result.collectionItems;
|
||||
}
|
||||
|
||||
this.isLoading = false;
|
||||
})
|
||||
for (let collection of response.data) {
|
||||
this.collections.push(collection);
|
||||
if (!this.showCollectionThumbnail)
|
||||
this.collectionItems[collection.id] = collection.preview_image_items ? collection.preview_image_items : [];
|
||||
}
|
||||
|
||||
|
||||
this.isLoading = false;
|
||||
this.totalCollections = response.headers['x-wp-total'];
|
||||
|
||||
}).catch((error) => {
|
||||
this.isLoading = false;
|
||||
if (error.response && error.response.status && error.response.status == 401)
|
||||
this.errorMessage = 'Not allowed to see these collections.'
|
||||
if (error.response && error.response.status && error.response.status == 401)
|
||||
this.errorMessage = 'Not allowed to see these collections.'
|
||||
|
||||
});
|
||||
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ export default function({ attributes, setAttributes, className, isSelected, clie
|
|||
<a
|
||||
id={ isNaN(term.id) ? term.id : 'term-id-' + term.id }
|
||||
href={ term.url }>
|
||||
{ !showTermThumbnail ?
|
||||
{ ( !showTermThumbnail && Array.isArray(termItems) ) ?
|
||||
<div class="term-items-grid">
|
||||
<img
|
||||
src={ termItems[0] ? thumbHelper.getSrc(termItems[0]['thumbnail'], 'tainacan-medium', termItems[0]['document_mimetype']) :`${tainacan_blocks.base_url}/assets/images/placeholder_square.png` }
|
||||
|
@ -93,9 +93,9 @@ export default function({ attributes, setAttributes, className, isSelected, clie
|
|||
);
|
||||
}
|
||||
|
||||
function setContent(){
|
||||
isLoading = true;
|
||||
function setContent() {
|
||||
|
||||
isLoading = true;
|
||||
setAttributes({
|
||||
isLoading: isLoading
|
||||
});
|
||||
|
@ -107,41 +107,20 @@ export default function({ attributes, setAttributes, className, isSelected, clie
|
|||
|
||||
terms = [];
|
||||
|
||||
let endpoint = '/taxonomy/' + taxonomyId + '/terms/?'+ qs.stringify({ hideempty: 0, include: selectedTerms.map((term) => { return term.id; }) }) + '&order=asc&fetch_only=id,name,url,header_image';
|
||||
let endpoint = '/taxonomy/' + taxonomyId + '/terms/?'+ qs.stringify({ hideempty: 0, include: selectedTerms.map((term) => { return term.id; }), fetch_preview_image_items: showTermThumbnail ? 0 : 3 }) + '&order=asc';
|
||||
tainacan.get(endpoint, { cancelToken: itemsRequestSource.token })
|
||||
.then(response => {
|
||||
|
||||
if (showTermThumbnail) {
|
||||
for (let term of response.data) {
|
||||
terms.push(prepareItem(term));
|
||||
}
|
||||
setAttributes({
|
||||
content: <div></div>,
|
||||
terms: terms,
|
||||
isLoading: false,
|
||||
itemsRequestSource: itemsRequestSource
|
||||
});
|
||||
} else {
|
||||
let promises = [];
|
||||
for (let term of response.data) {
|
||||
promises.push(
|
||||
tainacan.get('/items/?perpage=3&fetch_only=name,url,thumbnail&taxquery[0][taxonomy]=tnc_tax_' + taxonomyId + '&taxquery[0][terms][0]=' + term.id + '&taxquery[0][compare]=IN')
|
||||
.then(response => { return({ term: term, termItems: response.data.items }) })
|
||||
.catch((error) => console.log(error))
|
||||
);
|
||||
}
|
||||
axios.all(promises).then((results) => {
|
||||
for (let result of results) {
|
||||
terms.push(prepareItem(result.term, result.termItems));
|
||||
}
|
||||
setAttributes({
|
||||
content: <div></div>,
|
||||
terms: terms,
|
||||
isLoading: false,
|
||||
itemsRequestSource: itemsRequestSource
|
||||
});
|
||||
})
|
||||
}
|
||||
for (let term of response.data)
|
||||
terms.push(prepareItem(term, (!showTermThumbnail && term.preview_image_items) ? term.preview_image_items : []));
|
||||
|
||||
isLoading = false;
|
||||
setAttributes({
|
||||
content: <div></div>,
|
||||
terms: terms,
|
||||
isLoading: isLoading,
|
||||
itemsRequestSource: itemsRequestSource
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
:href="term.url">
|
||||
<div class="term-items-grid">
|
||||
<blur-hash-image
|
||||
:height="termItems[term.id][2] ? $thumbHelper.getHeight(termItems[term.id][0]['thumbnail'], 'tainacan-medium') : 275"
|
||||
:height="termItems[term.id][0] ? $thumbHelper.getHeight(termItems[term.id][0]['thumbnail'], 'tainacan-medium') : 275"
|
||||
:width="termItems[term.id][0] ? $thumbHelper.getWidth(termItems[term.id][0]['thumbnail'], 'tainacan-medium') : 275"
|
||||
:src="termItems[term.id][0] ? $thumbHelper.getSrc(termItems[term.id][0]['thumbnail'], 'tainacan-medium', termItems[term.id][0]['document_mimetype']) :`${tainacanBaseUrl}/assets/images/placeholder_square.png`"
|
||||
:srcset="termItems[term.id][0] ? $thumbHelper.getSrcSet(termItems[term.id][0]['thumbnail'], 'tainacan-medium', termItems[term.id][0]['document_mimetype']) :`${tainacanBaseUrl}/assets/images/placeholder_square.png`"
|
||||
|
@ -274,43 +274,26 @@ export default {
|
|||
|
||||
this.termsRequestSource = axios.CancelToken.source();
|
||||
|
||||
let endpoint = '/taxonomy/' + this.taxonomyId + '/terms/?'+ qs.stringify({ hideempty: 0, include: this.selectedTerms }) + '&order=asc&fetch_only=id,name,url,header_image';
|
||||
let endpoint = '/taxonomy/' + this.taxonomyId + '/terms/?'+ qs.stringify({ hideempty: 0, include: this.selectedTerms, fetch_preview_image_items: this.showTermThumbnail ? 0 : 3 }) + '&order=asc';
|
||||
|
||||
this.tainacanAxios.get(endpoint, { cancelToken: this.termsRequestSource.token })
|
||||
.then(response => {
|
||||
|
||||
if (this.showTermThumbnail) {
|
||||
for (let term of response.data)
|
||||
this.terms.push(term);
|
||||
|
||||
this.isLoading = false;
|
||||
} else {
|
||||
let promises = [];
|
||||
for (let term of response.data) {
|
||||
promises.push(
|
||||
this.tainacanAxios.get('/items/?perpage=3&fetch_only=name,url,thumbnail&taxquery[0][taxonomy]=tnc_tax_' + this.taxonomyId + '&taxquery[0][terms][0]=' + term.id + '&taxquery[0][compare]=IN')
|
||||
.then(response => { return({ termId: term.id, termItems: response.data.items }) })
|
||||
);
|
||||
this.terms.push(term);
|
||||
}
|
||||
axios.all(promises).then((results) => {
|
||||
for (let result of results) {
|
||||
this.termItems[result.termId] = result.termItems;
|
||||
}
|
||||
|
||||
this.isLoading = false;
|
||||
})
|
||||
for (let term of response.data) {
|
||||
this.terms.push(term);
|
||||
if (!this.showTermThumbnail)
|
||||
this.termItems[term.id] = term.preview_image_items ? term.preview_image_items : [];
|
||||
}
|
||||
|
||||
this.isLoading = false;
|
||||
this.totalTerms = response.headers['x-wp-total'];
|
||||
|
||||
}).catch((error) => {
|
||||
this.isLoading = false;
|
||||
if (error.response && error.response.status && error.response.status == 401)
|
||||
this.errorMessage = 'Not allowed to see these terms.'
|
||||
if (error.response && error.response.status && error.response.status == 401)
|
||||
this.errorMessage = 'Not allowed to see these terms.'
|
||||
|
||||
});
|
||||
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue