Prevents TagInput filters to list results that are already selected as filters.

This commit is contained in:
Mateus Machado Luna 2018-07-05 17:49:37 -03:00
parent f6a1b9204a
commit b6e80a3500
3 changed files with 63 additions and 14 deletions

View File

@ -17,7 +17,7 @@ export const filter_type_mixin = {
query: {}
},
methods: {
getValuesPlainText(metadatumId, search, isRepositoryLevel) {
getValuesPlainText(metadatumId, search, isRepositoryLevel, valuesToIgnore) {
let url = '/collection/' + this.collection + '/metadata/' + metadatumId + '?fetch=all_metadatum_values&nopaging=1';
@ -35,7 +35,13 @@ export const filter_type_mixin = {
for (let metadata of res.data[0]) {
let index = this.options.findIndex(itemMetadata => itemMetadata.value === metadata.mvalue);
if (index < 0 && metadata.mvalue !== '') {
this.options.push({label: metadata.mvalue, value: metadata.mvalue})
if (valuesToIgnore != undefined && valuesToIgnore.length > 0) {
let indexToIgnore = valuesToIgnore.findIndex(value => value == metadata.mvalue);
if (indexToIgnore < 0)
this.options.push({ label: metadata.mvalue, value: metadata.mvalue })
} else {
this.options.push({ label: metadata.mvalue, value: metadata.mvalue })
}
}
}
@ -45,7 +51,7 @@ export const filter_type_mixin = {
this.$console.error(error);
});
},
getValuesRelationship(collectionTarget, search) {
getValuesRelationship(collectionTarget, search, valuesToIgnore) {
let url = '/collection/' + collectionTarget + '/items?';
if( search ){
@ -56,7 +62,13 @@ export const filter_type_mixin = {
.then(res => {
if (res.data.length > 0) {
for (let item of res.data) {
this.options.push({label: item.title, value: item.id, img: ( item.thumbnail.thumb ? item.thumbnail.thumb : this.thumbPlaceholderPath ) });
if (valuesToIgnore != undefined && valuesToIgnore.length > 0) {
let indexToIgnore = valuesToIgnore.findIndex(value => value == item.id);
if (indexToIgnore < 0)
this.options.push({ label: item.title, value: item.id, img: (item.thumbnail.thumb ? item.thumbnail.thumb : this.thumbPlaceholderPath) });
} else {
this.options.push({ label: item.title, value: item.id, img: (item.thumbnail.thumb ? item.thumbnail.thumb : this.thumbPlaceholderPath) });
}
}
}
})

View File

@ -7,10 +7,26 @@
:data="options"
autocomplete
expanded
:remove-on-keys="[]"
field="label"
attached
@typing="search"
:placeholder="(type == 'Tainacan\\Metadata_Types\\Relationship') ? $i18n.get('info_type_to_add_items') : $i18n.get('info_type_to_add_metadata')"/>
:placeholder="(type == 'Tainacan\\Metadata_Types\\Relationship') ? $i18n.get('info_type_to_add_items') : $i18n.get('info_type_to_add_metadata')">
<template slot-scope="props">
<div class="media">
<div
class="media-left"
v-if="props.option.img">
<img
width="24"
:src="`${props.option.img}`">
</div>
<div class="media-content">
{{ props.option.label }}
</div>
</div>
</template>
</b-taginput>
</div>
</template>
@ -121,13 +137,18 @@
search( query ){
let promise = null;
this.options = [];
let valuesToIgnore = [];
for(let val of this.selected)
valuesToIgnore.push( val.value );
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 );
promise = this.getValuesRelationship( collectionTarget, query, valuesToIgnore );
} else {
promise = this.getValuesPlainText( this.metadatum, query, this.isRepositoryLevel );
promise = this.getValuesPlainText( this.metadatum, query, this.isRepositoryLevel, valuesToIgnore );
}
promise
@ -153,7 +174,7 @@
axios.get('/collection/' + collectionTarget + '/items?' + query)
.then( res => {
for (let item of res.data) {
instance.selected.push({ label: item.title, value: item.id, img: '' });
instance.selected.push({ label: item.title, value: item.id, img: item.thumbnail.thumb });
}
})
.catch(error => {

View File

@ -7,6 +7,7 @@
:data="options"
autocomplete
expanded
:remove-on-keys="[]"
field="label"
attached
:class="{'has-selected': selected != undefined && selected != []}"
@ -125,7 +126,8 @@
search( query ){
let promise = null;
this.options = [];
const q = query;
const q = query;
const endpoint = this.isRepositoryLevel ? '/metadata/' + this.metadatum : '/collection/'+ this.collection +'/metadata/' + this.metadatum;
axios.get(endpoint)
@ -146,12 +148,26 @@
});
},
getValuesTaxonomy( taxonomy, query ){
let valuesToIgnore = [];
for(let val of this.selected)
valuesToIgnore.push( val.value );
return axios.get('/taxonomy/' + taxonomy + '/terms?hideempty=0&order=asc' ).then( res => {
for (let term of res.data) {
if( term.name.toLowerCase().indexOf( query.toLowerCase() ) >= 0 ){
this.taxonomy = term.taxonomy;
this.options.push({label: term.name, value: term.id});
}
for (let term of res.data) {
if (valuesToIgnore != undefined && valuesToIgnore.length > 0) {
let indexToIgnore = valuesToIgnore.findIndex(value => value == term.id);
if (indexToIgnore < 0) {
if( term.name.toLowerCase().indexOf( query.toLowerCase() ) >= 0 ){
this.taxonomy = term.taxonomy;
this.options.push({label: term.name, value: term.id});
}
}
} else {
if( term.name.toLowerCase().indexOf( query.toLowerCase() ) >= 0 ){
this.taxonomy = term.taxonomy;
this.options.push({label: term.name, value: term.id});
}
}
}
})
.catch(error => {