Skip to content

Commit

Permalink
feat: ✨ license editor and selector created for dataset rights page
Browse files Browse the repository at this point in the history
  • Loading branch information
slugb0t committed Dec 27, 2023
1 parent 6a259e4 commit 4b1d354
Showing 1 changed file with 43 additions and 19 deletions.
62 changes: 43 additions & 19 deletions src/views/study/dataset/metadata/rights/DatasetMetadataRights.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const router = useRouter();
const push = usePush();
const displayLicenseEditor = ref(false);
const draftLicense = ref("");
const licenseName = ref("");
const routeParams = {
datasetId: route.params.datasetId as string,
Expand Down Expand Up @@ -43,11 +44,20 @@ onBeforeMount(async () => {
console.log(data);
moduleData.rights = data.map((item: any) => {
console.log(item);
return {
...item,
origin: "remote",
};
});
console.log(moduleData.rights.length);
if (moduleData.rights.length > 0) {
draftLicense.value = moduleData.rights[0].license_text;
console.log(moduleData.rights[0].rights);
licenseName.value = moduleData.rights[0].rights;
console.log(licenseName.value);
displayLicenseEditor.value = true;
}
});
const removeRight = async (id: string) => {
Expand Down Expand Up @@ -91,8 +101,8 @@ const saveMetadata = (e: MouseEvent) => {
const data: any = moduleData.rights.map((item) => {
const entry = {
identifier: item.identifier || "",
identifier_scheme: item.identifier_scheme || "",
license_text: item.license_text || "",
identifier_scheme: draftLicense.value !== "" ? "SPDX" : "",
license_text: draftLicense.value || "",
rights: item.rights,
uri: item.uri || "",
};
Expand All @@ -106,6 +116,7 @@ const saveMetadata = (e: MouseEvent) => {
};
}
});
console.log(data);
const response = await fetch(
`${baseURL}/study/${studyId}/dataset/${datasetId}/metadata/rights`,
Expand Down Expand Up @@ -141,20 +152,7 @@ const updateLicense = async (value: string) => {
const license = licensesJSON.find((item) => item.name === value);
if (license) {
// if (moduleData.rights.length === 0) {
// moduleData.rights.push({
// id: nanoid(),
// identifier: license.licenseId,
// identifier_scheme: "SPDX",
// rights: license.name,
// uri: license.reference,
// });
// }
// moduleData.rights[0].rights = license.name;
// moduleData.rights[0].uri = license.reference;
// moduleData.rights[0].identifier = license.licenseId;
// moduleData.rights[0].identifier_scheme = "SPDX";
console.log(`${baseURL}/utils/requestjson?url=${encodeURIComponent(license.detailsUrl)}`);
const response = await fetch(
`${baseURL}/utils/requestjson?url=${encodeURIComponent(license.detailsUrl)}`,
{
Expand All @@ -167,10 +165,35 @@ const updateLicense = async (value: string) => {
if (response.ok) {
const response_data = await response.json();
// console.log(response_data);
console.log(response_data.licenseText);
draftLicense.value = response_data.licenseText;
licenseName.value = license.name;
displayLicenseEditor.value = true;
loading.value = false;
if (moduleData.rights.length === 0) {
moduleData.rights.push({
id: nanoid(),
identifier: license.licenseId,
identifier_scheme: "SPDX",
license_text: draftLicense.value,
origin: "local",
rights: license.name,
uri: license.reference,
});
} else {
console.log(moduleData);
console.log(moduleData.rights[0]);
console.log(moduleData.rights[0].rights);
moduleData.rights[0] = {
...moduleData.rights[0],
identifier: license.licenseId,
identifier_scheme: "SPDX",
rights: license.name,
uri: license.reference,
};
}
console.log(moduleData.rights);
console.log(license.name);
} else {
console.error("Failed to fetch license details:", response.status, response.statusText);
}
Expand All @@ -192,18 +215,19 @@ const updateLicense = async (value: string) => {
<n-form ref="formRef" :model="moduleData" size="large" label-placement="top" class="pr-4">
<n-form-item label="Rights" path="rights">
<n-select
v-model:value="moduleData.rights"
v-model="licenseName"
placeholder="MIT License Modern Variant."
clearable
:options="licensesJSON.map((option) => ({ label: option.name, value: option.name }))"
@update:value="updateLicense"
:value="licenseName !== '' ? licenseName : ''"
/>
</n-form-item>

<div v-if="displayLicenseEditor" class="pb-5">
<v-md-editor
v-model="draftLicense"
height="400px"
height="800px"
left-toolbar="undo redo clear | h bold italic strikethrough | ul ol table hr | link"
right-toolbar="sync-scroll preview fullscreen"
></v-md-editor>
Expand Down

0 comments on commit 4b1d354

Please sign in to comment.