Skip to content

Commit

Permalink
wip: contributors GM
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronm-2112 committed Nov 10, 2023
1 parent 84ac02e commit 75de157
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 14 deletions.
2 changes: 1 addition & 1 deletion scripts/guided-mode/guided-curate-dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -9001,7 +9001,7 @@ const handleAddContributorHeaderUI = () => {
`;
};

const openGuidedAddContributorSwal = async () => {
const window.openGuidedAddContributorSwal = async () => {
let affiliationTagify;
let contributorRolesTagify;

Expand Down
2 changes: 1 addition & 1 deletion sections/guided_mode/guided_curate_dataset.html
Original file line number Diff line number Diff line change
Expand Up @@ -2698,7 +2698,7 @@ <h2 class="text-sub-step-title mb-0">
<button
class="ui primary basic button mt-sm"
id="guided-button-add-contributor"
onclick="openGuidedAddContributorSwal(false)"
onclick="window.openGuidedAddContributorSwal(false)"
>
<i class="fas fa-plus" style="margin-right: 7px"></i>Add a new contributor
</button>
Expand Down
1 change: 1 addition & 0 deletions src/renderer/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import './scripts/organize-dataset/organizeDS'
import './scripts/organize-dataset/curate-functions'
import './scripts/metadata-files/manifest'
import './scripts/spreadSheetTools/spreadSheetTools'
import './scripts/others/contributor-storage'

// Application Lotties
import './assets/lotties/activate-lotties'
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/src/scripts/guided-mode/guided-curate-dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -8939,7 +8939,7 @@ const openGuidedEditContributorSwal = async (contibuttorOrcidToEdit) => {

const handleAddContributorHeaderUI = () => {
const existingContributorORCiDs = getExistingContributorORCiDs();
const locallyStoredContributorArray = loadStoredContributors().filter((contributor) => {
const locallyStoredContributorArray = window.loadStoredContributors().filter((contributor) => {
return !existingContributorORCiDs.includes(contributor.ORCiD);
});

Expand Down Expand Up @@ -9000,7 +9000,7 @@ const handleAddContributorHeaderUI = () => {
`;
};

