-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
510f59c
commit a82fcad
Showing
4 changed files
with
285 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
243 changes: 243 additions & 0 deletions
243
arches_lingo/src/arches_lingo/components/generic/NoteEditor.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,243 @@ | ||
<script setup lang="ts"> | ||
import { computed, inject, onMounted, ref, toRaw, toRef, type Ref } from "vue"; | ||
import Button from "primevue/button"; | ||
import { useGettext } from "vue3-gettext"; | ||
import { useRoute } from "vue-router"; | ||
import { useToast } from "primevue/usetoast"; | ||
import { | ||
fetchControlledListOptions, | ||
fetchGroupRdmSystemList, | ||
fetchPersonRdmSystemList, | ||
fetchTextualWorkRdmSystemList, | ||
updateSchemeNote, | ||
} from "@/arches_lingo/api.ts"; | ||
import DateDatatype from "@/arches_lingo/components/generic/DateDatatype.vue"; | ||
import NonLocalizedString from "@/arches_lingo/components/generic/NonLocalizedString.vue"; | ||
import ReferenceDatatype from "@/arches_lingo/components/generic/ReferenceDatatype.vue"; | ||
import ResourceInstanceRelationships from "@/arches_lingo/components/generic/ResourceInstanceRelationships.vue"; | ||
import { | ||
EDIT, | ||
ERROR, | ||
EVENT_TYPES_CONTROLLED_LIST, | ||
LABEL_CONTROLLED_LIST, | ||
LANGUAGE_CONTROLLED_LIST, | ||
METATYPES_CONTROLLED_LIST, | ||
selectedLanguageKey, | ||
STATUSES_CONTROLLED_LIST, | ||
} from "@/arches_lingo/constants.ts"; | ||
import type { | ||
ControlledListItem, | ||
ControlledListItemResult, | ||
ResourceInstanceReference, | ||
ResourceInstanceResult, | ||
SchemeStatement, | ||
} from "@/arches_lingo/types.ts"; | ||
import type { Language } from "@/arches_vue_utils/types.ts"; | ||
const emit = defineEmits(["update"]); | ||
const toast = useToast(); | ||
const route = useRoute(); | ||
const selectedLanguage = inject(selectedLanguageKey) as Ref<Language>; | ||
const { $gettext } = useGettext(); | ||
const props = withDefaults( | ||
defineProps<{ | ||
value?: SchemeStatement; | ||
}>(), | ||
{ | ||
value: () => ({}) as SchemeStatement, | ||
}, | ||
); | ||
const valueRef = toRef(props, "value"); | ||
const formValue = computed({ | ||
get: () => valueRef.value, | ||
set: (newVal: SchemeStatement) => { | ||
valueRef.value = newVal; | ||
}, | ||
}); | ||
const languageOptions = ref<ControlledListItem[]>([]); | ||
const typeOptions = ref<ControlledListItem[]>([]); | ||
const statusOptions = ref<ControlledListItem[]>([]); | ||
const metatypeOptions = ref<ControlledListItem[]>([]); | ||
const eventTypeOptions = ref<ControlledListItem[]>([]); | ||
const groupAndPersonOptions = ref<ResourceInstanceReference[]>(); | ||
const textualWorkOptions = ref<ResourceInstanceReference[]>(); | ||
function onUpdate( | ||
node: keyof SchemeStatement, | ||
val: ControlledListItem[] | ResourceInstanceReference[] | string, | ||
) { | ||
if (Array.isArray(val)) { | ||
(formValue.value[node] as unknown) = val.map((item) => toRaw(item)); | ||
} else { | ||
(formValue.value[node] as unknown) = toRaw(val); | ||
} | ||
} | ||
async function save() { | ||
try { | ||
await updateSchemeNote( | ||
route.params.id as string, | ||
formValue.value.tileid as string, | ||
formValue.value, | ||
); | ||
emit("update"); | ||
} catch (error) { | ||
toast.add({ | ||
severity: ERROR, | ||
summary: $gettext("Error saving scheme"), | ||
detail: (error as Error).message, | ||
}); | ||
} | ||
} | ||
async function getControlledListOptions( | ||
listId: string, | ||
): Promise<ControlledListItem[]> { | ||
const parsed = await fetchControlledListOptions(listId); | ||
const options = parsed.items.map( | ||
(item: ControlledListItemResult): ControlledListItem => ({ | ||
list_id: item.list_id, | ||
uri: item.uri, | ||
labels: item.values, | ||
}), | ||
); | ||
return options; | ||
} | ||
async function getResourceInstanceOptions( | ||
fetchOptions: () => Promise<ResourceInstanceResult[]>, | ||
): Promise<ResourceInstanceReference[]> { | ||
const options = await fetchOptions(); | ||
const results = options.map((option: ResourceInstanceResult) => { | ||
const result: ResourceInstanceReference = { | ||
display_value: option.descriptors[selectedLanguage.value.code].name, | ||
resourceId: option.resourceinstanceid, | ||
ontologyProperty: "ac41d9be-79db-4256-b368-2f4559cfbe55", | ||
inverseOntologyProperty: "ac41d9be-79db-4256-b368-2f4559cfbe55", | ||
}; | ||
return result; | ||
}); | ||
return results; | ||
} | ||
onMounted(async () => { | ||
const [languageOpts, typeOpts, statusOpts, metatypeOpts, eventTypeOpts] = | ||
await Promise.all([ | ||
getControlledListOptions(LANGUAGE_CONTROLLED_LIST), | ||
getControlledListOptions(LABEL_CONTROLLED_LIST), | ||
getControlledListOptions(STATUSES_CONTROLLED_LIST), | ||
getControlledListOptions(METATYPES_CONTROLLED_LIST), | ||
getControlledListOptions(EVENT_TYPES_CONTROLLED_LIST), | ||
]); | ||
languageOptions.value = languageOpts; | ||
typeOptions.value = typeOpts; | ||
statusOptions.value = statusOpts; | ||
metatypeOptions.value = metatypeOpts; | ||
eventTypeOptions.value = eventTypeOpts; | ||
groupAndPersonOptions.value = await getResourceInstanceOptions( | ||
fetchGroupRdmSystemList, | ||
); | ||
groupAndPersonOptions.value = [ | ||
...(groupAndPersonOptions.value || []), | ||
...(await getResourceInstanceOptions(fetchPersonRdmSystemList)), | ||
]; | ||
textualWorkOptions.value = await getResourceInstanceOptions( | ||
fetchTextualWorkRdmSystemList, | ||
); | ||
}); | ||
</script> | ||
|
||
<template> | ||
<!-- Statement: string --> | ||
<label for="">{{ $gettext("Statement") }}</label> | ||
<NonLocalizedString | ||
:value="value?.statement_content_n1 ?? ''" | ||
:mode="EDIT" | ||
@update="(val) => onUpdate('statement_content_n1', val)" | ||
/> | ||
<!-- Statement Language: reference datatype --> | ||
<label for="">{{ $gettext("Statement Language") }}</label> | ||
<ReferenceDatatype | ||
:value="value?.statement_language_n1" | ||
:mode="EDIT" | ||
:multi-value="false" | ||
:options="languageOptions" | ||
@update="(val) => onUpdate('statement_language_n1', val)" | ||
/> | ||
<!-- Statement Type: reference datatype --> | ||
<label for="">{{ $gettext("Statement Type") }}</label> | ||
<ReferenceDatatype | ||
:value="value?.statement_type_n1" | ||
:mode="EDIT" | ||
:multi-value="false" | ||
:options="typeOptions" | ||
@update="(val) => onUpdate('statement_type_n1', val)" | ||
/> | ||
|
||
<!-- Statement Status Metatype: reference datatype --> | ||
<label for="">{{ $gettext("Statement Metatype") }}</label> | ||
<ReferenceDatatype | ||
:value="value?.statement_type_metatype_n1" | ||
:mode="EDIT" | ||
:multi-value="false" | ||
:options="metatypeOptions" | ||
@update="(val) => onUpdate('statement_type_metatype_n1', val)" | ||
/> | ||
|
||
<!-- Statement Temporal Validity Start: date --> | ||
<label for="">{{ $gettext("Label Temporal Validity Start") }}</label> | ||
<DateDatatype | ||
:value="value?.statement_data_assignment_timespan_begin_of_the_begin" | ||
:mode="EDIT" | ||
@update="onUpdate" | ||
/> | ||
|
||
<!-- Statement Temporal Validity End: date --> | ||
<label for="">{{ $gettext("Label Temporal Validity End") }}</label> | ||
<DateDatatype | ||
:value="value?.statement_data_assignment_timespan_end_of_the_end" | ||
:mode="EDIT" | ||
@update="onUpdate" | ||
/> | ||
|
||
<!-- Contributor: resource instance --> | ||
<label for="">{{ $gettext("Contributor") }}</label> | ||
<ResourceInstanceRelationships | ||
:value="value?.statement_data_assignment_actor" | ||
:mode="EDIT" | ||
:options="groupAndPersonOptions" | ||
@update="(val) => onUpdate('statement_data_assignment_actor', val)" | ||
/> | ||
<!-- Sources: resource instance --> | ||
<label for="">{{ $gettext("Sources") }}</label> | ||
<ResourceInstanceRelationships | ||
:value="value?.statement_data_assignment_object_used" | ||
:mode="EDIT" | ||
:options="textualWorkOptions" | ||
@update=" | ||
(val) => onUpdate('statement_data_assignment_object_used', val) | ||
" | ||
/> | ||
<!-- Warrant Type: reference datatype --> | ||
<label for="">{{ $gettext("Warrant Type") }}</label> | ||
<ReferenceDatatype | ||
:value="value?.statement_data_assignment_type" | ||
:mode="EDIT" | ||
:multi-value="false" | ||
:options="eventTypeOptions" | ||
@update="(val) => onUpdate('statement_data_assignment_type', val)" | ||
/> | ||
<Button | ||
:label="$gettext('Update')" | ||
@click="save" | ||
></Button> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters