From 670ef88d0ea46e72ef44ed7a886845d6fc2c256e Mon Sep 17 00:00:00 2001 From: jyhein <124268211+jyhein@users.noreply.github.com> Date: Thu, 30 Jan 2025 10:48:29 +0200 Subject: [PATCH 1/3] Controlled vocabulary support --- src/components/Form/fields/Autosuggest.vue | 26 ++++++++++++- .../Form/fields/FieldControlledVocab.vue | 39 +++++++++++-------- 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/src/components/Form/fields/Autosuggest.vue b/src/components/Form/fields/Autosuggest.vue index baae16518..1ffa81db8 100644 --- a/src/components/Form/fields/Autosuggest.vue +++ b/src/components/Form/fields/Autosuggest.vue @@ -95,7 +95,25 @@ name="option" :suggestion="suggestion" /> - {{ suggestion.label }} + @@ -302,6 +320,12 @@ defineExpose({handleFocus}); background: @primary; transition: width 0.3s; } + + & ul li { + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } } .autosuggest__results-item--highlighted { diff --git a/src/components/Form/fields/FieldControlledVocab.vue b/src/components/Form/fields/FieldControlledVocab.vue index e213f6a3e..d46e79cbe 100644 --- a/src/components/Form/fields/FieldControlledVocab.vue +++ b/src/components/Form/fields/FieldControlledVocab.vue @@ -2,6 +2,17 @@ import FieldBaseAutosuggest from './FieldBaseAutosuggest.vue'; import debounce from 'debounce'; +function setSuggestion(value) { + const {name, label = null, identifier = null, ...extraItems} = value; + const suggestion = { + value: value, + label: label ?? name, + identifier: identifier, + ...(extraItems ? {extraItems: extraItems} : {}), + }; + return suggestion; +} + export default { name: 'FieldControlledVocab', extends: FieldBaseAutosuggest, @@ -15,7 +26,6 @@ export default { data() { return { allSuggestions: [], - suggestionsLoaded: false, suggestionsLoading: false, }; }, @@ -31,40 +41,35 @@ export default { if (this.suggestionsLoading) { return; } - if (!this.suggestionsLoaded) { - this.loadSuggestions(this.setSuggestions); - } + this.loadSuggestions(this.setSuggestions); this.setSuggestions(); }, /** * Load suggestions from the API */ - loadSuggestions(successCallback) { + loadSuggestions: debounce(function (successCallback) { this.suggestionsLoading = true; $.ajax({ url: this.apiUrl, type: 'GET', context: this, - data: this.isMultilingual ? {locale: this.localeKey} : {}, + data: { + term: this.inputValue ?? null, + ...(this.isMultilingual ? {locale: this.localeKey} : {}), + }, error(r) { this.ajaxErrorCallback(r); }, success(r) { - this.allSuggestions = r.map((v) => { - return { - value: v, - label: v, - }; - }); - this.suggestionsLoaded = true; + this.allSuggestions = r.map((v) => setSuggestion(v)); this.suggestionsLoading = false; if (successCallback) { successCallback.apply(this); } }, }); - }, + }, 250), /** * Override the parent method to accept any typed @@ -77,7 +82,7 @@ export default { this.select(suggestion); } else if (this.inputValue) { this.select({ - value: this.inputValue, + value: {name: this.inputValue}, label: this.inputValue, }); } @@ -99,8 +104,8 @@ export default { this.suggestions = this.allSuggestions.filter( (suggestion) => !this.inputValue || - (this.inputValue !== suggestion.value && - suggestion.value.match(regex)), + (this.inputValue !== suggestion.value.name && + suggestion.value.name.match(regex)), ); }, 250), }, From 47d23783081ba7fa1416afe145ed2f6f9a2e1717 Mon Sep 17 00:00:00 2001 From: jyhein <124268211+jyhein@users.noreply.github.com> Date: Fri, 31 Jan 2025 15:43:20 +0200 Subject: [PATCH 2/3] Controlled vocabulary support --- .../publication/WorkflowPublicationForm.vue | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/pages/workflow/components/publication/WorkflowPublicationForm.vue b/src/pages/workflow/components/publication/WorkflowPublicationForm.vue index b90c1db0b..3710a36f9 100644 --- a/src/pages/workflow/components/publication/WorkflowPublicationForm.vue +++ b/src/pages/workflow/components/publication/WorkflowPublicationForm.vue @@ -55,7 +55,16 @@ const displayNoFieldsEnabled = computed(() => { return false; }); -const {triggerDataChange} = useDataChanged(); +const customFns = { + metadata: metadataDataChange, +}; + +const {triggerDataChange} = useDataChanged(customFns[props.formName]); const {set, form} = useForm(publicationForm); + +async function metadataDataChange() { + // Some metadata fields need extra data from db not in publication object + fetchForm(); +} From e06e70020ca0001da586001afb7eb3ee4e5f3e19 Mon Sep 17 00:00:00 2001 From: jyhein <124268211+jyhein@users.noreply.github.com> Date: Tue, 4 Feb 2025 12:11:07 +0200 Subject: [PATCH 3/3] Controlled vocabulary support --- src/components/Form/fields/Autosuggest.vue | 15 ++++++++++----- .../publication/WorkflowPublicationForm.vue | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/components/Form/fields/Autosuggest.vue b/src/components/Form/fields/Autosuggest.vue index 1ffa81db8..6db329db1 100644 --- a/src/components/Form/fields/Autosuggest.vue +++ b/src/components/Form/fields/Autosuggest.vue @@ -99,13 +99,18 @@
  • {{ suggestion.label }}
  • -
  • - +
  • + {{ suggestion.identifier }} -
  • -
  • - {{ suggestion.identifier }} +