const openGuidedAddContributorSwal = async () => {
window.openGuidedAddContributorSwal = async () => {
let affiliationTagify;
let contributorRolesTagify;

Expand Down
90 changes: 90 additions & 0 deletions src/renderer/src/scripts/others/contributor-storage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
while (!window.htmlPagesAdded) {
await new Promise((resolve) => setTimeout(resolve, 100))
}

const storedContributorsPath = window.path.join(window.homeDirectory, "SODA", "stored-contributors.json");

// Save the contributors array to the JSON file
const saveStoredContributors = (contributors) => {
try {
window.fs.writeFileSync(storedContributorsPath, JSON.stringify(contributors));
} catch (err) {
window.log.info("Error saving stored contributors file: " + err);
}
};

// Load the stored contributors array from the JSON file
// If the file doesn't exist, return an empty array
window.loadStoredContributors = () => {
try {
const contributorFileData = window.fs.readFileSync(storedContributorsPath);
return JSON.parse(contributorFileData);
} catch (err) {
return [];
}
};

// Add a new contributor to the JSON file
// If a contributor with the same ORCiD already exists, update the existing contributor
const addOrUpdateStoredContributor = (
firstName,
lastName,
ORCiD,
affiliationsArray,
rolesArray
) => {
if (typeof firstName !== "string" || !firstName.length > 0) {
window.log.info("Attempted to add contributor with invalid first name");
return;
}
if (typeof lastName !== "string" || !lastName.length > 0) {
window.log.info("Attempted to add contributor with invalid last name");
return;
}
if (typeof ORCiD !== "string" || !ORCiD.length > 0) {
window.log.info("Attempted to add contributor with invalid ORCiD");
return;
}
if (!Array.isArray(affiliationsArray) || affiliationsArray.length === 0) {
window.log.info("Invalid affiliations array");
return;
}
if (!Array.isArray(rolesArray) || rolesArray.length === 0) {
window.log.info("Invalid roles array");
return;
}

// If the stored contributors file doesn't exist, create it and write an empty array to it
if (!window.fs.existsSync(storedContributorsPath)) {
try {
window.fs.writeFileSync(storedContributorsPath, "[]");
} catch (err) {
window.log.info("Error creating stored contributors file: " + err);
return;
}
}

const contributorObj = {
firstName: firstName,
lastName: lastName,
ORCiD: ORCiD,
affiliations: affiliationsArray,
roles: rolesArray,
};

const storedContributorsArray = window.loadStoredContributors();

const existingStoredContributorWithSameORCiDIndex = storedContributorsArray.findIndex(
(contributorObj) => contributorObj.ORCiD === ORCiD
);

// If a contributor with the same ORCiD already exists, update the existing contributor
if (existingStoredContributorWithSameORCiDIndex >= 0) {
storedContributorsArray[existingStoredContributorWithSameORCiDIndex] = contributorObj;
} else {
// If a contributor with the same ORCiD doesn't exist, add the new contributor
storedContributorsArray.push(contributorObj);
}
// Write the updated array to the JSON file
saveStoredContributors(storedContributorsArray);
};
18 changes: 9 additions & 9 deletions src/renderer/src/scripts/others/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ let introStatus = {

// // Log file settings //
window.log.setupRendererLogOptions()
const homeDirectory = await window.electron.ipcRenderer.invoke('get-app-path', 'home')
window.homeDirectory = await window.electron.ipcRenderer.invoke('get-app-path', 'home')



Expand Down Expand Up @@ -1371,28 +1371,28 @@ dragselect_area.subscribe("dragstart", ({ items, event, isDragging }) => {
// ///// Global variables for this section

// /////// Save and load award and milestone info
// let metadataPath = window.path.join(homeDirectory, "SODA", "METADATA");
// let metadataPath = window.path.join(window.homeDirectory, "SODA", "METADATA");
// let awardFileName = "awards.json";
// let affiliationFileName = "affiliations.json";
// let milestoneFileName = "milestones.json";
// let protocolConfigFileName = "protocol-config.json";
// let affiliationConfigPath = window.path.join(metadataPath, affiliationFileName);
// let milestonePath = window.path.join(metadataPath, milestoneFileName);
window.progressFilePath = window.path.join(homeDirectory, "SODA", "Progress");
// let guidedProgressFilePath = window.path.join(homeDirectory, "SODA", "Guided-Progress");
// const guidedManifestFilePath = window.path.join(homeDirectory, "SODA", "guided_manifest_files");
window.progressFilePath = window.path.join(window.homeDirectory, "SODA", "Progress");
// let guidedProgressFilePath = window.path.join(window.homeDirectory, "SODA", "Guided-Progress");
// const guidedManifestFilePath = window.path.join(window.homeDirectory, "SODA", "guided_manifest_files");
// let protocolConfigPath = window.path.join(metadataPath, protocolConfigFileName);
// let allCollectionTags = {};
// let currentTags = {};
// let currentCollectionTags = [];

// if (process.platform === "linux") {
// //check if data exists inside of the Soda folder, and if it does, move it into the capitalized SODA folder
// if (fs.existsSync(window.path.join(homeDirectory, "Soda"))) {
// if (fs.existsSync(window.path.join(window.homeDirectory, "Soda"))) {
// //copy the folder contents of home/Soda to home/SODA
// fs.copySync(window.path.join(homeDirectory, "Soda"), window.path.join(homeDirectory, "SODA"));
// fs.copySync(window.path.join(window.homeDirectory, "Soda"), window.path.join(window.homeDirectory, "SODA"));
// //delete the old folder
// fs.removeSync(window.path.join(homeDirectory, "Soda"));
// fs.removeSync(window.path.join(window.homeDirectory, "Soda"));
// }
// }

Expand Down Expand Up @@ -5295,7 +5295,7 @@ const addDataArrayToDatasetStructureAtPath = async (importedData) => {
// let original_image_path = path[0];
// let image_path = original_image_path;
// let destination_image_path = require("path").join(
// homeDirectory,
// window.homeDirectory,
// "SODA",
// "banner-image-conversion"
// );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2693,7 +2693,7 @@ <h2 class="text-sub-step-title mb-0">
<button
class="ui primary basic button mt-sm"
id="guided-button-add-contributor"
onclick="openGuidedAddContributorSwal(false)"
onclick="window.openGuidedAddContributorSwal(false)"
>
<i class="fas fa-plus" style="margin-right: 7px"></i>Add a new contributor
</button>
Expand Down

0 comments on commit 75de157

Please sign in to comment.