From 0693917030da47abd3979497873e29658a71d35f Mon Sep 17 00:00:00 2001 From: Aaron Gundel Date: Mon, 18 Nov 2024 10:39:23 -0700 Subject: [PATCH 1/3] Adds namespace sec with nonlocalized string widget --- .../pkg/graphs/resource_models/Scheme.json | 15 +- .../resource_models/scheme_rdm_system.json | 13 +- arches_lingo/serializers.py | 8 + arches_lingo/src/arches_lingo/api.ts | 25 ++++ .../components/generic/ControlledListItem.vue | 22 +++ .../generic/ControlledListItemViewer.vue | 8 + .../components/generic/NonLocalizedString.vue | 27 ++++ .../generic/NonLocalizedStringEditor.vue | 22 +++ .../generic/NonLocalizedStringViewer.vue | 6 + .../components/scheme/editor/SchemeEditor.vue | 137 ++++++++++++++---- .../scheme/report/SchemeAuthority.vue | 7 + .../scheme/report/SchemeLicense.vue | 8 + .../scheme/report/SchemeNamespace.vue | 84 +++++++++++ .../components/scheme/report/SchemeNote.vue | 9 ++ .../scheme/report/SchemeStandard.vue | 9 ++ .../components/scheme/report/SchemeUri.vue | 1 + arches_lingo/src/arches_lingo/constants.ts | 2 +- .../src/arches_lingo/pages/SchemePage.vue | 50 ++++++- arches_lingo/src/arches_lingo/types.ts | 36 +++++ arches_lingo/templates/arches_urls.htm | 1 + arches_lingo/urls.py | 6 + arches_lingo/views/api/pythonic_models.py | 6 + 22 files changed, 446 insertions(+), 56 deletions(-) create mode 100644 arches_lingo/src/arches_lingo/components/generic/ControlledListItem.vue create mode 100644 arches_lingo/src/arches_lingo/components/generic/ControlledListItemViewer.vue create mode 100644 arches_lingo/src/arches_lingo/components/generic/NonLocalizedString.vue create mode 100644 arches_lingo/src/arches_lingo/components/generic/NonLocalizedStringEditor.vue create mode 100644 arches_lingo/src/arches_lingo/components/generic/NonLocalizedStringViewer.vue create mode 100644 arches_lingo/src/arches_lingo/components/scheme/report/SchemeNamespace.vue diff --git a/arches_lingo/pkg/graphs/resource_models/Scheme.json b/arches_lingo/pkg/graphs/resource_models/Scheme.json index eeb75ab8..50a6675b 100644 --- a/arches_lingo/pkg/graphs/resource_models/Scheme.json +++ b/arches_lingo/pkg/graphs/resource_models/Scheme.json @@ -1463,20 +1463,13 @@ { "card_id": "92c68f1f-423c-11ee-8a8d-11afefc4bff7", "config": { - "defaultValue": { - "en": { - "direction": "ltr", - "value": "" - } - }, + "defaultValue": "", "i18n_properties": [ "placeholder" ], "label": "Namespace Name", "maxLength": null, - "placeholder": { - "en": "Enter text" - }, + "placeholder":"Enter text", "uneditable": false, "width": "100%" }, @@ -1488,7 +1481,7 @@ "sortorder": 0, "source_identifier_id": null, "visible": true, - "widget_id": "10000000-0000-0000-0000-000000000001" + "widget_id": "46ef064b-2611-4708-9f52-60136bd8a65b" }, { "card_id": "87fac835-423c-11ee-8a8d-11afefc4bff7", @@ -3196,7 +3189,7 @@ { "alias": "namespace_name", "config": {}, - "datatype": "string", + "datatype": "non-localized-string", "description": null, "exportable": false, "fieldname": null, diff --git a/arches_lingo/pkg/graphs/resource_models/scheme_rdm_system.json b/arches_lingo/pkg/graphs/resource_models/scheme_rdm_system.json index e900b711..3a9b37c7 100644 --- a/arches_lingo/pkg/graphs/resource_models/scheme_rdm_system.json +++ b/arches_lingo/pkg/graphs/resource_models/scheme_rdm_system.json @@ -3393,20 +3393,13 @@ { "card_id": "5b8894b3-48aa-11ee-8a8d-11afefc4bff7", "config": { - "defaultValue": { - "en": { - "direction": "ltr", - "value": "" - } - }, + "defaultValue": "", "i18n_properties": [ "placeholder" ], "label": "Namespace Name", "maxLength": null, - "placeholder": { - "en": "Enter text" - }, + "placeholder": "Enter text", "uneditable": false, "width": "100%" }, @@ -3417,7 +3410,7 @@ "node_id": "5b8894c0-48aa-11ee-8a8d-11afefc4bff7", "sortorder": 0, "visible": true, - "widget_id": "10000000-0000-0000-0000-000000000001" + "widget_id": "46ef064b-2611-4708-9f52-60136bd8a65b" }, { "card_id": "5b8894b6-48aa-11ee-8a8d-11afefc4bff7", diff --git a/arches_lingo/serializers.py b/arches_lingo/serializers.py index 3fcd733c..07c2baba 100644 --- a/arches_lingo/serializers.py +++ b/arches_lingo/serializers.py @@ -18,6 +18,14 @@ class Meta: fields = "__all__" +class SchemeNamespaceSerializer(ArchesModelSerializer): + class Meta: + model = ResourceInstance + graph_slug = "scheme" + nodegroups = ["namespace"] + fields = "__all__" + + class ConceptStatementSerializer(ArchesTileSerializer): class Meta: model = TileModel diff --git a/arches_lingo/src/arches_lingo/api.ts b/arches_lingo/src/arches_lingo/api.ts index ac148ef9..a75131da 100644 --- a/arches_lingo/src/arches_lingo/api.ts +++ b/arches_lingo/src/arches_lingo/api.ts @@ -1,5 +1,6 @@ import arches from "arches"; import Cookies from "js-cookie"; +import type { SchemeNamespace } from "@/arches_lingo/types"; function getToken() { const token = Cookies.get("csrftoken"); @@ -37,6 +38,30 @@ export const fetchUser = async () => { return parsed; }; +export const fetchSchemeNamespace = async (schemeId: string) => { + const response = await fetch(arches.urls.api_uri_namespace(schemeId)); + const parsed = await response.json(); + if (!response.ok) throw new Error(parsed.message || response.statusText); + return parsed; +}; + +export const updateSchemeNamespace = async ( + schemeId: string, + schemeNamespace: SchemeNamespace, +) => { + const response = await fetch(arches.urls.api_uri_namespace(schemeId), { + method: "PATCH", + headers: { + "X-CSRFTOKEN": getToken(), + "Content-Type": "application/json", + }, + body: JSON.stringify(schemeNamespace), + }); + const parsed = await response.json(); + if (!response.ok) throw new Error(parsed.message || response.statusText); + return parsed; +}; + export const fetchSearchResults = async ( searchTerm: string, items: number, diff --git a/arches_lingo/src/arches_lingo/components/generic/ControlledListItem.vue b/arches_lingo/src/arches_lingo/components/generic/ControlledListItem.vue new file mode 100644 index 00000000..377063f0 --- /dev/null +++ b/arches_lingo/src/arches_lingo/components/generic/ControlledListItem.vue @@ -0,0 +1,22 @@ + + + diff --git a/arches_lingo/src/arches_lingo/components/generic/ControlledListItemViewer.vue b/arches_lingo/src/arches_lingo/components/generic/ControlledListItemViewer.vue new file mode 100644 index 00000000..063e6465 --- /dev/null +++ b/arches_lingo/src/arches_lingo/components/generic/ControlledListItemViewer.vue @@ -0,0 +1,8 @@ + + diff --git a/arches_lingo/src/arches_lingo/components/generic/NonLocalizedString.vue b/arches_lingo/src/arches_lingo/components/generic/NonLocalizedString.vue new file mode 100644 index 00000000..0dfe8c15 --- /dev/null +++ b/arches_lingo/src/arches_lingo/components/generic/NonLocalizedString.vue @@ -0,0 +1,27 @@ + + + diff --git a/arches_lingo/src/arches_lingo/components/generic/NonLocalizedStringEditor.vue b/arches_lingo/src/arches_lingo/components/generic/NonLocalizedStringEditor.vue new file mode 100644 index 00000000..164fdb91 --- /dev/null +++ b/arches_lingo/src/arches_lingo/components/generic/NonLocalizedStringEditor.vue @@ -0,0 +1,22 @@ + + diff --git a/arches_lingo/src/arches_lingo/components/generic/NonLocalizedStringViewer.vue b/arches_lingo/src/arches_lingo/components/generic/NonLocalizedStringViewer.vue new file mode 100644 index 00000000..b0570b45 --- /dev/null +++ b/arches_lingo/src/arches_lingo/components/generic/NonLocalizedStringViewer.vue @@ -0,0 +1,6 @@ + + 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 3fda8c94..6b22e4a2 100644 --- a/arches_lingo/src/arches_lingo/components/scheme/editor/SchemeEditor.vue +++ b/arches_lingo/src/arches_lingo/components/scheme/editor/SchemeEditor.vue @@ -2,13 +2,40 @@ import { useGettext } from "vue3-gettext"; import Button from "primevue/button"; +import Tabs from "primevue/tabs"; +import TabList from "primevue/tablist"; +import Tab from "primevue/tab"; +import TabPanels from "primevue/tabpanels"; +import TabPanel from "primevue/tabpanel"; +import SchemeNamespace from "../report/SchemeNamespace.vue"; +import { onBeforeUpdate, onUpdated, ref } from "vue"; +import type { DataComponentMode } from "@/arches_lingo/types"; + const { $gettext } = useGettext(); const props = defineProps<{ editorMax: boolean; + activeTab: string; }>(); +type sectionTypes = typeof SchemeNamespace; +const childRefs = ref>([]); +const editMode: DataComponentMode = "edit"; +const schemeComponents = [ + { + component: SchemeNamespace, + props: { + mode: editMode, + }, + on: { + update: onUpdated, + }, + id: "namespace", + editorTabName: $gettext("Scheme Namespace"), + }, +]; + +const emit = defineEmits(["maximize", "side", "close", "updated"]); -const emit = defineEmits(["maximize", "side", "close"]); const toggleSize = () => { if (props.editorMax) { @@ -17,37 +44,95 @@ const toggleSize = () => { emit("side"); } }; + +schemeComponents.map((x) => { + x.props.mode = "edit"; +}); + +const getRef = (el: object | null, index: number) => { + if (el != null) childRefs.value[index] = el as sectionTypes; +}; + +onBeforeUpdate(() => { + childRefs.value = []; +}); + +const updateScheme = async () => { + await Promise.all( + childRefs.value.map(async (ref) => { + return ref.save(); + }), + ); + + emit('updated'); +}; +