Updates to filters getting information from metadat_type_object.

This commit is contained in:
Mateus Machado Luna 2019-10-16 11:23:56 -03:00
parent ef8ceeffce
commit 6531b3cdf7
4 changed files with 56 additions and 31 deletions

View File

@ -49,7 +49,8 @@
return { return {
selected:'', selected:'',
options: [], options: [],
label: '' label: '',
relatedCollectionId: ''
} }
}, },
watch: { watch: {
@ -57,6 +58,15 @@
this.updateSelectedValues(); this.updateSelectedValues();
}, },
}, },
created() {
if (this.metadatumType === 'Tainacan\\Metadata_Types\\Relationship' &&
this.filter.metadatum &&
this.filter.metadatum.metadata_type_object &&
this.filter.metadatum.metadata_type_object.options &&
this.filter.metadatum.metadata_type_object.options.collection_id) {
this.relatedCollectionId = this.filter.metadatum.metadata_type_object.options.collection_id;
}
},
mounted() { mounted() {
this.updateSelectedValues(); this.updateSelectedValues();
}, },
@ -122,7 +132,12 @@
if (this.metadatumType === 'Tainacan\\Metadata_Types\\Relationship') { if (this.metadatumType === 'Tainacan\\Metadata_Types\\Relationship') {
axios.get('/items/' + metadata.value + '?fetch_only=title,thumbnail') let endpoint = '/items/' + metadata.value + '?fetch_only=title,thumbnail';
if (this.relatedCollectionId != '')
endpoint = '/collection/' + this.relatedCollectionId + endpoint;
axios.get(endpoint)
.then( res => { .then( res => {
let item = res.data; let item = res.data;
this.label = item.title; this.label = item.title;

View File

@ -54,7 +54,8 @@
return { return {
results:'', results:'',
selected:[], selected:[],
options: [] options: [],
relatedCollectionId: ''
} }
}, },
watch: { watch: {
@ -62,6 +63,15 @@
this.updateSelectedValues(); this.updateSelectedValues();
} }
}, },
created() {
if (this.metadatumType === 'Tainacan\\Metadata_Types\\Relationship' &&
this.filter.metadatum &&
this.filter.metadatum.metadata_type_object &&
this.filter.metadatum.metadata_type_object.options &&
this.filter.metadatum.metadata_type_object.options.collection_id) {
this.relatedCollectionId = this.filter.metadatum.metadata_type_object.options.collection_id;
}
},
mounted() { mounted() {
this.updateSelectedValues(); this.updateSelectedValues();
}, },
@ -106,8 +116,12 @@
if ( this.metadatumType === 'Tainacan\\Metadata_Types\\Relationship' ) { if ( this.metadatumType === 'Tainacan\\Metadata_Types\\Relationship' ) {
let query = qs.stringify({ postin: metadata.value, fetch_only: 'title,thumbnail', fetch_only_meta: '' }); let query = qs.stringify({ postin: metadata.value, fetch_only: 'title,thumbnail', fetch_only_meta: '' });
let endpoint = '/items/' + metadata.value;
axios.get('/items?' + query)
if (this.relatedCollectionId != '')
endpoint = '/collection/' + this.relatedCollectionId + endpoint;
axios.get(endpoint + query)
.then( res => { .then( res => {
if (res.data.items) { if (res.data.items) {
this.selected = []; this.selected = [];

View File

@ -60,7 +60,7 @@
options: [], options: [],
selected: [], selected: [],
taxonomy: '', taxonomy: '',
taxonomy_id: Number taxonomyId: ''
} }
}, },
watch: { watch: {
@ -80,6 +80,16 @@
this.loadOptions(); this.loadOptions();
} }
}, },
created() {
if (this.metadatumType === 'Tainacan\\Metadata_Types\\Relationship' &&
this.filter.metadatum &&
this.filter.metadatum.metadata_type_object &&
this.filter.metadatum.metadata_type_object.options &&
this.filter.metadatum.metadata_type_object.options.taxonomy_id) {
this.taxonomyId = this.filter.metadatum.metadata_type_object.options.taxonomy_id;
this.taxonomy = 'tnc_tax_' + this.taxonomyId;
}
},
mounted(){ mounted(){
this.loadOptions(); this.loadOptions();
}, },
@ -239,7 +249,7 @@
props: { props: {
parent: parent, parent: parent,
filter: this.filter, filter: this.filter,
taxonomy_id: this.taxonomy_id, taxonomy_id: this.taxonomyId,
selected: this.selected, selected: this.selected,
metadatumId: this.metadatumId, metadatumId: this.metadatumId,
taxonomy: this.taxonomy, taxonomy: this.taxonomy,
@ -258,11 +268,6 @@
}, },
prepareOptionsForTaxonomy(items) { prepareOptionsForTaxonomy(items) {
if (items[0] != undefined) {
this.taxonomy = items[0].taxonomy;
this.taxonomy_id = items[0].taxonomy_id;
}
this.options = []; this.options = [];
this.options = items.slice(); // copy array. this.options = items.slice(); // copy array.

View File

@ -43,24 +43,19 @@
export default { export default {
mixins: [ filterTypeMixin, dynamicFilterTypeMixin ], mixins: [ filterTypeMixin, dynamicFilterTypeMixin ],
created(){ created() {
let endpoint = '/collection/' + this.collectionId + '/metadata/' + this.metadatumId; if (this.metadatumType === 'Tainacan\\Metadata_Types\\Relationship' &&
this.filter.metadatum &&
if (this.isRepositoryLevel || this.collectionId == 'default'){ this.filter.metadatum.metadata_type_object &&
endpoint = '/metadata/' + this.metadatumId; this.filter.metadatum.metadata_type_object.options &&
} this.filter.metadatum.metadata_type_object.options.taxonomy_id) {
this.taxonomyId = this.filter.metadatum.metadata_type_object.options.taxonomy_id;
axios.get(endpoint) this.taxonomy = 'tnc_tax_' + this.taxonomyId;
.then( res => { }
let metadatum = res.data;
this.taxonomyId = metadatum.metadata_type_options.taxonomy_id
this.updateSelectedValues();
});
}, },
watch: { watch: {
'query.taxquery'() { 'query.taxquery'() {
if (this.taxonomyId != '') this.updateSelectedValues();
this.updateSelectedValues();
} }
}, },
data(){ data(){
@ -92,8 +87,6 @@
return axios.get(endpoint).then( res => { return axios.get(endpoint).then( res => {
for (let term of res.data.values) { for (let term of res.data.values) {
this.taxonomy = term.taxonomy;
if (valuesToIgnore != undefined && valuesToIgnore.length > 0) { if (valuesToIgnore != undefined && valuesToIgnore.length > 0) {
let indexToIgnore = valuesToIgnore.findIndex(value => value == term.value); let indexToIgnore = valuesToIgnore.findIndex(value => value == term.value);
@ -127,8 +120,6 @@
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;
this.taxonomy = 'tnc_tax_' + this.taxonomyId;
let index = this.query.taxquery.findIndex(newMetadatum => newMetadatum.taxonomy == this.taxonomy); let index = this.query.taxquery.findIndex(newMetadatum => newMetadatum.taxonomy == this.taxonomy);
if ( index >= 0){ if ( index >= 0){