Skip to content

Commit

Permalink
Add resource instance nodes to scheme label form #147
Browse files Browse the repository at this point in the history
  • Loading branch information
johnatawnclementawn committed Jan 3, 2025
1 parent 1a731a6 commit da263b3
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 12 deletions.
16 changes: 16 additions & 0 deletions arches_lingo/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,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__"
14 changes: 14 additions & 0 deletions arches_lingo/src/arches_lingo/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,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 Down
74 changes: 63 additions & 11 deletions arches_lingo/src/arches_lingo/components/generic/LabelEditor.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<script setup lang="ts">
import { defineProps, onMounted, ref } from "vue";
import { fetchControlledListOptions } from "@/arches_lingo/api.ts";
import { defineProps, inject, onMounted, ref, type Ref } from "vue";
import {
fetchControlledListOptions,
fetchGroupRdmSystemList,
fetchPersonRdmSystemList,
fetchTextualWorkRdmSystemList,
} from "@/arches_lingo/api.ts";
import NonLocalizedString from "@/arches_lingo/components/generic/NonLocalizedString.vue";
import ReferenceDatatype from "@/arches_lingo/components/generic/ReferenceDatatype.vue";
// import ResourceInstanceRelationships from "@/arches_lingo/components/generic/ResourceInstanceRelationships.vue";
import ResourceInstanceRelationships from "@/arches_lingo/components/generic/ResourceInstanceRelationships.vue";
import {
selectedLanguageKey,
EDIT,
LANGUAGE_CONTROLLED_LIST,
LABEL_CONTROLLED_LIST,
Expand All @@ -19,8 +25,12 @@ import type {
AppellativeStatus,
ControlledListItem,
ControlledListItemResult,
ResourceInstanceReference,
ResourceInstanceResult,
} from "@/arches_lingo/types.ts";
import type { Language } from "@/arches_vue_utils/types.ts";
const selectedLanguage = inject(selectedLanguageKey) as Ref<Language>;
const props = withDefaults(
defineProps<{
value?: AppellativeStatus;
Expand All @@ -35,7 +45,9 @@ function onUpdate(newValue: string) {
console.log(newValue);
}
async function getOptions(listId: string): Promise<ControlledListItem[]> {
async function getControlledListOptions(
listId: string,
): Promise<ControlledListItem[]> {
const parsed = await fetchControlledListOptions(listId);
const options = parsed.items.map(
(item: ControlledListItemResult): ControlledListItem => ({
Expand All @@ -47,27 +59,55 @@ async function getOptions(listId: string): Promise<ControlledListItem[]> {
return options;
}
async function getResourceInstanceOptions(
fetchOptions: () => Promise<ResourceInstanceResult[]>,
): Promise<ResourceInstanceReference[]> {
const options = await fetchOptions();
const results = options.map((option: ResourceInstanceResult) => {
const result: ResourceInstanceReference = {
display_value: option.descriptors[selectedLanguage.value.code].name,
resourceId: option.resourceinstanceid,
ontologyProperty: "ac41d9be-79db-4256-b368-2f4559cfbe55",
inverseOntologyProperty: "ac41d9be-79db-4256-b368-2f4559cfbe55",
};
return result;
});
return results;
}
const languageOptions = ref<ControlledListItem[]>([]);
const typeOptions = ref<ControlledListItem[]>([]);
const statusOptions = ref<ControlledListItem[]>([]);
const metatypeOptions = ref<ControlledListItem[]>([]);
const eventTypeOptions = ref<ControlledListItem[]>([]);
const groupAndPersonOptions = ref<ResourceInstanceReference[]>();
const textualWorkOptions = ref<ResourceInstanceReference[]>();
onMounted(async () => {
const [languageOpts, typeOpts, statusOpts, metatypeOpts, eventTypeOpts] =
await Promise.all([
getOptions(LANGUAGE_CONTROLLED_LIST),
getOptions(LABEL_CONTROLLED_LIST),
getOptions(STATUSES_CONTROLLED_LIST),
getOptions(METATYPES_CONTROLLED_LIST),
getOptions(EVENT_TYPES_CONTROLLED_LIST),
getControlledListOptions(LANGUAGE_CONTROLLED_LIST),
getControlledListOptions(LABEL_CONTROLLED_LIST),
getControlledListOptions(STATUSES_CONTROLLED_LIST),
getControlledListOptions(METATYPES_CONTROLLED_LIST),
getControlledListOptions(EVENT_TYPES_CONTROLLED_LIST),
]);
languageOptions.value = languageOpts;
typeOptions.value = typeOpts;
statusOptions.value = statusOpts;
metatypeOptions.value = metatypeOpts;
eventTypeOptions.value = eventTypeOpts;
groupAndPersonOptions.value = await getResourceInstanceOptions(
fetchGroupRdmSystemList,
);
groupAndPersonOptions.value = [
...(groupAndPersonOptions.value || []),
...(await getResourceInstanceOptions(fetchPersonRdmSystemList)),
];
textualWorkOptions.value = await getResourceInstanceOptions(
fetchTextualWorkRdmSystemList,
);
});
</script>

Expand Down Expand Up @@ -125,10 +165,22 @@ onMounted(async () => {

<!-- Contributor: resource instance -->
<label for="">{{ $gettext("Contributor") }}</label>

<ResourceInstanceRelationships
:value="appellative_status?.appellative_status_data_assignment_actor"
:mode="EDIT"
:options="groupAndPersonOptions"
@update="onUpdate"
/>
<!-- Sources: resource instance -->
<label for="">{{ $gettext("Sources") }}</label>

<ResourceInstanceRelationships
:value="
appellative_status?.appellative_status_data_assignment_object_used
"
:mode="EDIT"
:options="textualWorkOptions"
@update="onUpdate"
/>
<!-- Warrant Type: reference datatype -->
<label for="">{{ $gettext("Warrant Type") }}</label>
<ReferenceDatatype
Expand Down
2 changes: 2 additions & 0 deletions arches_lingo/templates/arches_urls.htm
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@
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' %}"
api_group_list="{% url 'api-group-list' %}"
api_person_list="{% url 'api-person-list' %}"
></div>
{% endblock arches_urls %}
12 changes: 12 additions & 0 deletions arches_lingo/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
ConceptListCreateView,
ConceptStatementDetailView,
ConceptStatementListCreateView,
GroupRdmSystemSerializerView,
PersonRdmSystemSerializerView,
SchemeCreationView,
SchemeDetailView,
SchemeLabelTileView,
Expand Down Expand Up @@ -83,6 +85,16 @@
TextualWorkRdmSystemSerializerView.as_view(),
name="api-textualwork-list",
),
path(
"api/group-rdm-system",
GroupRdmSystemSerializerView.as_view(),
name="api-group-list",
),
path(
"api/person-rdm-system",
PersonRdmSystemSerializerView.as_view(),
name="api-person-list",
),
path(
"api/scheme/statements",
SchemeStatementListCreateView.as_view(),
Expand Down
16 changes: 15 additions & 1 deletion arches_lingo/views/api/pythonic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@

from arches_lingo.serializers import (
ConceptSerializer,
ConceptStatementSerializer,
GroupRdmSystemSerializer,
PersonRdmSystemSerializer,
SchemeCreationSerializer,
SchemeLabelSerializer,
SchemeLabelTileSerializer,
SchemeNamespaceSerializer,
SchemeNoteSerializer,
SchemeNoteTileSerializer,
SchemeSerializer,
ConceptStatementSerializer,
SchemeStatementSerializer,
TextualWorkRdmSystemSerializer,
)
Expand Down Expand Up @@ -84,6 +86,18 @@ class TextualWorkRdmSystemSerializerView(ArchesModelAPIMixin, ListAPIView):
pagination_class = None


class GroupRdmSystemSerializerView(ArchesModelAPIMixin, ListAPIView):
permission_classes = [RDMAdministrator]
serializer_class = GroupRdmSystemSerializer
pagination_class = None


class PersonRdmSystemSerializerView(ArchesModelAPIMixin, ListAPIView):
permission_classes = [RDMAdministrator]
serializer_class = PersonRdmSystemSerializer
pagination_class = None


class ConceptDetailView(ArchesModelAPIMixin, RetrieveUpdateDestroyAPIView):
permission_classes = [RDMAdministrator]
serializer_class = ConceptSerializer
Expand Down

0 comments on commit da263b3

Please sign in to comment.