From 65e8aeda8562bba89db58f011f6b7d4c237dfbc7 Mon Sep 17 00:00:00 2001 From: Aaron Gundel Date: Tue, 10 Dec 2024 23:25:00 -0700 Subject: [PATCH 1/3] Adds scheme labels section (re: #146) --- arches_lingo/serializers.py | 16 ++ arches_lingo/src/arches_lingo/api.ts | 21 ++ .../components/generic/ControlledListItem.vue | 6 +- .../generic/ControlledListItemViewer.vue | 8 - .../components/generic/LabelViewer.vue | 165 ++++++++++++++ .../components/generic/MetaStringViewer.vue | 137 ++++++++++++ .../components/generic/NonLocalizedString.vue | 6 +- .../generic/ResourceInstanceRelationships.vue | 10 +- .../ResourceInstanceRelationshipsViewer.vue | 15 -- .../ControlledListItemViewer.vue | 28 +++ .../NonLocalizedStringEditor.vue | 0 .../NonLocalizedStringViewer.vue | 0 .../ResourceInstanceRelationshipsEditor.vue | 0 .../ResourceInstanceRelationshipsViewer.vue | 31 +++ .../components/scheme/editor/SchemeEditor.vue | 21 +- .../components/scheme/report/SchemeLabel.vue | 211 ++++++++++++++---- .../scheme/report/SchemeNamespace.vue | 54 +++-- .../scheme/report/SchemeSection.vue | 5 +- .../scheme/report/SchemeStandard.vue | 108 ++++++--- arches_lingo/src/arches_lingo/constants.ts | 1 + .../src/arches_lingo/pages/SchemePage.vue | 23 +- arches_lingo/src/arches_lingo/routes.ts | 2 +- arches_lingo/src/arches_lingo/types.ts | 39 +++- arches_lingo/templates/arches_urls.htm | 6 +- arches_lingo/urls.py | 12 + arches_lingo/views/api/pythonic_models.py | 12 + 26 files changed, 798 insertions(+), 139 deletions(-) delete mode 100644 arches_lingo/src/arches_lingo/components/generic/ControlledListItemViewer.vue create mode 100644 arches_lingo/src/arches_lingo/components/generic/MetaStringViewer.vue delete mode 100644 arches_lingo/src/arches_lingo/components/generic/ResourceInstanceRelationshipsViewer.vue create mode 100644 arches_lingo/src/arches_lingo/components/generic/controlled-list-item/ControlledListItemViewer.vue rename arches_lingo/src/arches_lingo/components/generic/{ => non-localized-string}/NonLocalizedStringEditor.vue (100%) rename arches_lingo/src/arches_lingo/components/generic/{ => non-localized-string}/NonLocalizedStringViewer.vue (100%) rename arches_lingo/src/arches_lingo/components/generic/{ => resource-instance-relationships}/ResourceInstanceRelationshipsEditor.vue (100%) create mode 100644 arches_lingo/src/arches_lingo/components/generic/resource-instance-relationships/ResourceInstanceRelationshipsViewer.vue diff --git a/arches_lingo/serializers.py b/arches_lingo/serializers.py index 95ca4f07..d8078f90 100644 --- a/arches_lingo/serializers.py +++ b/arches_lingo/serializers.py @@ -34,6 +34,22 @@ class Meta: fields = "__all__" +class SchemeLabelSerializer(ArchesModelSerializer): + class Meta: + model = ResourceInstance + graph_slug = "scheme" + nodegroups = ["appellative_status"] + fields = "__all__" + + +class SchemeLabelTileSerializer(ArchesTileSerializer): + class Meta: + model = TileModel + graph_slug = "scheme" + root_node = "appellative_status" + fields = "__all__" + + class TextualWorkRdmSystemSerializer(ArchesModelSerializer): class Meta: model = ResourceInstance diff --git a/arches_lingo/src/arches_lingo/api.ts b/arches_lingo/src/arches_lingo/api.ts index 318dfcb3..d28c04d8 100644 --- a/arches_lingo/src/arches_lingo/api.ts +++ b/arches_lingo/src/arches_lingo/api.ts @@ -59,6 +59,27 @@ export const fetchSchemeCreation = async (schemeId: string) => { return parsed; }; +export const fetchSchemeLabel = async (schemeId: string) => { + const response = await fetch(arches.urls.api_scheme_label(schemeId)); + const parsed = await response.json(); + if (!response.ok) throw new Error(parsed.message || response.statusText); + return parsed; +}; + +export const deleteSchemeLabelTile = async (tileId: string) => { + const response = await fetch(arches.urls.api_scheme_label_tile(tileId), { + method: "DELETE", + headers: { "X-CSRFTOKEN": getToken() }, + }); + + if (!response.ok) { + const parsed = await response.json(); + throw new Error(parsed.message || response.statusText); + } else { + return true; + } +}; + export const updateSchemeCreation = async ( schemeId: string, schemeInstance: SchemeInstance, diff --git a/arches_lingo/src/arches_lingo/components/generic/ControlledListItem.vue b/arches_lingo/src/arches_lingo/components/generic/ControlledListItem.vue index 695c0398..2dc64268 100644 --- a/arches_lingo/src/arches_lingo/components/generic/ControlledListItem.vue +++ b/arches_lingo/src/arches_lingo/components/generic/ControlledListItem.vue @@ -3,12 +3,12 @@ import type { ControlledListItem, DataComponentMode, } from "@/arches_lingo/types"; -import ControlledListItemViewer from "@/arches_lingo/components/generic/ControlledListItemViewer.vue"; +import ControlledListItemViewer from "@/arches_lingo/components/generic/controlled-list-item/ControlledListItemViewer.vue"; import { EDIT, VIEW } from "@/arches_lingo/constants.ts"; -const { mode = EDIT } = defineProps<{ +const { mode = VIEW } = defineProps<{ mode?: DataComponentMode; - value?: ControlledListItem; + value?: ControlledListItem | ControlledListItem[]; }>(); defineEmits(["update"]); diff --git a/arches_lingo/src/arches_lingo/components/generic/ControlledListItemViewer.vue b/arches_lingo/src/arches_lingo/components/generic/ControlledListItemViewer.vue deleted file mode 100644 index 063e6465..00000000 --- a/arches_lingo/src/arches_lingo/components/generic/ControlledListItemViewer.vue +++ /dev/null @@ -1,8 +0,0 @@ - - diff --git a/arches_lingo/src/arches_lingo/components/generic/LabelViewer.vue b/arches_lingo/src/arches_lingo/components/generic/LabelViewer.vue index e69de29b..eea4fb6d 100644 --- a/arches_lingo/src/arches_lingo/components/generic/LabelViewer.vue +++ b/arches_lingo/src/arches_lingo/components/generic/LabelViewer.vue @@ -0,0 +1,165 @@ + + + + + diff --git a/arches_lingo/src/arches_lingo/components/generic/MetaStringViewer.vue b/arches_lingo/src/arches_lingo/components/generic/MetaStringViewer.vue new file mode 100644 index 00000000..92cccc2a --- /dev/null +++ b/arches_lingo/src/arches_lingo/components/generic/MetaStringViewer.vue @@ -0,0 +1,137 @@ + + + + diff --git a/arches_lingo/src/arches_lingo/components/generic/NonLocalizedString.vue b/arches_lingo/src/arches_lingo/components/generic/NonLocalizedString.vue index cf2ae836..0f665e19 100644 --- a/arches_lingo/src/arches_lingo/components/generic/NonLocalizedString.vue +++ b/arches_lingo/src/arches_lingo/components/generic/NonLocalizedString.vue @@ -1,10 +1,10 @@ - diff --git a/arches_lingo/src/arches_lingo/components/generic/controlled-list-item/ControlledListItemViewer.vue b/arches_lingo/src/arches_lingo/components/generic/controlled-list-item/ControlledListItemViewer.vue new file mode 100644 index 00000000..a863750f --- /dev/null +++ b/arches_lingo/src/arches_lingo/components/generic/controlled-list-item/ControlledListItemViewer.vue @@ -0,0 +1,28 @@ + + diff --git a/arches_lingo/src/arches_lingo/components/generic/NonLocalizedStringEditor.vue b/arches_lingo/src/arches_lingo/components/generic/non-localized-string/NonLocalizedStringEditor.vue similarity index 100% rename from arches_lingo/src/arches_lingo/components/generic/NonLocalizedStringEditor.vue rename to arches_lingo/src/arches_lingo/components/generic/non-localized-string/NonLocalizedStringEditor.vue diff --git a/arches_lingo/src/arches_lingo/components/generic/NonLocalizedStringViewer.vue b/arches_lingo/src/arches_lingo/components/generic/non-localized-string/NonLocalizedStringViewer.vue similarity index 100% rename from arches_lingo/src/arches_lingo/components/generic/NonLocalizedStringViewer.vue rename to arches_lingo/src/arches_lingo/components/generic/non-localized-string/NonLocalizedStringViewer.vue diff --git a/arches_lingo/src/arches_lingo/components/generic/ResourceInstanceRelationshipsEditor.vue b/arches_lingo/src/arches_lingo/components/generic/resource-instance-relationships/ResourceInstanceRelationshipsEditor.vue similarity index 100% rename from arches_lingo/src/arches_lingo/components/generic/ResourceInstanceRelationshipsEditor.vue rename to arches_lingo/src/arches_lingo/components/generic/resource-instance-relationships/ResourceInstanceRelationshipsEditor.vue diff --git a/arches_lingo/src/arches_lingo/components/generic/resource-instance-relationships/ResourceInstanceRelationshipsViewer.vue b/arches_lingo/src/arches_lingo/components/generic/resource-instance-relationships/ResourceInstanceRelationshipsViewer.vue new file mode 100644 index 00000000..f5757350 --- /dev/null +++ b/arches_lingo/src/arches_lingo/components/generic/resource-instance-relationships/ResourceInstanceRelationshipsViewer.vue @@ -0,0 +1,31 @@ + + + + diff --git a/arches_lingo/src/arches_lingo/components/scheme/editor/SchemeEditor.vue b/arches_lingo/src/arches_lingo/components/scheme/editor/SchemeEditor.vue index 11ca725a..b8cf522f 100644 --- a/arches_lingo/src/arches_lingo/components/scheme/editor/SchemeEditor.vue +++ b/arches_lingo/src/arches_lingo/components/scheme/editor/SchemeEditor.vue @@ -1,4 +1,5 @@ + diff --git a/arches_lingo/src/arches_lingo/components/scheme/report/SchemeNamespace.vue b/arches_lingo/src/arches_lingo/components/scheme/report/SchemeNamespace.vue index c5b01449..a4733ba5 100644 --- a/arches_lingo/src/arches_lingo/components/scheme/report/SchemeNamespace.vue +++ b/arches_lingo/src/arches_lingo/components/scheme/report/SchemeNamespace.vue @@ -14,17 +14,19 @@ import type { SchemeNamespaceUpdate, SchemeInstance, } from "@/arches_lingo/types"; -import { VIEW, EDIT } from "@/arches_lingo/constants.ts"; +import { VIEW, EDIT, OPEN_EDITOR, ERROR } from "@/arches_lingo/constants.ts"; +import { useToast } from "primevue/usetoast"; +const toast = useToast(); const { $gettext } = useGettext(); -const schemeNamespace = ref(); +const schemeInstance = ref(); const route = useRoute(); defineProps<{ mode?: DataComponentMode; }>(); -defineEmits(["openEditor"]); +defineEmits([OPEN_EDITOR]); defineExpose({ save, getSectionValue }); @@ -33,19 +35,45 @@ onMounted(async () => { }); async function save() { - await updateSchemeNamespace( - route.params.id as string, - schemeNamespace.value as SchemeInstance, - ); + try { + await updateSchemeNamespace( + route.params.id as string, + schemeInstance.value as SchemeInstance, + ); + } catch (error) { + toast.add({ + severity: ERROR, + summary: $gettext("Error"), + detail: + error instanceof Error + ? error.message + : $gettext( + "Could not update the namespace for the resource", + ), + }); + } } async function getSectionValue() { - const response = await fetchSchemeNamespace(route.params.id as string); - schemeNamespace.value = response; + try { + const response = await fetchSchemeNamespace(route.params.id as string); + schemeInstance.value = response; + } catch (error) { + toast.add({ + severity: ERROR, + summary: $gettext("Error"), + detail: + error instanceof Error + ? error.message + : $gettext( + "Could not fetch the namespace for the resource", + ), + }); + } } function onNamespaceNameUpdate(val: string) { - const namespaceValue = schemeNamespace.value as SchemeNamespaceUpdate; + const namespaceValue = schemeInstance.value as SchemeNamespaceUpdate; if (!namespaceValue?.namespace) { namespaceValue.namespace = { namespace_name: val, @@ -63,10 +91,10 @@ function onNamespaceNameUpdate(val: string) {
@@ -174,5 +173,9 @@ function onCreationUpdate(val: string[]) { :mode="EDIT" @update="onCreationUpdate" /> +
diff --git a/arches_lingo/src/arches_lingo/components/scheme/report/SchemeUri.vue b/arches_lingo/src/arches_lingo/components/scheme/report/SchemeUri.vue index b31483f3..072b92c2 100644 --- a/arches_lingo/src/arches_lingo/components/scheme/report/SchemeUri.vue +++ b/arches_lingo/src/arches_lingo/components/scheme/report/SchemeUri.vue @@ -6,6 +6,6 @@ const { $gettext } = useGettext(); diff --git a/arches_lingo/src/arches_lingo/constants.ts b/arches_lingo/src/arches_lingo/constants.ts index a197c2a7..c1b4c758 100644 --- a/arches_lingo/src/arches_lingo/constants.ts +++ b/arches_lingo/src/arches_lingo/constants.ts @@ -9,6 +9,7 @@ export const CONTRAST = "contrast"; export const EDIT = "edit"; export const VIEW = "view"; export const OPEN_EDITOR = "openEditor"; +export const UPDATED = "updated"; export const DEFAULT_ERROR_TOAST_LIFE = 8000; export const SEARCH_RESULTS_PER_PAGE = 25; diff --git a/arches_lingo/src/arches_lingo/pages/SchemePage.vue b/arches_lingo/src/arches_lingo/pages/SchemePage.vue index f2113083..ba9f2d93 100644 --- a/arches_lingo/src/arches_lingo/pages/SchemePage.vue +++ b/arches_lingo/src/arches_lingo/pages/SchemePage.vue @@ -13,7 +13,7 @@ import type { SectionTypes } from "@/arches_lingo/types.ts"; const editorVisible = ref(false); const sectionVisible = ref(true); -const editorTab = ref(); +const editorForm = ref(); const editorTileId = ref(); const childRefs = ref>([]); @@ -33,8 +33,8 @@ const onClose = () => { sectionVisible.value = true; }; -const onOpenEditor = (tab: string, tileId: string) => { - editorTab.value = tab; +const onOpenEditor = (form: string, tileId: string) => { + editorForm.value = form; editorVisible.value = true; sectionVisible.value = true; editorTileId.value = tileId; @@ -88,9 +88,9 @@ const getRef = (el: object | null, index: number) => { :min-size="33" > import("@/arches_lingo/pages/SchemePage.vue"), meta: { shouldShowNavigation: true, - shouldShowHierarchy: false, + shouldShowHierarchy: true, requiresAuthentication: true, }, }, diff --git a/arches_lingo/src/arches_lingo/types.ts b/arches_lingo/src/arches_lingo/types.ts index ad9074fe..b44443fe 100644 --- a/arches_lingo/src/arches_lingo/types.ts +++ b/arches_lingo/src/arches_lingo/types.ts @@ -1,13 +1,13 @@ import type { Ref } from "vue"; import type { TreeNode } from "primevue/treenode"; import type { Label } from "@/arches_vue_utils/types.ts"; -import SchemeLabel from "@/arches_lingo/components/scheme/report/SchemeLabel.vue"; -import SchemeNamespace from "@/arches_lingo/components/scheme/report/SchemeNamespace.vue"; -import SchemeLicense from "@/arches_lingo/components/scheme/report/SchemeLicense.vue"; -import SchemeStandard from "@/arches_lingo/components/scheme/report/SchemeStandard.vue"; -import SchemeAuthority from "@/arches_lingo/components/scheme/report/SchemeAuthority.vue"; -import SchemeNote from "@/arches_lingo/components/scheme/report/SchemeNote.vue"; -import type { EDIT, VIEW } from "@/constants.ts"; +import type { EDIT, VIEW } from "./constants"; +import SchemeNamespace from "@/arches_lingo/src/arches_lingo/components/scheme/report/SchemeNamespace.vue"; +import SchemeLabel from "@/arches_lingo/src/arches_lingo/components/scheme/report/SchemeLabel.vue"; +import SchemeLicense from "@/arches_lingo/src/arches_lingo/components/scheme/report/SchemeLicense.vue"; +import SchemeStandard from "@/arches_lingo/src/arches_lingo/components/scheme/report/SchemeStandard.vue"; +import SchemeAuthority from "@/arches_lingo/src/arches_lingo/components/scheme/report/SchemeAuthority.vue"; +import SchemeNote from "@/arches_lingo/src/arches_lingo/components/scheme/report/SchemeNote.vue"; export interface User { first_name: string; @@ -95,6 +95,7 @@ export interface MetaStringText { type: string; language: string; deleteConfirm: string; + noRecords: string; } export interface AppellativeStatus {