Skip to content

Commit

Permalink
Add resolving labels to enum select editor
Browse files Browse the repository at this point in the history
  • Loading branch information
janslifka committed Sep 8, 2023
1 parent 70acf75 commit 9d1a63a
Showing 1 changed file with 35 additions and 9 deletions.
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"

Check warning on line 6 in src/components/ShaclForm/Editor/EnumSelectEditor.vue

View workflow job for this annotation

GitHub Actions / build (fairdatapoint-index, 16)

Attribute ":key" should go before "@input"

Check warning on line 6 in src/components/ShaclForm/Editor/EnumSelectEditor.vue

View workflow job for this annotation

GitHub Actions / build (fairdatapoint-index, 16)

Attribute ":key" should go before "@input"

Check warning on line 6 in src/components/ShaclForm/Editor/EnumSelectEditor.vue

View workflow job for this annotation

GitHub Actions / build (fairdatapoint, 16)

Attribute ":key" should go before "@input"

Check warning on line 6 in src/components/ShaclForm/Editor/EnumSelectEditor.vue

View workflow job for this annotation

GitHub Actions / build (fairdatapoint, 16)

Attribute ":key" should go before "@input"

Check warning on line 6 in src/components/ShaclForm/Editor/EnumSelectEditor.vue

View workflow job for this annotation

GitHub Actions / build (fairdatapoint-index, 16)

Attribute ":key" should go before "@input"

Check warning on line 6 in src/components/ShaclForm/Editor/EnumSelectEditor.vue

View workflow job for this annotation

GitHub Actions / build (fairdatapoint-index, 16)

Attribute ":key" should go before "@input"

Check warning on line 6 in src/components/ShaclForm/Editor/EnumSelectEditor.vue

View workflow job for this annotation

GitHub Actions / build (fairdatapoint, 16)

Attribute ":key" should go before "@input"

Check warning on line 6 in src/components/ShaclForm/Editor/EnumSelectEditor.vue

View workflow job for this annotation

GitHub Actions / build (fairdatapoint, 16)

Attribute ":key" should go before "@input"
>
<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

0 comments on commit 9d1a63a

Please sign in to comment.