Merge branch 'develop' into feature/compount-metadata-type-refactor

This commit is contained in:
vnmedeiros 2020-03-10 13:55:34 -03:00
commit 98215e86ff
9 changed files with 129 additions and 30 deletions

View File

@ -39,8 +39,9 @@
:is-using-elastic-search="isUsingElasticSearch"
:is-repository-level="isRepositoryLevel"
:is-loading-items.sync="isLoadingItems"
:current-collection-id="$eventBusSearch.collectionId"
@input="onInput"
@sendValuesToTags="onSendValuesToTags"/>
@sendValuesToTags="onSendValuesToTags" />
</div>
</b-collapse>
</b-field>

View File

@ -53,7 +53,11 @@
import { filterTypeMixin } from '../../../js/filter-types-mixin';
export default {
mixins: [ filterTypeMixin ],
mixins: [ filterTypeMixin ],
props: {
isRepositoryLevel: Boolean,
currentCollectionId: String
},
data(){
return {
isLoadingOptions: true,
@ -129,10 +133,14 @@
let route = '';
if (this.collectionId == 'default')
if (this.isRepositoryLevel)
route = `/facets/${this.metadatumId}?getSelected=1&order=asc&parent=0&number=${this.filter.max_options}&` + qs.stringify(query_items);
else
route = `/collection/${this.collectionId}/facets/${this.metadatumId}?getSelected=1&order=asc&parent=0&number=${this.filter.max_options}&` + qs.stringify(query_items);
else {
if (this.collectionId == 'default' && this.currentCollectionId)
route = `/collection/${this.currentCollectionId}/facets/${this.metadatumId}?getSelected=1&order=asc&parent=0&number=${this.filter.max_options}&` + qs.stringify(query_items);
else
route = `/collection/${this.collectionId}/facets/${this.metadatumId}?getSelected=1&order=asc&parent=0&number=${this.filter.max_options}&` + qs.stringify(query_items);
}
this.options = [];

View File

@ -112,7 +112,16 @@
'number': 12
};
let endpoint = this.isRepositoryLevel ? '/facets/' + this.metadatumId : '/collection/'+ this.collectionId +'/facets/' + this.metadatumId;
let endpoint = '';
if (this.isRepositoryLevel)
endpoint += '/facets/' + this.metadatumId;
else {
if (this.collectionId == 'default' && this.currentCollection)
endpoint += '/collection/' + this.currentCollectionId +'/facets/' + this.metadatumId;
else
endpoint += '/collection/' + this.collectionId +'/facets/' + this.metadatumId;
}
endpoint += '?order=asc&' + qs.stringify(query_items);

View File

@ -17,7 +17,8 @@ export const filterTypeMixin = {
query: Object,
isRepositoryLevel: Boolean,
isUsingElasticSearch: Boolean,
isLoadingItems: Boolean
isLoadingItems: Boolean,
currentCollectionId: Boolean
},
created() {
this.collectionId = this.filter.collection_id ? this.filter.collection_id : this.collectionId;
@ -67,11 +68,15 @@ export const dynamicFilterTypeMixin = {
let query_items = { 'current_query': currentQuery };
let url = '';
if (isRepositoryLevel || this.filter.collection_id == 'default')
if (isRepositoryLevel)
url = `/facets/${metadatumId}?getSelected=${getSelected}&`;
else
url = `/collection/${this.filter.collection_id}/facets/${metadatumId}?getSelected=${getSelected}&`;
else {
if (this.filter.collection_id == 'default' && this.currentCollectionId)
url = `/collection/${this.currentCollectionId}/facets/${metadatumId}?getSelected=${getSelected}&`;
else
url = `/collection/${this.filter.collection_id}/facets/${metadatumId}?getSelected=${getSelected}&`;
}
if (offset != undefined && number != undefined) {
if (!this.isUsingElasticSearch)
@ -145,12 +150,16 @@ export const dynamicFilterTypeMixin = {
let query_items = { 'current_query': currentQuery };
let url = '';
if (isRepositoryLevel || this.filter.collection_id == 'default')
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 (isRepositoryLevel)
url = `/facets/${this.filter.metadatum.metadatum_id}?getSelected=${getSelected}&`;
else {
if (this.filter.collection_id == 'default' && this.currentCollectionId)
url = `/collection/${this.currentCollectionId}/facets/${this.filter.metadatum.metadatum_id}?getSelected=${getSelected}&`;
else
url = `/collection/${this.filter.collection_id}/facets/${this.filter.metadatum.metadatum_id}?getSelected=${getSelected}&`;
}
if (offset != undefined && number != undefined)
url += `offset=${offset}&number=${number}`;
else
@ -314,7 +323,6 @@ export const dynamicFilterTypeMixin = {
}
}
}
console.log(this.shouldAddOptions)
if (this.shouldAddOptions === true && this.searchResults && this.searchResults.length)
this.searchResults = this.searchResults.concat(sResults);

View File

@ -215,7 +215,7 @@ registerBlockType('tainacan/carousel-collections-list', {
collections = [];
let endpoint = '/collections?'+ qs.stringify({ postin: selectedCollections, perpage: selectedCollections.length }) + '&fetch_only=name,url,thumbnail';
let endpoint = '/collections?'+ qs.stringify({ postin: selectedCollections.map((collection) => { return collection.id }), perpage: selectedCollections.length }) + '&fetch_only=name,url,thumbnail';
tainacan.get(endpoint, { cancelToken: itemsRequestSource.token })
.then(response => {
@ -266,7 +266,7 @@ registerBlockType('tainacan/carousel-collections-list', {
if (existingItemIndex >= 0)
collections.splice(existingItemIndex, 1);
let existingSelectedItemIndex = selectedCollections.findIndex((existingSelectedItem) => existingSelectedItem == itemId);
let existingSelectedItemIndex = selectedCollections.findIndex((existingSelectedItem) => existingSelectedItem.id == itemId);
if (existingSelectedItemIndex >= 0)
selectedCollections.splice(existingSelectedItemIndex, 1);
@ -405,9 +405,9 @@ registerBlockType('tainacan/carousel-collections-list', {
<CarouselCollectionsModal
selectedCollectionsObject={ selectedCollections }
onApplySelection={ (aSelectionOfCollections) => {
selectedCollections = selectedCollections.concat(aSelectionOfCollections.map((collection) => { return collection.id; }));
selectedCollections = aSelectionOfCollections;
setAttributes({
selectedCollections: selectedCollections,
selectedCollections: aSelectionOfCollections,
isModalOpen: false
});
setContent();
@ -535,7 +535,7 @@ registerBlockType('tainacan/carousel-collections-list', {
} = attributes;
return <div
className={ className }
selected-collections={ JSON.stringify(selectedCollections) }
selected-collections={ JSON.stringify(selectedCollections.map((collection) => { return collection.id })) }
arrows-position={ arrowsPosition }
auto-play={ '' + autoPlay }
auto-play-speed={ autoPlaySpeed }
@ -548,5 +548,38 @@ registerBlockType('tainacan/carousel-collections-list', {
id={ 'wp-block-tainacan-carousel-collections-list_' + blockId }>
{ content }
</div>
}
},
deprecated: [
{
save({ attributes, className }){
const {
content,
blockId,
selectedCollections,
arrowsPosition,
maxCollectionsNumber,
autoPlay,
autoPlaySpeed,
loopSlides,
hideName,
showCollectionThumbnail
} = attributes;
return <div
className={ className }
selected-collections={ JSON.stringify(selectedCollections) }
arrows-position={ arrowsPosition }
auto-play={ '' + autoPlay }
auto-play-speed={ autoPlaySpeed }
loop-slides={ '' + loopSlides }
hide-name={ '' + hideName }
max-collections-number={ maxCollectionsNumber }
tainacan-api-root={ tainacan_blocks.root }
tainacan-base-url={ tainacan_blocks.base_url }
show-collection-thumbnail={ '' + showCollectionThumbnail }
id={ 'wp-block-tainacan-carousel-collections-list_' + blockId }>
{ content }
</div>
}
}
]
});

View File

@ -207,6 +207,7 @@ export default class CarouselItemsModal extends React.Component {
className="wp-block-tainacan-modal dynamic-modal"
title={ this.props.loadStrategy == 'selection' ? __('Select items to add on block', 'tainacan') : __('Configure the items search to be used on block', 'tainacan')}
onRequestClose={ () => this.cancelSelection() }
shouldCloseOnClickOutside={ false }
contentLabel={ this.props.loadStrategy == 'selection' ? __('Select items that will be added on block', 'tainacan') : __('Configure your items search that will load items on block', 'tainacan')}>
<iframe
id="itemsFrame"
@ -242,6 +243,7 @@ export default class CarouselItemsModal extends React.Component {
className="wp-block-tainacan-modal"
title={__('Select a collection to fetch items from', 'tainacan')}
onRequestClose={ () => this.cancelSelection() }
shouldCloseOnClickOutside={ false }
contentLabel={__('Select items', 'tainacan')}>
<div>
<div className="modal-search-area">

View File

@ -171,6 +171,7 @@ export default class DynamicItemsModal extends React.Component {
className="wp-block-tainacan-modal dynamic-modal"
title={__('Configure the items search to be used on block', 'tainacan')}
onRequestClose={ () => this.cancelSelection() }
shouldCloseOnClickOutside={ false }
contentLabel={__('Configure your items search to be shown on block', 'tainacan')}>
<iframe
id="itemsFrame"
@ -194,6 +195,7 @@ export default class DynamicItemsModal extends React.Component {
className="wp-block-tainacan-modal"
title={__('Select a collection to fetch items from', 'tainacan')}
onRequestClose={ () => this.cancelSelection() }
shouldCloseOnClickOutside={ false }
contentLabel={__('Select items', 'tainacan')}>
<div>
<div className="modal-search-area">

View File

@ -210,7 +210,7 @@ registerBlockType('tainacan/carousel-terms-list', {
terms = [];
let endpoint = '/taxonomy/' + taxonomyId + '/terms/?'+ qs.stringify({ hideempty: 0, include: selectedTerms }) + '&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; }) }) + '&order=asc&fetch_only=id,name,url,header_image';
tainacan.get(endpoint, { cancelToken: itemsRequestSource.token })
.then(response => {
@ -261,7 +261,7 @@ registerBlockType('tainacan/carousel-terms-list', {
if (existingItemIndex >= 0)
terms.splice(existingItemIndex, 1);
let existingSelectedItemIndex = selectedTerms.findIndex((existingSelectedItem) => existingSelectedItem == itemId);
let existingSelectedItemIndex = selectedTerms.findIndex((existingSelectedItem) => existingSelectedItem.id == itemId);
if (existingSelectedItemIndex >= 0)
selectedTerms.splice(existingSelectedItemIndex, 1);
@ -406,7 +406,8 @@ registerBlockType('tainacan/carousel-terms-list', {
setAttributes({ taxonomyId: taxonomyId });
}}
onApplySelection={ (aSelectionOfTerms) =>{
selectedTerms = selectedTerms.concat(aSelectionOfTerms.map((term) => { return term.id; }));
selectedTerms = aSelectionOfTerms;
setAttributes({
selectedTerms: selectedTerms,
isModalOpen: false
@ -537,7 +538,7 @@ registerBlockType('tainacan/carousel-terms-list', {
} = attributes;
return <div
className={ className }
selected-terms={ JSON.stringify(selectedTerms) }
selected-terms={ JSON.stringify(selectedTerms.map((term) => { return term.id; })) }
arrows-position={ arrowsPosition }
auto-play={ '' + autoPlay }
auto-play-speed={ autoPlaySpeed }
@ -551,5 +552,40 @@ registerBlockType('tainacan/carousel-terms-list', {
id={ 'wp-block-tainacan-carousel-terms-list_' + blockId }>
{ content }
</div>
}
},
deprecated: [
{
save({ attributes, className }){
const {
content,
blockId,
selectedTerms,
arrowsPosition,
maxTermsNumber,
autoPlay,
autoPlaySpeed,
loopSlides,
hideName,
showTermThumbnail,
taxonomyId
} = attributes;
return <div
className={ className }
selected-terms={ JSON.stringify(selectedTerms) }
arrows-position={ arrowsPosition }
auto-play={ '' + autoPlay }
auto-play-speed={ autoPlaySpeed }
loop-slides={ '' + loopSlides }
hide-name={ '' + hideName }
max-terms-number={ maxTermsNumber }
taxonomy-id={ taxonomyId }
tainacan-api-root={ tainacan_blocks.root }
tainacan-base-url={ tainacan_blocks.base_url }
show-term-thumbnail={ '' + showTermThumbnail }
id={ 'wp-block-tainacan-carousel-terms-list_' + blockId }>
{ content }
</div>
}
}
]
});

View File

@ -51,7 +51,7 @@ export default class TermsModal extends React.Component {
taxonomyId: this.props.existingTaxonomyId,
temporarySelectedTerms: JSON.parse(JSON.stringify(this.props.selectedTermsObject))
});
if (this.props.existingTaxonomyId != null && this.props.existingTaxonomyId != undefined) {
this.fetchTaxonomy(this.props.existingTaxonomyId);
this.fetchModalTerms(0, this.props.existingTaxonomyId);