From e532c10852ec2e2402653b55e558dc98161c2703 Mon Sep 17 00:00:00 2001 From: Leo Germani Date: Tue, 8 Oct 2019 15:11:58 -0300 Subject: [PATCH] relationship: return the selected metadata for search as label #311 --- .../relationship/Relationship.vue | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/classes/metadata-types/relationship/Relationship.vue b/src/classes/metadata-types/relationship/Relationship.vue index 37e3a3dd5..b36e5262d 100644 --- a/src/classes/metadata-types/relationship/Relationship.vue +++ b/src/classes/metadata-types/relationship/Relationship.vue @@ -26,11 +26,12 @@ let collectionId = ( this.metadatum && this.metadatum.metadatum.metadata_type_options.collection_id ) ? this.metadatum.metadatum.metadata_type_options.collection_id : this.collection_id; if ( this.metadatum.value && (Array.isArray( this.metadatum.value ) ? this.metadatum.value.length > 0 : true )){ let query = qs.stringify({ postin: ( Array.isArray( this.metadatum.value ) ) ? this.metadatum.value : [ this.metadatum.value ] }); + query += this.metadatum.metadatum.metadata_type_options.search ? '&fetch_only_meta=' + this.metadatum.metadatum.metadata_type_options.search : ''; axios.get('/collection/'+collectionId+'/items?' + query + '&nopaging=1&fetch_only=title,thumbnail') .then( res => { if (res.data.items) { for (let item of res.data.items) { - this.selected.push({ label: item.title, value: item.id, img: item.thumbnail && item.thumbnail['tainacan-small'] && item.thumbnail['tainacan-small'][0] ? item.thumbnail['tainacan-small'][0] : '' }); + this.selected.push({ label: this.getItemLabel(item), value: item.id, img: item.thumbnail && item.thumbnail['tainacan-small'] && item.thumbnail['tainacan-small'][0] ? item.thumbnail['tainacan-small'][0] : '' }); } } }) @@ -104,7 +105,7 @@ if (result.items) { for (let item of result.items) { - this.options.push({ label: item.title, value: item.id }) + this.options.push({ label: this.getItemLabel(item), value: item.id }) } } }) @@ -115,6 +116,20 @@ this.options = []; } }, 500), + getItemLabel(item) { + let label = ''; + for (let m in item.metadata) { + if (item.metadata[m].id == this.metadatum.metadatum.metadata_type_options.search) { + label = item.metadata[m].value_as_string; + } + } + if (label != '' && label != item.title && item.title != '') { + label += ' (' + item.title + ')'; + } else if (label == '') { + label = item.title; + } + return label; + }, mountQuery( search ) { let query = []; @@ -133,6 +148,7 @@ query['search'] = search; } query['fetch_only'] = 'title,thumbnail'; + query['fetch_only_meta'] = this.metadatum.metadatum.metadata_type_options.search; return query; }