From 7625096659e2aea0dab080653cd6f8123f495adf Mon Sep 17 00:00:00 2001 From: Jan Slifka Date: Mon, 4 Sep 2023 11:17:52 +0200 Subject: [PATCH] Add resolving labels to enum select editor --- .../ShaclForm/Editor/EnumSelectEditor.vue | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/src/components/ShaclForm/Editor/EnumSelectEditor.vue b/src/components/ShaclForm/Editor/EnumSelectEditor.vue index 1d2c03f..9c3ba04 100644 --- a/src/components/ShaclForm/Editor/EnumSelectEditor.vue +++ b/src/components/ShaclForm/Editor/EnumSelectEditor.vue @@ -8,11 +8,11 @@ - select - @@ -21,6 +21,8 @@ import * as $rdf from 'rdflib' import _ from 'lodash' import { Component, Prop, Vue } from 'vue-property-decorator' import rdfUtils from '@/rdf/utils' +import api from '@/api' +import { SHACL } from '@/rdf/namespaces' @Component({}) export default class EnumSelectEditor extends Vue { @@ -30,11 +32,30 @@ export default class EnumSelectEditor extends Vue { @Prop({ required: true }) readonly value: any - createOptions() { - return _.get(this.field, 'in', []).map((val) => ({ - key: val, - value: rdfUtils.pathTerm(val), - })) + keys : any + + values : any + + created(): void { + this.keys = [] + this.values = {} + + _.get(this.field, 'in', []).forEach((key) => { + this.keys.push(key) + this.values[key] = rdfUtils.pathTerm(key) + + if (this.field.nodeKind === SHACL('IRI').value) { + this.resolveValue(key) + } + }) + } + + async resolveValue(key: string): Promise { + try { + this.values[key] = await api.label.getLabel(key) + } catch { + // nothing could be fetched, keep default label + } } onInput(e) {