Fixes Taxonomy TagInput not loading selected terms from URL.

This commit is contained in:
Mateus Machado Luna 2018-07-05 14:35:06 -03:00
parent 6fc2f9f2b3
commit 9fc3da4c6c
3 changed files with 27 additions and 34 deletions

View File

@ -9,7 +9,6 @@
expanded expanded
:clear-on-select="true" :clear-on-select="true"
@input="search" @input="search"
:loading="isLoading"
field="label" field="label"
@select="option => setResults(option) " @select="option => setResults(option) "
:placeholder="$i18n.get('info_type_to_search')"> :placeholder="$i18n.get('info_type_to_search')">
@ -72,7 +71,6 @@
results:'', results:'',
selected:'', selected:'',
options: [], options: [],
isLoading: false,
type: '', type: '',
collection: '', collection: '',
metadatum: '', metadatum: '',
@ -102,27 +100,22 @@
this.selectedValues(); this.selectedValues();
}, },
search( query ){ search( query ){
if (query == '') {
this.cleanSearch(); let promise = null;
this.options = [];
if ( this.type === 'Tainacan\\Metadata_Types\\Relationship' ) {
let collectionTarget = ( this.metadatum_object && this.metadatum_object.metadata_type_options.collection_id ) ?
this.metadatum_object.metadata_type_options.collection_id : this.collection_id;
promise = this.getValuesRelationship( collectionTarget, query );
} else { } else {
let promise = null; promise = this.getValuesPlainText( this.metadatum, query, this.isRepositoryLevel );
this.options = [];
if ( this.type === 'Tainacan\\Metadata_Types\\Relationship' ) {
let collectionTarget = ( this.metadatum_object && this.metadatum_object.metadata_type_options.collection_id ) ?
this.metadatum_object.metadata_type_options.collection_id : this.collection_id;
promise = this.getValuesRelationship( collectionTarget, query );
} else {
promise = this.getValuesPlainText( this.metadatum, query, this.isRepositoryLevel );
}
promise.then( () => {
this.isLoading = false;
}).catch( error => {
this.$console.log('error select', error );
this.isLoading = false;
});
} }
promise.catch( error => {
this.$console.log('error select', error );
});
}, },
selectedValues(){ selectedValues(){
const instance = this; const instance = this;

View File

@ -81,7 +81,6 @@
results:'', results:'',
selected:[], selected:[],
options: [], options: [],
isLoading: false,
type: '', type: '',
collection: '', collection: '',
metadatum: '', metadatum: '',
@ -130,12 +129,10 @@
} else { } else {
promise = this.getValuesPlainText( this.metadatum, query, this.isRepositoryLevel ); promise = this.getValuesPlainText( this.metadatum, query, this.isRepositoryLevel );
} }
this.isLoading = true;
promise.then(() => { promise
this.isLoading = false; .catch( error => {
}).catch( error => {
this.$console.log('error select', error ); this.$console.log('error select', error );
this.isLoading = false;
}); });
}, },
selectedValues(){ selectedValues(){
@ -143,7 +140,7 @@
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) ) if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
return false; return false;
let index = this.query.metaquery.findIndex(newMetadatum => newMetadatum.key === this.metadatum ); let index = this.query.metaquery.findIndex(newMetadatum => newMetadatum.key == this.metadatum );
if ( index >= 0){ if ( index >= 0){
let metadata = this.query.metaquery[ index ]; let metadata = this.query.metaquery[ index ];
let collectionTarget = ( this.metadatum_object && this.metadatum_object.metadata_type_options.collection_id ) ? let collectionTarget = ( this.metadatum_object && this.metadatum_object.metadata_type_options.collection_id ) ?

View File

@ -2,14 +2,16 @@
<div class="block"> <div class="block">
<b-taginput <b-taginput
size="is-small" size="is-small"
icon="magnify"
v-model="selected" v-model="selected"
:data="options" :data="options"
:loading="isLoading"
autocomplete autocomplete
expanded
field="label" field="label"
attached attached
:class="{'has-selected': selected != undefined && selected != []}" :class="{'has-selected': selected != undefined && selected != []}"
@typing="search" /> @typing="search"
:placeholder="$i18n.get('info_type_to_search')" />
</div> </div>
</template> </template>
@ -160,7 +162,7 @@
if ( !this.query || !this.query.taxquery || !Array.isArray( this.query.taxquery ) ) if ( !this.query || !this.query.taxquery || !Array.isArray( this.query.taxquery ) )
return false; return false;
let index = this.query.taxquery.findIndex(newMetadatum => newMetadatum.taxonomy === this.taxonomy ); let index = this.query.taxquery.findIndex(newMetadatum => newMetadatum.taxonomy == 'tnc_tax_' + taxonomy );
if ( index >= 0){ if ( index >= 0){
let metadata = this.query.taxquery[ index ]; let metadata = this.query.taxquery[ index ];
for ( let id of metadata.terms ){ for ( let id of metadata.terms ){
@ -171,8 +173,9 @@
} }
}, },
getTerm( taxonomy, id ){ getTerm( taxonomy, id ){
return axios.get('/taxonomy/' + taxonomy + '/terms/' + id + '?order=asc&hideempty=0' ).then( res => { return axios.get('/taxonomy/' + taxonomy + '/terms/' + id + '?order=asc&hideempty=0' )
this.$console.log(res); .then( res => {
this.selected.push({ label: res.data.name, value: res.data.id })
}) })
.catch(error => { .catch(error => {
this.$console.log(error); this.$console.log(error);