Skip to content

Commit 9d1a63a

Browse files
committed
Add resolving labels to enum select editor
1 parent 70acf75 commit 9d1a63a

File tree

1 file changed

+35
-9
lines changed

1 file changed

+35
-9
lines changed

src/components/ShaclForm/Editor/EnumSelectEditor.vue

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
class="input-field"
44
:value="toInputValue(value)"
55
@input="onInput"
6+
:key="resolvedCounter"
67
>
78
<option :value="null">
89
- select -
910
</option>
1011
<option
11-
v-for="option in createOptions()"
12-
:key="option.key"
13-
:value="option.key"
12+
v-for="key in keys"
13+
:key="key"
14+
:value="key"
1415
>
15-
{{ option.value }}
16+
{{ values[key] }}
1617
</option>
1718
</select>
1819
</template>
@@ -21,6 +22,8 @@ import * as $rdf from 'rdflib'
2122
import _ from 'lodash'
2223
import { Component, Prop, Vue } from 'vue-property-decorator'
2324
import rdfUtils from '@/rdf/utils'
25+
import api from '@/api'
26+
import { SHACL } from '@/rdf/namespaces'
2427
2528
@Component({})
2629
export default class EnumSelectEditor extends Vue {
@@ -30,11 +33,34 @@ export default class EnumSelectEditor extends Vue {
3033
@Prop({ required: true })
3134
readonly value: any
3235
33-
createOptions() {
34-
return _.get(this.field, 'in', []).map((val) => ({
35-
key: val,
36-
value: rdfUtils.pathTerm(val),
37-
}))
36+
keys : any
37+
38+
values : any
39+
40+
resolvedCounter : number = 0
41+
42+
created(): void {
43+
this.keys = []
44+
this.values = {}
45+
46+
_.get(this.field, 'in', []).forEach((key) => {
47+
this.keys.push(key)
48+
this.values[key] = rdfUtils.pathTerm(key)
49+
50+
if (this.field.nodeKind === SHACL('IRI').value) {
51+
this.resolveValue(key)
52+
}
53+
})
54+
}
55+
56+
async resolveValue(key: string): Promise<void> {
57+
try {
58+
const label = await api.label.getLabel(key)
59+
this.values[key] = label.data.label
60+
this.resolvedCounter += 1
61+
} catch {
62+
// nothing could be fetched, keep default label
63+
}
3864
}
3965
4066
onInput(e) {

0 commit comments

Comments
 (0)