Skip to content

Commit

Permalink
Fix scheme rights statement, #151
Browse files Browse the repository at this point in the history
  • Loading branch information
njkim committed Jan 22, 2025
1 parent c90620b commit 79a9a92
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
4 changes: 3 additions & 1 deletion arches_lingo/src/arches_lingo/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,16 +333,18 @@ export const deleteSchemeRights = async (

export const createSchemeRightStatement = async (
schemeId: string,
parentTileId: string,
schemeRightStatementValue: SchemeRightStatement,
) => {
const response = await fetch(arches.urls.api_scheme_right_statement_tile_create, {
method: "PATCH",
method: "POST",
headers: {
"X-CSRFTOKEN": getToken(),
"Content-Type": "application/json",
},
body: JSON.stringify({
resourceinstance: schemeId,
parenttile: parentTileId,
...schemeRightStatementValue,
}),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ const rightTypeOptions = ref<ControlledListItem[]>();
const languageOptions = ref<ControlledListItem[]>();
const noteOptions = ref<ControlledListItem[]>();
const metatypesOptions = ref<ControlledListItem[]>();
const editingStatement = ref<boolean>(false);
const editingStatement = ref(false);
const parentExists = ref(false);
const props = withDefaults(
defineProps<{
Expand All @@ -80,19 +81,14 @@ const props = withDefaults(
const schemeRights = ref<SchemeRights>();
const schemeRightStatement = ref<SchemeRightStatement[]>();
const rightsTileId = ref<string>();
const rightStatementTileId = ref<string>();
const selectedSchemeRightStatement = computed(() => {
const selected = schemeRightStatement.value?.find(
(tile) => tile.tileid === props.tileId
);
if (!selected) {
return {
tileid: "",
right_statement_content: "",
right_statement_label: "",
right_statement_language: [],
right_statement_type: [],
right_statement_type_metatype: [],
} as SchemeRightStatement;
return {} as SchemeRightStatement;
} else { return selected; }
},
);
Expand Down Expand Up @@ -195,9 +191,16 @@ async function saveRights() {
}
async function saveRightStatement() {
if (!selectedSchemeRightStatement.value) {
return;
}
try {
if (!selectedSchemeRightStatement.value?.tileid) {
await createSchemeRightStatement(route.params.id as string, selectedSchemeRightStatement.value);
await createSchemeRightStatement(
route.params.id as string,
rightStatementTileId.value ?? '',
selectedSchemeRightStatement.value
);
} else {
await updateSchemeRightStatement(
route.params.id as string,
Expand All @@ -221,10 +224,15 @@ async function getSectionValue() {
}
const actorOptions = await getActorOptions();
const schemeInstance = await fetchSchemeRights(route.params.id as string);
rightsTileId.value = schemeInstance?.rights?.tileid ?? '';
rightStatementTileId.value = schemeInstance?.right_statement?.tileid ?? '';
if (schemeInstance?.right_statement && !Array.isArray(schemeInstance?.right_statement)) {
schemeInstance.right_statement = [schemeInstance.right_statement];
}
schemeRights.value = schemeInstance?.rights;
schemeRights.value = schemeInstance?.rights ?? {};
if (schemeInstance?.rights) {
parentExists.value = true;
}
schemeRightStatement.value = schemeInstance?.right_statement;
actorRdmOptions.value = actorOptions.map((option) => {
const savedSource = schemeRights.value?.right_holder?.find(
Expand Down Expand Up @@ -263,6 +271,10 @@ async function deleteStatementValue(tileId: string) {
}
};
function addStatementValue() {
editingStatement.value = true;
};
function editStatementValue(tileId: string) {
editingStatement.value = true;
const selectedSchemeRightStatement = schemeRightStatement.value?.find(
Expand Down Expand Up @@ -362,7 +374,7 @@ defineExpose({ getSectionValue });
</SchemeReportSection>
</div>
<div v-if="mode === EDIT">
<div v-if="!editingStatement">
<div>
<h4>{{ $gettext('Rights Holders') }}</h4>
<ResourceInstanceRelationships
:value="schemeRights?.right_holder"
Expand All @@ -382,8 +394,13 @@ defineExpose({ getSectionValue });
:label="$gettext('Update')"
@click="saveRights"
></Button>
<Button
if-show="parentExists"
:label="$gettext('Add Scheme Right Statement')"
@click="addStatementValue"
></Button>
</div>
<div v-if="!editingStatement">
<div v-show="editingStatement">
<h4>{{ $gettext('Statement') }}</h4>
<NonLocalizedString
:value="selectedSchemeRightStatement?.right_statement_content"
Expand Down

0 comments on commit 79a9a92

Please sign in to comment.