Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scheme Label Editor & Reference Datatype Widget #169

Merged
merged 42 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
51ca818
make import flexible
johnatawnclementawn Dec 12, 2024
0a6e33b
Stub out reference dt widget rename from controlledlistitem
johnatawnclementawn Dec 18, 2024
b98ed49
Stub out label viewer #147
johnatawnclementawn Dec 19, 2024
c2093dd
Parse refdt options and pass to widget component #147
johnatawnclementawn Dec 30, 2024
6c10a1f
Get option labels to populate dropdown & align listitem type with til…
johnatawnclementawn Dec 31, 2024
9ff15fa
Update uri ref for select component reactivity #147
johnatawnclementawn Dec 31, 2024
310401c
Handle multiValue reference datatype in widget editor #147
johnatawnclementawn Jan 2, 2025
6b74f41
Use refdt widget in label editor #147
johnatawnclementawn Jan 2, 2025
abf06f7
nits #147
johnatawnclementawn Jan 2, 2025
e3c119d
Add resource instance nodes to scheme label form #147
johnatawnclementawn Jan 2, 2025
5d8c7c3
Add person_rdm slug and upgrade model to latest v8 requirements #147
johnatawnclementawn Jan 2, 2025
60536ab
pr feedback & readability improvements #147
johnatawnclementawn Jan 2, 2025
2a2b889
nit #147
johnatawnclementawn Jan 3, 2025
20227b0
Save / update scheme labels #147
johnatawnclementawn Jan 4, 2025
faae95c
creates date datatype after rebase #147 (#174)
chrabyrd Jan 6, 2025
1f6b076
nit #147
johnatawnclementawn Jan 6, 2025
4ea7d6c
Parse date value from primevue #147
johnatawnclementawn Jan 8, 2025
f067d49
Handle value updates for all node types #147
johnatawnclementawn Jan 8, 2025
be6d74e
Clean up refdt value ingestion #147
johnatawnclementawn Jan 8, 2025
0500832
Fix label values not updating between edit sessions and update save m…
johnatawnclementawn Jan 8, 2025
eb23d27
rm unnessecary assignment
johnatawnclementawn Jan 8, 2025
57348b8
fix labeleditor update #147
johnatawnclementawn Jan 8, 2025
f901175
nit #147
johnatawnclementawn Jan 8, 2025
c290ff6
Fix console warning about shallowRef
jacobtylerwalls Jan 8, 2025
d325db5
Fix reactivity of primeuve picker
jacobtylerwalls Jan 8, 2025
a3c7cb4
ensure metastring viewer is in view mode #147
johnatawnclementawn Jan 8, 2025
86f230e
Merge branch 'main' into jmc/147_scheme_label_editor
johnatawnclementawn Jan 8, 2025
c07c6ae
nit
johnatawnclementawn Jan 8, 2025
510f59c
Revert "Fix reactivity of primeuve picker"
johnatawnclementawn Jan 9, 2025
65f5e83
pr feedback #147
johnatawnclementawn Jan 10, 2025
e41c50f
Add form labels and passthru values for accessibility #147
johnatawnclementawn Jan 13, 2025
8ffb6c1
When creating new tile, update edit session #147
johnatawnclementawn Jan 13, 2025
557a2a0
nit #147
johnatawnclementawn Jan 14, 2025
f71bacb
Prevent multiple prefLabels in same language #147
johnatawnclementawn Jan 15, 2025
8418e8a
nit #147
johnatawnclementawn Jan 15, 2025
96dd5b2
Avoid hard coded fetching of reference dt options #147
johnatawnclementawn Jan 16, 2025
02a721e
naming nit #147
johnatawnclementawn Jan 16, 2025
600fe2f
Harden prefLabel check to prevent tile creation errors
jacobtylerwalls Jan 16, 2025
46e44f1
More informative failure (for now) if multiple prefLabel list items
jacobtylerwalls Jan 17, 2025
bff6057
Use useId()
jacobtylerwalls Jan 17, 2025
57ea8cc
Revert "Revert "Fix reactivity of primeuve picker""
jacobtylerwalls Jan 17, 2025
35a1237
Fix pt pass thru
jacobtylerwalls Jan 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
266 changes: 173 additions & 93 deletions arches_lingo/pkg/graphs/resource_models/person_rdm_system.json

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions arches_lingo/serializers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
from django.utils.translation import gettext as _
from rest_framework.exceptions import ValidationError

from arches_references.models import ListItem

from arches.app.models.models import ResourceInstance, TileModel
from arches.app.models.serializers import ArchesModelSerializer, ArchesTileSerializer

Expand Down Expand Up @@ -49,6 +54,50 @@ class Meta:
root_node = "appellative_status"
fields = "__all__"

def validate(self, data):
data = super().validate(data)
try:
PREF_LABEL_LIST_ITEM = ListItem.objects.get(
list_item_values__value="prefLabel",
)
except ListItem.MultipleObjectsReturned:
raise RuntimeError(
_(
"Ask your system administrator to deduplicate the prefLabel list items."
)
)

if data:
# TODO: reduce nested-fallback awkwardness by returning a dataclass from
# ReferenceDataType.to_python() and feeding incoming data to it.
new_label_language = next(
iter(data.get("appellative_status_ascribed_name_language", None) or []),
{},
)
new_label_type = next(
iter(data.get("appellative_status_ascribed_relation", None) or []), {}
)
current_labels = data["resourceinstance"].appellative_status

