Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 35 additions & 9 deletions src/components/ShaclForm/Editor/EnumSelectEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
class="input-field"
:value="toInputValue(value)"
@input="onInput"
:key="resolvedCounter"
>
<option :value="null">
- select -
</option>
<option
v-for="option in createOptions()"
:key="option.key"
:value="option.key"
v-for="key in keys"
:key="key"
:value="key"
>
{{ option.value }}
{{ values[key] }}
</option>
</select>
</template>
Expand All @@ -21,6 +22,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 {
Expand All @@ -30,11 +33,34 @@ 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

resolvedCounter : number = 0

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<void> {
try {
const label = await api.label.getLabel(key)
this.values[key] = label.data.label
this.resolvedCounter += 1
} catch {
// nothing could be fetched, keep default label
}
}

onInput(e) {
Expand Down