Skip to content

Commit

Permalink
fix: generate template ffm
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronm-2112 committed Jan 18, 2024
1 parent f7d405e commit f2d9ecf
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import "./strain"
import "./checkDiskSpace"
import "./spreadsheet-import-gm"
import "./shell"
import "./templates"


const sodaVersion = app.getVersion();
Expand Down
3 changes: 3 additions & 0 deletions src/main/main-process/native-ui/dialogs/open-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,9 @@ ipcMain.on("open-folder-dialog-save-metadata", async (event, filename) => {
}
});




// Generate submission file
ipcMain.on("open-folder-dialog-save-submission", async (event, filename) => {
let mainWindow = BrowserWindow.getFocusedWindow();
Expand Down
11 changes: 11 additions & 0 deletions src/main/templates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ipcMain } from "electron";
import fs from "fs"

ipcMain.handle("write-template", async (event, templatePath, destinationPath) => {
return fs.createReadStream(templatePath).pipe(fs.createWriteStream(destinationPath))
})


ipcMain.handle("get-current-directory", async (event) => {
return __dirname
})
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions src/renderer/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import './scripts/metadata-files/datasetDescription'
import './scripts/metadata-files/readme-changes'
import "./scripts/organize-dataset/validation-functions"
import "./scripts/collections/collections"
import "./scripts/metadata-files/downloadTemplates"

// Application Lotties
import './assets/lotties/activate-lotties'
Expand Down
45 changes: 27 additions & 18 deletions src/renderer/src/scripts/metadata-files/downloadTemplates.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// This file is used to download the metadata templates
// from the SODA-FOR-SPARC folder and save them to the local file system.
import kombuchaEnums from "../analytics/analytics-enums"
import Swal from "sweetalert2"

while (!window.htmlPagesAdded) {
await new Promise((resolve) => setTimeout(resolve, 100))
}

// Metadata Templates //
const downloadSubmission = document.getElementById("a-submission");
Expand All @@ -17,11 +23,14 @@ let templateArray = [
"DataDeliverablesDocument-template.docx",
];

const downloadTemplates = (templateItem, destinationFolder) => {
let templatePath = path.join(__dirname, "file_templates", templateItem);
let destinationPath = path.join(destinationFolder, templateItem);
const downloadTemplates = async (templateItem, destinationFolder) => {
let currentDirectory = await window.electron.ipcRenderer.invoke("get-current-directory");
let templatePath = window.path.join(currentDirectory, "..", "renderer", "file_templates", templateItem);
console.log(templatePath)
let destinationPath = window.path.join(destinationFolder, templateItem);
console.log(destinationPath)

if (fs.existsSync(destinationPath)) {
if (window.fs.existsSync(destinationPath)) {
let emessage = "File '" + templateItem + "' already exists in " + destinationFolder;
Swal.fire({
icon: "error",
Expand All @@ -31,13 +40,13 @@ const downloadTemplates = (templateItem, destinationFolder) => {
backdrop: "rgba(0,0,0, 0.4)",
});

ipcRenderer.send("track-event", "Error", `Download Template - ${templateItem}`);
window.electron.ipcRenderer.send("track-event", "Error", `Download Template - ${templateItem}`);

let templateLabel = Object.values(kombuchaEnums.Label).find((label) => {
return label === templateItem;
});

ipcRenderer.send(
window.electron.ipcRenderer.send(
"track-kombucha",
kombuchaEnums.Category.PREPARE_METADATA,
kombuchaEnums.Action.DOWNLOAD_TEMPLATES,
Expand All @@ -48,7 +57,7 @@ const downloadTemplates = (templateItem, destinationFolder) => {
}
);
} else {
fs.createReadStream(templatePath).pipe(fs.createWriteStream(destinationPath));
await window.electron.ipcRenderer.invoke("write-template", templatePath, destinationPath)
let emessage = `Successfully saved '${templateItem}' to ${destinationFolder}`;

Swal.fire({
Expand All @@ -58,13 +67,13 @@ const downloadTemplates = (templateItem, destinationFolder) => {
heightAuto: false,
backdrop: "rgba(0,0,0, 0.4)",
});
ipcRenderer.send("track-event", "Success", `Download Template - ${templateItem}`);
window.electron.ipcRenderer.send("track-event", "Success", `Download Template - ${templateItem}`);

let templateLabel = Object.values(kombuchaEnums.Label).find((label) => {
return label === templateItem;
});

ipcRenderer.send(
window.electron.ipcRenderer.send(
"track-kombucha",
kombuchaEnums.Category.PREPARE_METADATA,
kombuchaEnums.Action.DOWNLOAD_TEMPLATES,
Expand All @@ -78,46 +87,46 @@ const downloadTemplates = (templateItem, destinationFolder) => {
};

downloadSubmission.addEventListener("click", (event) => {
ipcRenderer.send("open-folder-dialog-save-metadata", templateArray[0]);
window.electron.ipcRenderer.send("open-folder-dialog-save-metadata", templateArray[0]);
});

downloadDescription.addEventListener("click", (event) => {
ipcRenderer.send("open-folder-dialog-save-metadata", templateArray[1]);
window.electron.ipcRenderer.send("open-folder-dialog-save-metadata", templateArray[1]);
});

downloadSubjects.addEventListener("click", (event) => {
ipcRenderer.send("open-folder-dialog-save-metadata", templateArray[2]);
window.electron.ipcRenderer.send("open-folder-dialog-save-metadata", templateArray[2]);
});

downloadSamples.addEventListener("click", (event) => {
ipcRenderer.send("open-folder-dialog-save-metadata", templateArray[3]);
window.electron.ipcRenderer.send("open-folder-dialog-save-metadata", templateArray[3]);
});

downloadManifest.addEventListener("click", (event) => {
ipcRenderer.send("open-folder-dialog-save-metadata", templateArray[4]);
window.electron.ipcRenderer.send("open-folder-dialog-save-metadata", templateArray[4]);
});

document.querySelectorAll(".guided-data-deliverables-download-button").forEach((button) => {
button.addEventListener("click", (event) => {
ipcRenderer.send("open-folder-dialog-save-metadata", "code_description.xlsx");
window.electron.ipcRenderer.send("open-folder-dialog-save-metadata", "code_description.xlsx");
});
});

document
.querySelectorAll(".guided-subject-sample-pool-structure-download-button")
.forEach((button) => {
button.addEventListener("click", (event) => {
ipcRenderer.send("open-folder-dialog-save-metadata", "subjects_pools_samples_structure.xlsx");
window.electron.ipcRenderer.send("open-folder-dialog-save-metadata", "subjects_pools_samples_structure.xlsx");
});
});

ipcRenderer.on("selected-metadata-download-folder", (event, path, filename) => {
window.electron.ipcRenderer.on("selected-metadata-download-folder", (event, path, filename) => {
if (path.length > 0) {
downloadTemplates(filename, path[0]);
}
});

ipcRenderer.on("selected-DDD-download-folder", (event, path, filename) => {
window.electron.ipcRenderer.on("selected-DDD-download-folder", (event, path, filename) => {
if (path.length > 0) {
downloadTemplates(filename, path[0]);
}
Expand Down

0 comments on commit f2d9ecf

Please sign in to comment.