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
:clear-on-select="true"
@input="search"
:loading="isLoading"
field="label"
@select="option => setResults(option) "
:placeholder="$i18n.get('info_type_to_search')">
@ -72,7 +71,6 @@
results:'',
selected:'',
options: [],
isLoading: false,
type: '',
collection: '',
metadatum: '',
@ -102,27 +100,22 @@
this.selectedValues();
},
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 {
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 {
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 = this.getValuesPlainText( this.metadatum, query, this.isRepositoryLevel );
}
promise.catch( error => {
this.$console.log('error select', error );
});
},
selectedValues(){
const instance = this;
@ -138,7 +131,7 @@
if ( this.type === 'Tainacan\\Metadata_Types\\Relationship' ) {
// let query = qs.stringify({ postin: metadata.value });
axios.get('/items/' + metadata.value)
.then( res => {

View File

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

View File

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