for label in current_labels:
label_language = next(
iter(label.appellative_status_ascribed_name_language or []), {}
)
label_type = next(
iter(label.appellative_status_ascribed_relation or []), {}
)
if (
data.get("tileid", None) not in (None, label.tileid)
and new_label_type.get("uri", "") == PREF_LABEL_LIST_ITEM.uri
and label_type.get("uri", "") == PREF_LABEL_LIST_ITEM.uri
and label_language.get("uri", "")
== new_label_language.get("uri", "")
):
raise ValidationError(
_("Only one preferred label per language is permitted.")
)
return data


class SchemeNoteSerializer(ArchesModelSerializer):
class Meta:
Expand Down Expand Up @@ -88,3 +137,19 @@ class Meta:
graph_slug = "concept"
nodegroups = "__all__"
fields = "__all__"


class PersonRdmSystemSerializer(ArchesModelSerializer):
class Meta:
model = ResourceInstance
graph_slug = "person"
nodegroups = "__all__"
fields = "__all__"


class GroupRdmSystemSerializer(ArchesModelSerializer):
class Meta:
model = ResourceInstance
graph_slug = "group"
nodegroups = "__all__"
fields = "__all__"
68 changes: 66 additions & 2 deletions arches_lingo/src/arches_lingo/api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import arches from "arches";
import Cookies from "js-cookie";

import type { SchemeInstance } from "@/arches_lingo/types";
import type { AppellativeStatus, SchemeInstance } from "@/arches_lingo/types";

function getToken() {
const token = Cookies.get("csrftoken");
Expand Down Expand Up @@ -53,6 +52,20 @@ export const fetchTextualWorkRdmSystemList = async () => {
return parsed;
};

export const fetchGroupRdmSystemList = async () => {
const response = await fetch(arches.urls.api_group_list);
const parsed = await response.json();
if (!response.ok) throw new Error(parsed.message || response.statusText);
return parsed;
};

export const fetchPersonRdmSystemList = async () => {
const response = await fetch(arches.urls.api_person_list);
const parsed = await response.json();
if (!response.ok) throw new Error(parsed.message || response.statusText);
return parsed;
};

export const fetchSchemeCreation = async (schemeId: string) => {
const response = await fetch(arches.urls.api_scheme_creation(schemeId));
const parsed = await response.json();
Expand All @@ -67,6 +80,26 @@ export const fetchSchemeLabel = async (schemeId: string) => {
return parsed;
};

export const createSchemeLabel = async (
schemeId: string,
appellative_status: AppellativeStatus,
) => {
const response = await fetch(arches.urls.api_scheme_label_list_create, {
method: "POST",
headers: {
"X-CSRFTOKEN": getToken(),
"Content-Type": "application/json",
},
body: JSON.stringify({
resourceinstance: schemeId,
...appellative_status,
}),
});
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,
Expand All @@ -87,6 +120,30 @@ export const deleteSchemeLabelTile = async (
}
};

export const updateSchemeLabel = async (
schemeId: string,
tileId: string,
appellative_status: AppellativeStatus,
) => {
const response = await fetch(
arches.urls.api_scheme_label_tile(schemeId, tileId),
{
method: "PATCH",
headers: {
"X-CSRFTOKEN": getToken(),
"Content-Type": "application/json",
},
body: JSON.stringify(appellative_status),
},
);
const parsed = await response.json();
if (!response.ok)
throw new Error(
parsed.non_field_errors || parsed.message || response.statusText,
);
return parsed;
};

export const fetchSchemeNotes = async (schemeId: string) => {
const response = await fetch(arches.urls.api_scheme_note(schemeId));
const parsed = await response.json();
Expand Down Expand Up @@ -193,3 +250,10 @@ export const fetchSchemes = async () => {
if (!response.ok) throw new Error(parsed.message || response.statusText);
return parsed;
};

export const fetchControlledListOptions = async (controlledListId: string) => {
const response = await fetch(arches.urls.controlled_list(controlledListId));
const parsed = await response.json();
if (!response.ok) throw new Error(parsed.message || response.statusText);
return parsed;
};

This file was deleted.

46 changes: 46 additions & 0 deletions arches_lingo/src/arches_lingo/components/generic/DateDatatype.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<script setup lang="ts">
import DateDatatypeViewer from "@/arches_lingo/components/generic/date-datatype/DateDatatypeViewer.vue";
import DateDatatypeEditor from "@/arches_lingo/components/generic/date-datatype/DateDatatypeEditor.vue";

import { EDIT, VIEW } from "@/arches_lingo/constants.ts";

import type { DataComponentMode } from "@/arches_lingo/types.ts";

interface Props {
dateFormat?: string;
mode?: DataComponentMode;
value?: string;
ptAriaLabeledBy?: string;
}

withDefaults(defineProps<Props>(), {
dateFormat: "yy-mm-dd",
mode: VIEW,
value: "",
});

const emits = defineEmits(["update"]);

const onUpdate = (val: string) => {
emits("update", val);
};
</script>

<template>
<div>
<div v-if="mode === VIEW">
<DateDatatypeViewer
:date-format="dateFormat"
:value="value"
/>
</div>
<div v-if="mode === EDIT">
<DateDatatypeEditor
:date-format="dateFormat"
:value="value"
:pt-aria-labeled-by="ptAriaLabeledBy"
@update="onUpdate"
/>
</div>
</div>
</template>
Loading
Loading