Skip to content

Commit

Permalink
wip: GM upload dataset files uploads begins
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronm-2112 committed Nov 15, 2023
1 parent 94f02bb commit 6c92b60
Show file tree
Hide file tree
Showing 14 changed files with 4,233 additions and 323 deletions.
14 changes: 7 additions & 7 deletions scripts/guided-mode/guided-curate-dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -3230,23 +3230,23 @@ const updateManifestJson = async (highLvlFolderName, result) => {

const guidedCreateManifestFilesAndAddToDatasetStructure = async () => {
// First, empty the guided_manifest_files so we can add the new manifest files
fs.emptyDirSync(guidedManifestFilePath);
fs.emptyDirSync(window.guidedManifestFilePath);

const guidedManifestData = sodaJSONObj["guided-manifest-files"];
for (const [highLevelFolder, manifestData] of Object.entries(guidedManifestData)) {
let manifestJSON = processManifestInfo(
let manifestJSON = window.processManifestInfo(
guidedManifestData[highLevelFolder]["headers"],
guidedManifestData[highLevelFolder]["data"]
);
jsonManifest = JSON.stringify(manifestJSON);

const manifestPath = path.join(guidedManifestFilePath, highLevelFolder, "manifest.xlsx");
const manifestPath = path.join(window.guidedManifestFilePath, highLevelFolder, "manifest.xlsx");

fs.mkdirSync(path.join(guidedManifestFilePath, highLevelFolder), {
fs.mkdirSync(path.join(window.guidedManifestFilePath, highLevelFolder), {
recursive: true,
});

convertJSONToXlsx(JSON.parse(jsonManifest), manifestPath);
window.convertJSONToXlsx(JSON.parse(jsonManifest), manifestPath);
datasetStructureJSONObj["folders"][highLevelFolder]["files"]["manifest.xlsx"] = {
action: ["new"],
path: manifestPath,
Expand Down Expand Up @@ -13726,7 +13726,7 @@ const openGuidedDatasetRenameSwal = async () => {
};

const guidedUploadDatasetToPennsieve = async () => {
updateJSONStructureDSstructure();
window.updateJSONStructureDSstructure();

// Initiate curation by calling Python function
let manifest_files_requested = false;
Expand All @@ -13751,7 +13751,7 @@ const guidedUploadDatasetToPennsieve = async () => {
dataset_name = sodaJSONObj["digital-metadata"]["name"];
sodaJSONObj["bf-dataset-selected"] = {};
sodaJSONObj["bf-dataset-selected"]["dataset-name"] = dataset_name;
sodaJSONObj["bf-account-selected"]["account-name"] = window.defaultBfDataset;
sodaJSONObj["bf-account-selected"]["account-name"] = window.defaultBfAccount;
dataset_destination = "Pennsieve";
}

Expand Down
14 changes: 7 additions & 7 deletions scripts/metadata-files/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,9 @@ $(document).ready(function () {
})["Sheet1"];
}
// If file doesn't exist then that means it didn't get imported properly
let sortedJSON = processManifestInfo(manifestHeader, manifestFileData);
let sortedJSON = window.processManifestInfo(manifestHeader, manifestFileData);
jsonManifest = JSON.stringify(sortedJSON);
convertJSONToXlsx(JSON.parse(jsonManifest), selectedManifestFilePath);
window.convertJSONToXlsx(JSON.parse(jsonManifest), selectedManifestFilePath);
}
}

Expand Down Expand Up @@ -465,7 +465,7 @@ $(document).ready(function () {

// Header and data should be formatted correctly

let sortedJSON = processManifestInfo(manifestHeader, manifestData);
let sortedJSON = window.processManifestInfo(manifestHeader, manifestData);
sodaCopy["manifest-files"][highLevelFolderName] = {
headers: manifestHeader,
data: manifestData,
Expand Down Expand Up @@ -542,9 +542,9 @@ $(document).ready(function () {
},
})["Sheet1"];

let sortedJSON = processManifestInfo(savedHeaders, savedData);
let sortedJSON = window.processManifestInfo(savedHeaders, savedData);
jsonManifest = JSON.stringify(sortedJSON);
convertJSONToXlsx(JSON.parse(jsonManifest), selectedManifestFilePath);
window.convertJSONToXlsx(JSON.parse(jsonManifest), selectedManifestFilePath);
//Update the metadata in json object
// If extra columns are added preserve them into sodaJSONObj
for (let i = 0; i < savedData.length; i++) {
Expand Down Expand Up @@ -691,7 +691,7 @@ window.smoothScrollToElement = (idOrElement, block = "start", inline = "nearest"
}
};

const processManifestInfo = (headers, data) => {
const window.processManifestInfo = (headers, data) => {
let sortedArr = [];
// sort json data by appending ordered entries (by columns) to each object's element
for (let i = 0; i < data.length; i++) {
Expand Down Expand Up @@ -739,7 +739,7 @@ const createWorkbookStyle = (wb, color) => {
});
};

const convertJSONToXlsx = (jsondata, excelfile) => {
const window.convertJSONToXlsx = (jsondata, excelfile) => {
const requiredManifestHeaders = [
"filename",
"timestamp",
Expand Down
8 changes: 4 additions & 4 deletions scripts/organize-dataset/curate-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1758,9 +1758,9 @@ const ffOpenManifestEditSwal = async (highlevelFolderName) => {
},
})["Sheet1"];

let sortedJSON = processManifestInfo(savedHeaders, savedData);
let sortedJSON = window.processManifestInfo(savedHeaders, savedData);
jsonManifest = JSON.stringify(sortedJSON);
convertJSONToXlsx(JSON.parse(jsonManifest), selectedManifestFilePath);
window.convertJSONToXlsx(JSON.parse(jsonManifest), selectedManifestFilePath);
//Update the metadata in json object
for (let i = 0; i < savedData.length; i++) {
let fileName = savedData[i][0];
Expand Down Expand Up @@ -1912,9 +1912,9 @@ const ffmCreateManifest = async (sodaJson) => {
}
// If file doesn't exist then that means it didn't get imported properly

let sortedJSON = processManifestInfo(manifestHeader, manifestFileData);
let sortedJSON = window.processManifestInfo(manifestHeader, manifestFileData);
jsonManifest = JSON.stringify(sortedJSON);
convertJSONToXlsx(JSON.parse(jsonManifest), selectedManifestFilePath);
window.convertJSONToXlsx(JSON.parse(jsonManifest), selectedManifestFilePath);
}
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/others/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1635,7 +1635,7 @@ let affiliationConfigPath = path.join(metadataPath, affiliationFileName);
let milestonePath = path.join(metadataPath, milestoneFileName);
let progressFilePath = path.join(homeDirectory, "SODA", "Progress");
let guidedProgressFilePath = path.join(homeDirectory, "SODA", "Guided-Progress");
const guidedManifestFilePath = path.join(homeDirectory, "SODA", "guided_manifest_files");
const window.guidedManifestFilePath = path.join(homeDirectory, "SODA", "guided_manifest_files");
let protocolConfigPath = path.join(metadataPath, protocolConfigFileName);
let allCollectionTags = {};
let currentTags = {};
Expand Down
14 changes: 7 additions & 7 deletions scripts/others/tab-effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -3043,14 +3043,14 @@ const populateOrganizeDatasetUI = (currentLocation, datasetFolder) => {

// Step 3: Dataset structure

const updateJSONStructureDSstructure = () => {
sodaJSONObj["dataset-structure"] = datasetStructureJSONObj;
window.updateJSONStructureDSstructure = () => {
window.sodaJSONObj["dataset-structure"] = window.datasetStructureJSONObj;
// check if dataset-structure key is empty (no high-level folders are included)
if (
JSON.stringify(sodaJSONObj["dataset-structure"]) === "{}" ||
JSON.stringify(sodaJSONObj["dataset-structure"]["folders"]) === "{}"
JSON.stringify(window.sodaJSONObj["dataset-structure"]) === "{}" ||
JSON.stringify(window.sodaJSONObj["dataset-structure"]["folders"]) === "{}"
) {
delete sodaJSONObj["dataset-structure"];
delete window.sodaJSONObj["dataset-structure"];
}
};

Expand Down Expand Up @@ -3360,7 +3360,7 @@ const updateOverallJSONStructure = (id) => {
} else if (id === allParentStepsJSON["manifest-file"]) {
updateJSONStructureManifest();
} else if (id === allParentStepsJSON["organize-dataset"]) {
updateJSONStructureDSstructure();
window.updateJSONStructureDSstructure();
}
};
//////////////////////////////// END OF Functions to update JSON object //////////////////////////////////////////
Expand Down Expand Up @@ -3579,7 +3579,7 @@ const updateJSONObjectProgress = () => {
// updateJSONStructureGettingStarted();
updateJSONStructureMetadataFiles();
updateJSONStructureManifest();
updateJSONStructureDSstructure();
window.updateJSONStructureDSstructure();
updateJSONStructureGenerate(true, sodaJSONObj);
};

Expand Down
1 change: 1 addition & 0 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {spawn, execFile} from "node:child_process"
import { existsSync } from 'fs'
import { JSONStorage } from "node-localstorage";
import log from 'electron-log/main';
import "./manifest-workbook"

import "./main-process/native-ui/dialogs/open-file"

Expand Down
107 changes: 107 additions & 0 deletions src/main/manifest-workbook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { ipcMain, app } from "electron";
import excel4node from "excel4node";



ipcMain.handle("convertJSONToSxlsx", async (jsondata, excelfile) => {
return await convertJSONToXlsx(jsondata, excelfile);
})


const convertJSONToXlsx = async (jsondata, excelfile) => {
const requiredManifestHeaders = [
"filename",
"timestamp",
"description",
"file type",
"Additional Metadata",
];
const blueHeader = ["filename", "File Name", "file name"];
const greenHeader = ["timestamp", "description", "file type"];
const yellowHeader = ["Additional Metadata"];
const wb = new excel4node.Workbook();
// create wb style that makes the background styling
const greenHeaderStyle = createWorkbookStyle(wb, "a8d08d");
const yellowHeaderStyle = createWorkbookStyle(wb, "ffd965");
const blueHeaderStyle = createWorkbookStyle(wb, "A0C2E6");
const standardCellStyle = wb.createStyle({
font: {
bold: false,
color: "#000000",
size: 12,
name: "Calibri",
},
});

const wsOptions = {
sheetFormat: {
defaultColWidth: 20,
},
};
const ws = wb.addWorksheet("Sheet1", wsOptions);
const headingColumnNames = Object.keys(jsondata[0]);
//Write Column Title in Excel file
let headingColumnIndex = 1;
headingColumnNames.forEach((heading) => {
let styleObject = yellowHeaderStyle;
if (blueHeader.includes(heading)) {
styleObject = blueHeaderStyle;
}
if (yellowHeader.includes(heading)) {
styleObject = yellowHeaderStyle;
}
if (greenHeader.includes(heading)) {
styleObject = greenHeaderStyle;
}

ws.cell(1, headingColumnIndex++)
.string(heading)
.style(styleObject);
});
//Write Data in Excel file
let rowIndex = 2;
jsondata.forEach((record) => {
let columnIndex = 1;
Object.keys(record).forEach((columnName) => {
ws.cell(rowIndex, columnIndex++)
.string(record[columnName])
.style(standardCellStyle);
});
rowIndex++;
});
wb.write(excelfile);
}

const createWorkbookStyle = (wb, color) => {
return wb.createStyle({
fill: {
type: "pattern",
patternType: "solid",
fgColor: color,
},
font: {
bold: true,
color: "#000000",
size: 12,
name: "Calibri",
},
border: {
left: {
style: "thin",
color: "#000000",
},
right: {
style: "thin",
color: "#000000",
},
top: {
style: "thin",
color: "#000000",
},
bottom: {
style: "thin",
color: "#000000",
},
},
});
};
1 change: 1 addition & 0 deletions src/preload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import logger from 'electron-log/renderer'
import imageDataURI from "image-data-uri" // TODO: fix this
import Jimp from "jimp";
import excel4node from "excel4node";
// import * as excel4node from 'excel4node';
import { spawn } from "node:child_process"

import "v8-compile-cache";
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 @@ -13,6 +13,7 @@ import './scripts/metadata-files/manifest'
import './scripts/spreadSheetTools/spreadSheetTools'
import './scripts/others/contributor-storage'
import './scripts/metadata-files/subjects-samples'
import './scripts/others/tab-effects'

// Application Lotties
import './assets/lotties/activate-lotties'
Expand Down
Loading

0 comments on commit 6c92b60

Please sign in to comment.