From 8895e831b02ef449491b0705942d904382ab18e4 Mon Sep 17 00:00:00 2001 From: Aaron Gundel Date: Wed, 8 Jan 2025 11:49:37 -0700 Subject: [PATCH 1/2] Adds note editor (#177) --- arches_lingo/src/arches_lingo/api.ts | 47 ++- .../components/generic/NoteEditor.vue | 318 ++++++++++++++++++ .../components/scheme/report/SchemeNote.vue | 35 +- arches_lingo/src/arches_lingo/types.ts | 4 + arches_lingo/templates/arches_urls.htm | 1 + arches_lingo/urls.py | 6 + arches_lingo/views/api/pythonic_models.py | 5 + 7 files changed, 409 insertions(+), 7 deletions(-) create mode 100644 arches_lingo/src/arches_lingo/components/generic/NoteEditor.vue diff --git a/arches_lingo/src/arches_lingo/api.ts b/arches_lingo/src/arches_lingo/api.ts index 5cf0ea51..06169eb7 100644 --- a/arches_lingo/src/arches_lingo/api.ts +++ b/arches_lingo/src/arches_lingo/api.ts @@ -1,6 +1,10 @@ import arches from "arches"; import Cookies from "js-cookie"; -import type { AppellativeStatus, SchemeInstance } from "@/arches_lingo/types"; +import type { + AppellativeStatus, + SchemeInstance, + SchemeStatement, +} from "@/arches_lingo/types"; function getToken() { const token = Cookies.get("csrftoken"); @@ -100,6 +104,26 @@ export const createSchemeLabel = async ( return parsed; }; +export const createSchemeNote = async ( + schemeId: string, + statement: SchemeStatement, +) => { + const response = await fetch(arches.urls.api_scheme_note_create, { + method: "POST", + headers: { + "X-CSRFTOKEN": getToken(), + "Content-Type": "application/json", + }, + body: JSON.stringify({ + resourceinstance: schemeId, + ...statement, + }), + }); + const parsed = await response.json(); + if (!response.ok) throw new Error(parsed.message || response.statusText); + return parsed; +}; + export const deleteSchemeLabelTile = async ( schemeId: string, tileId: string, @@ -151,6 +175,27 @@ export const fetchSchemeNotes = async (schemeId: string) => { return parsed; }; +export const updateSchemeNote = async ( + schemeId: string, + tileId: string, + schemeStatement: SchemeStatement, +) => { + const response = await fetch( + arches.urls.api_scheme_note_tile(schemeId, tileId), + { + method: "PATCH", + headers: { + "X-CSRFTOKEN": getToken(), + "Content-Type": "application/json", + }, + body: JSON.stringify(schemeStatement), + }, + ); + const parsed = await response.json(); + if (!response.ok) throw new Error(parsed.message || response.statusText); + return parsed; +}; + export const deleteSchemeNoteTile = async ( schemeId: string, tileId: string, diff --git a/arches_lingo/src/arches_lingo/components/generic/NoteEditor.vue b/arches_lingo/src/arches_lingo/components/generic/NoteEditor.vue new file mode 100644 index 00000000..2da0ab6e --- /dev/null +++ b/arches_lingo/src/arches_lingo/components/generic/NoteEditor.vue @@ -0,0 +1,318 @@ + + + diff --git a/arches_lingo/src/arches_lingo/components/scheme/report/SchemeNote.vue b/arches_lingo/src/arches_lingo/components/scheme/report/SchemeNote.vue index 5fdfeb45..fcff21bd 100644 --- a/arches_lingo/src/arches_lingo/components/scheme/report/SchemeNote.vue +++ b/arches_lingo/src/arches_lingo/components/scheme/report/SchemeNote.vue @@ -1,5 +1,5 @@ diff --git a/arches_lingo/src/arches_lingo/types.ts b/arches_lingo/src/arches_lingo/types.ts index b19de89d..d2c28b08 100644 --- a/arches_lingo/src/arches_lingo/types.ts +++ b/arches_lingo/src/arches_lingo/types.ts @@ -131,8 +131,12 @@ export interface SchemeStatement { statement_content_n1: string; statement_language_n1?: ControlledListItem[]; statement_type_n1?: ControlledListItem[]; + statement_type_metatype_n1?: ControlledListItem[]; statement_data_assignment_object_used: ResourceInstanceReference[]; statement_data_assignment_actor: ResourceInstanceReference[]; + statement_data_assignment_type: ControlledListItem[]; + statement_data_assignment_timespan_begin_of_the_begin: string; + statement_data_assignment_timespan_end_of_the_end: string; } export interface SchemeInstance { diff --git a/arches_lingo/templates/arches_urls.htm b/arches_lingo/templates/arches_urls.htm index 1f968285..d17610c1 100644 --- a/arches_lingo/templates/arches_urls.htm +++ b/arches_lingo/templates/arches_urls.htm @@ -16,6 +16,7 @@ api_scheme_label_list_create="{% url 'api-scheme-label-list-create' %}" api_scheme_note='(resourceid)=>{return "{% url "api-scheme-note" "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" %}".replace("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", resourceid)}' api_scheme_note_tile='(resourceid, tileid)=>{return "{% url "api-scheme-note-tile" "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaab" %}".replace("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", resourceid).replace("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaab", tileid)}' + api_scheme_note_create="{% url 'api-scheme-note-create' %}" api_scheme_creation='(resourceid)=>{return "{% url "api-scheme-creation" "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" %}".replace("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", resourceid)}' api_textualwork_list="{% url 'api-textualwork-list' %}" api_group_list="{% url 'api-group-list' %}" diff --git a/arches_lingo/urls.py b/arches_lingo/urls.py index 33e3de87..0cc20a85 100644 --- a/arches_lingo/urls.py +++ b/arches_lingo/urls.py @@ -21,6 +21,7 @@ SchemeNamespaceView, SchemeNoteTileView, SchemeNoteView, + SchemeNoteCreateView, SchemeStatementDetailView, SchemeStatementListCreateView, TextualWorkRdmSystemSerializerView, @@ -86,6 +87,11 @@ SchemeNoteTileView.as_view(), name="api-scheme-note-tile", ), + path( + "api/scheme/note", + SchemeNoteCreateView.as_view(), + name="api-scheme-note-create", + ), path( "api/textual-work", TextualWorkRdmSystemSerializerView.as_view(), diff --git a/arches_lingo/views/api/pythonic_models.py b/arches_lingo/views/api/pythonic_models.py index aa3ed1d7..ccdf108f 100644 --- a/arches_lingo/views/api/pythonic_models.py +++ b/arches_lingo/views/api/pythonic_models.py @@ -85,6 +85,11 @@ class SchemeNoteTileView(ArchesModelAPIMixin, RetrieveUpdateDestroyAPIView): serializer_class = SchemeNoteTileSerializer +class SchemeNoteCreateView(ArchesModelAPIMixin, ListCreateAPIView): + permission_classes = [RDMAdministrator] + serializer_class = SchemeNoteTileSerializer + + class TextualWorkRdmSystemSerializerView(ArchesModelAPIMixin, ListAPIView): permission_classes = [RDMAdministrator] serializer_class = TextualWorkRdmSystemSerializer From 57f31e2737fe26aa66cc8c87114d94719adbf20f Mon Sep 17 00:00:00 2001 From: Aaron Gundel Date: Tue, 21 Jan 2025 10:26:58 -0700 Subject: [PATCH 2/2] fixup! Adds note editor (#177) --- .../components/generic/NoteEditor.vue | 146 ++++++++++++------ 1 file changed, 100 insertions(+), 46 deletions(-) diff --git a/arches_lingo/src/arches_lingo/components/generic/NoteEditor.vue b/arches_lingo/src/arches_lingo/components/generic/NoteEditor.vue index 2da0ab6e..87b3a934 100644 --- a/arches_lingo/src/arches_lingo/components/generic/NoteEditor.vue +++ b/arches_lingo/src/arches_lingo/components/generic/NoteEditor.vue @@ -1,5 +1,14 @@