Skip to content

Commit

Permalink
adds notes section (#162)
Browse files Browse the repository at this point in the history
* adds notes section

* fix naming nit

* wrap gettext in spans

* pr feedback

* pr feedback
  • Loading branch information
aarongundel committed Jan 2, 2025
1 parent 65e8aed commit b430b06
Show file tree
Hide file tree
Showing 11 changed files with 258 additions and 25 deletions.
16 changes: 16 additions & 0 deletions arches_lingo/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ class Meta:
fields = "__all__"


class SchemeNoteSerializer(ArchesModelSerializer):
class Meta:
model = ResourceInstance
graph_slug = "scheme"
nodegroups = ["statement"]
fields = "__all__"


class SchemeNoteTileSerializer(ArchesTileSerializer):
class Meta:
model = TileModel
graph_slug = "scheme"
root_node = "statement"
fields = "__all__"


class TextualWorkRdmSystemSerializer(ArchesModelSerializer):
class Meta:
model = ResourceInstance
Expand Down
43 changes: 38 additions & 5 deletions arches_lingo/src/arches_lingo/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,44 @@ export const fetchSchemeLabel = async (schemeId: string) => {
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() },
});
export const deleteSchemeLabelTile = async (
schemeId: string,
tileId: string,
) => {
const response = await fetch(
arches.urls.api_scheme_label_tile(schemeId, 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 fetchSchemeNotes = async (schemeId: string) => {
const response = await fetch(arches.urls.api_scheme_note(schemeId));
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,
) => {
const response = await fetch(
arches.urls.api_scheme_note_tile(schemeId, tileId),
{
method: "DELETE",
headers: { "X-CSRFTOKEN": getToken() },
},
);

if (!response.ok) {
const parsed = await response.json();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function confirmDelete(tileId: string) {
confirm.require({
header: $gettext("Confirmation"),
message: props.metaStringText.deleteConfirm,
group: props.metaStringText.name,
accept: () => {
emits("deleteString", tileId);
},
Expand All @@ -45,6 +46,7 @@ function confirmDelete(tileId: string) {
<template>
<ConfirmDialog
:pt="{ root: { style: { fontFamily: 'sans-serif' } } }"
:group="metaStringText.name"
></ConfirmDialog>
<DataTable
v-model:expanded-rows="expandedRows"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import TabPanel from "primevue/tabpanel";
import SchemeNamespace from "@/arches_lingo/components/scheme/report/SchemeNamespace.vue";
import SchemeStandard from "@/arches_lingo/components/scheme/report/SchemeStandard.vue";
import SchemeLabel from "@/arches_lingo/components/scheme/report/SchemeLabel.vue";
import SchemeNote from "@/arches_lingo/components/scheme/report/SchemeNote.vue";
import type { SectionTypes } from "@/arches_lingo/types.ts";
const { $gettext } = useGettext();
Expand All @@ -37,6 +38,11 @@ const schemeComponents = [
id: "standard",
editorTabName: $gettext("Scheme Standards Followed"),
},
{
component: SchemeNote,
id: "note",
editorTabName: $gettext("Scheme Notes"),
},
];
const emit = defineEmits(["maximize", "side", "close", "updated"]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async function getSectionValue() {
async function deleteSectionValue(tileId: string) {
let result = false;
try {
result = await deleteSchemeLabelTile(tileId);
result = await deleteSchemeLabelTile(route.params.id as string, tileId);
} catch (error) {
toast.add({
severity: ERROR,
Expand Down Expand Up @@ -122,10 +122,12 @@ async function save() {
@delete-string="deleteSectionValue"
>
<template #name="{ rowData }">
{{
(rowData as AppellativeStatus)
.appellative_status_ascribed_name_content
}}
<span>
{{
(rowData as AppellativeStatus)
.appellative_status_ascribed_name_content
}}
</span>
</template>
<template #type="{ rowData }">
<ControlledListItem
Expand All @@ -147,7 +149,7 @@ async function save() {
</template>
<template #drawer="{ rowData }">
<div>
{{ $gettext("Bibliographic Sources") }}:
<span>{{ $gettext("Bibliographic Sources:") }}</span>
<ResourceInstanceRelationships
:value="
(rowData as AppellativeStatus)
Expand All @@ -156,7 +158,7 @@ async function save() {
></ResourceInstanceRelationships>
</div>
<div>
{{ $gettext("Contributors") }}:
<span>{{ $gettext("Contributors:") }}</span>
<ResourceInstanceRelationships
:value="
(rowData as AppellativeStatus)
Expand Down
156 changes: 146 additions & 10 deletions arches_lingo/src/arches_lingo/components/scheme/report/SchemeNote.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,156 @@
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { useGettext } from "vue3-gettext";
import { useRoute } from "vue-router";
import { useToast } from "primevue/usetoast";
import MetaStringViewer from "@/arches_lingo/components/generic/MetaStringViewer.vue";
import SchemeReportSection from "@/arches_lingo/components/scheme/report/SchemeSection.vue";
import { deleteSchemeNoteTile, fetchSchemeNotes } from "@/arches_lingo/api.ts";
import { ERROR, OPEN_EDITOR, VIEW, EDIT } from "@/arches_lingo/constants.ts";
import type {
DataComponentMode,
MetaStringText,
SchemeInstance,
SchemeStatement,
} from "@/arches_lingo/types.ts";
import ResourceInstanceRelationships from "@/arches_lingo/components/generic/ResourceInstanceRelationships.vue";
import ControlledListItem from "@/arches_lingo/components/generic/ControlledListItem.vue";
const save = () => {
console.log("save");
};
const getSectionValue = async () => {
console.log("update");
const { $gettext } = useGettext();
const schemeInstance = ref<SchemeInstance>();
const route = useRoute();
const toast = useToast();
const metaStringLabel: MetaStringText = {
deleteConfirm: $gettext("Are you sure you want to delete this note?"),
language: $gettext("Note Language"),
name: $gettext("Note Name"),
type: $gettext("Note Type"),
};
defineExpose({ save, getSectionValue });
const { $gettext } = useGettext();
withDefaults(
defineProps<{
mode?: DataComponentMode;
tileId?: string | null;
}>(),
{
mode: VIEW,
tileId: null, // editor arg specifying what tile to operate on.
},
);
const emits = defineEmits([OPEN_EDITOR]);
defineExpose({ getSectionValue });
onMounted(() => {
getSectionValue();
});
async function getSectionValue() {
try {
const result = await fetchSchemeNotes(route.params.id as string);
schemeInstance.value = {
statement: result.statement,
};
} catch (error) {
toast.add({
severity: ERROR,
summary: $gettext("Error"),
detail:
error instanceof Error
? error.message
: $gettext("Could not fetch the notes for the resource"),
});
}
}
async function deleteSectionValue(tileId: string) {
let result = false;
try {
result = await deleteSchemeNoteTile(route.params.id as string, tileId);
} catch (error) {
toast.add({
severity: ERROR,
summary: $gettext("Error"),
detail:
error instanceof Error
? error.message
: $gettext("Could not delete selected note"),
});
}
if (result) {
getSectionValue();
}
}
function editSectionValue(tileId: string) {
const schemeStatement = schemeInstance.value?.statement?.find(
(tile) => tile.tileid === tileId,
);
if (schemeStatement && schemeStatement.tileid === tileId) {
emits(OPEN_EDITOR, schemeStatement.tileid);
} else {
toast.add({
severity: ERROR,
summary: $gettext("Error"),
detail: $gettext("Could not find the selected label to edit"),
});
}
}
</script>

<template>
<SchemeReportSection :title-text="$gettext('Scheme Notes')">
abc
</SchemeReportSection>
<div v-if="mode === VIEW">
<SchemeReportSection
:title-text="$gettext('Scheme Notes')"
@open-editor="emits(OPEN_EDITOR)"
>
<MetaStringViewer
:meta-strings="schemeInstance?.statement"
:meta-string-text="metaStringLabel"
@edit-string="editSectionValue"
@delete-string="deleteSectionValue"
>
<template #name="{ rowData }">
<span>
{{ (rowData as SchemeStatement).statement_content_n1 }}
</span>
</template>
<template #type="{ rowData }">
<ControlledListItem
:value="(rowData as SchemeStatement).statement_type_n1"
/>
</template>
<template #language="{ rowData }">
<ControlledListItem
:value="
(rowData as SchemeStatement).statement_language_n1
"
/>
</template>
<template #drawer="{ rowData }">
<div>
<span>{{ $gettext("Bibliographic Sources:") }}</span>
<ResourceInstanceRelationships
:value="
(rowData as SchemeStatement)
.statement_data_assignment_object_used
"
/>
</div>
<div>
<span>{{ $gettext("Contributors:") }}</span>
<ResourceInstanceRelationships
:value="
(rowData as SchemeStatement)
.statement_data_assignment_actor
"
/>
</div>
</template>
</MetaStringViewer>
</SchemeReportSection>
</div>
<div v-if="mode === EDIT"></div>
</template>
4 changes: 3 additions & 1 deletion arches_lingo/src/arches_lingo/pages/SchemePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ const getRef = (el: object | null, index: number) => {
:ref="(el) => getRef(el, index)"
v-bind="component.props"
@open-editor="
(tileId: string) => onOpenEditor(component.id, tileId)
(tileId: string) => {
onOpenEditor(component.id, tileId);
}
"
/>
</template>
Expand Down
10 changes: 10 additions & 0 deletions arches_lingo/src/arches_lingo/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ export interface AppellativeStatus {
appellative_status_data_assignment_actor: ResourceInstanceReference[];
}

export interface SchemeStatement {
tileid: string;
statement_content_n1: string;
statement_language_n1?: ControlledListItem[];
statement_type_n1?: ControlledListItem[];
statement_data_assignment_object_used: ResourceInstanceReference[];
statement_data_assignment_actor: ResourceInstanceReference[];
}

export interface SchemeInstance {
namespace?: {
namespace_name: string;
Expand All @@ -117,6 +126,7 @@ export interface SchemeInstance {
creation_sources: ResourceInstanceReference[];
};
appellative_status?: AppellativeStatus[];
statement?: SchemeStatement[];
}

export interface SchemeResource {
Expand Down
4 changes: 3 additions & 1 deletion arches_lingo/templates/arches_urls.htm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
api_uri_namespace='(resourceid)=>{return "{% url "api-uri-components" "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" %}".replace("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", resourceid)}'
api_schemes="{% url 'schemes-list-create' %}"
api_scheme_label='(resourceid)=>{return "{% url "api-scheme-label" "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" %}".replace("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", resourceid)}'
api_scheme_label_tile='(tileid)=>{return "{% url "api-scheme-label-tile" "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" %}".replace("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", tileid)}'
api_scheme_label_tile='(resourceid, tileid)=>{return "{% url "api-scheme-label-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='(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_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' %}"
></div>
Expand Down
14 changes: 13 additions & 1 deletion arches_lingo/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
SchemeLabelView,
SchemeListCreateView,
SchemeNamespaceView,
SchemeNoteTileView,
SchemeNoteView,
SchemeStatementDetailView,
SchemeStatementListCreateView,
TextualWorkRdmSystemSerializerView,
Expand Down Expand Up @@ -61,10 +63,20 @@
name="api-scheme-label",
),
path(
"api/scheme-label/<uuid:pk>",
"api/scheme/<uuid:resource_id>/label/<uuid:pk>",
SchemeLabelTileView.as_view(),
name="api-scheme-label-tile",
),
path(
"api/scheme/<uuid:pk>/note",
SchemeNoteView.as_view(),
name="api-scheme-note",
),
path(
"api/scheme/<uuid:resource_id>/note/<uuid:pk>",
SchemeNoteTileView.as_view(),
name="api-scheme-note-tile",
),
path(
"api/textual-work",
TextualWorkRdmSystemSerializerView.as_view(),
Expand Down
Loading

0 comments on commit b430b06

Please sign in to comment.