-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add right holder to scheme rights, #151
- Loading branch information
Showing
8 changed files
with
222 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 112 additions & 7 deletions
119
arches_lingo/src/arches_lingo/components/scheme/report/SchemeLicense.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,124 @@ | ||
<script setup lang="ts"> | ||
import { inject, onMounted, ref, type Ref } from "vue"; | ||
import { useRoute } from "vue-router"; | ||
import { useGettext } from "vue3-gettext"; | ||
import SchemeReportSection from "@/arches_lingo/components/scheme/report/SchemeSection.vue"; | ||
const save = () => { | ||
console.log("save"); | ||
import { | ||
fetchSchemeRights, | ||
updateSchemeRights, | ||
fetchPersonRdmSystemList, | ||
fetchGroupRdmSystemList, | ||
} from "@/arches_lingo/api.ts"; | ||
import type { | ||
DataComponentMode, | ||
ResourceInstanceReference, | ||
ResourceInstanceResult, | ||
SchemeInstance, | ||
} from "@/arches_lingo/types"; | ||
import { selectedLanguageKey, VIEW, EDIT } from "@/arches_lingo/constants.ts"; | ||
import ResourceInstanceRelationships from "../../generic/ResourceInstanceRelationships.vue"; | ||
import type { Language } from "@/arches_vue_utils/types.ts"; | ||
onMounted(async () => { | ||
getSectionValue(); | ||
}); | ||
defineEmits(["openEditor"]); | ||
defineProps<{ | ||
mode?: DataComponentMode; | ||
}>(); | ||
const schemeRights = ref<SchemeInstance>(); | ||
const route = useRoute(); | ||
const actorRdmOptions = ref<ResourceInstanceReference[]>(); | ||
const selectedLanguage = inject(selectedLanguageKey) as Ref<Language>; | ||
async function getOptions(): Promise<ResourceInstanceReference[]> { | ||
const options_person = await fetchPersonRdmSystemList(); | ||
const options_group = await fetchGroupRdmSystemList(); | ||
const options = options_person.concat(options_group); | ||
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; | ||
}; | ||
function onSchemeRightsUpdate(val: string[]) { | ||
const schemeRightsValue = schemeRights.value!; | ||
console.log(schemeRightsValue); | ||
if (actorRdmOptions.value) { | ||
const options = actorRdmOptions.value?.filter((option) => | ||
val.includes(option.resourceId), | ||
); | ||
if (!schemeRightsValue?.rights) { | ||
schemeRightsValue.rights = { | ||
right_holder: options, | ||
}; | ||
} else { | ||
schemeRightsValue.rights.right_holder = options; | ||
} | ||
} | ||
}; | ||
const getSectionValue = async () => { | ||
console.log("update"); | ||
async function save() { | ||
await updateSchemeRights( | ||
route.params.id as string, | ||
schemeRights.value as SchemeInstance, | ||
); | ||
}; | ||
async function getSectionValue() { | ||
const options = !actorRdmOptions.value | ||
? await getOptions() | ||
: actorRdmOptions.value; | ||
const scheme = await fetchSchemeRights(route.params.id as string); | ||
const hydratedResults = options.map((option) => { | ||
const savedSource = scheme.rights?.right_holder.find( | ||
(source: ResourceInstanceReference) => | ||
source.resourceId === option.resourceId, | ||
); | ||
if (savedSource) { | ||
return savedSource; | ||
} else { | ||
return option; | ||
} | ||
}); | ||
actorRdmOptions.value = hydratedResults; | ||
schemeRights.value = scheme; | ||
}; | ||
defineExpose({ save, getSectionValue }); | ||
const { $gettext } = useGettext(); | ||
</script> | ||
|
||
<template> | ||
<SchemeReportSection :title-text="$gettext('License')"> | ||
abc | ||
</SchemeReportSection> | ||
<div> | ||
<div v-if="!mode || mode === VIEW"> | ||
<SchemeReportSection | ||
:title-text="$gettext('Scheme Rights')" | ||
@open-editor="$emit('openEditor')" | ||
> | ||
<h4>{{ $gettext('Rights Holders') }}</h4> | ||
<ResourceInstanceRelationships | ||
:value="schemeRights?.rights?.right_holder" | ||
:mode="VIEW" | ||
/> | ||
</SchemeReportSection> | ||
</div> | ||
<div v-if="mode === EDIT"> | ||
<h4>{{ $gettext('Rights Holders') }}</h4> | ||
<ResourceInstanceRelationships | ||
:value="schemeRights?.rights?.right_holder" | ||
:options="actorRdmOptions" | ||
:mode="EDIT" | ||
@update="onSchemeRightsUpdate" | ||
/> | ||
</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters