Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resolving labels to enum select editor #141

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
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