-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #329 from NeurodataWithoutBorders/fix-exit
Fix Exit Button
- Loading branch information
Showing
13 changed files
with
212 additions
and
108 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { app, isElectron } from "../electron/index.js"; | ||
import paths from "../../../../paths.config.json" assert { type: "json" }; | ||
import { joinPath } from "../globals.js"; | ||
|
||
export const reloadPageToHome = () => { | ||
if (isStorybook) return; | ||
window.location = isElectron ? window.location.pathname : window.location.origin; | ||
}; // Clear all query params | ||
|
||
// Filesystem Management | ||
export const homeDirectory = app?.getPath("home") ?? ""; | ||
export const appDirectory = homeDirectory ? joinPath(homeDirectory, paths.root) : ""; | ||
export const guidedProgressFilePath = homeDirectory ? joinPath(appDirectory, ...paths.subfolders.progress) : ""; | ||
|
||
export const isStorybook = window.location.href.includes("iframe.html"); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { guidedProgressFilePath } from "../dependencies/simple.js"; | ||
import { fs } from "../electron/index.js"; | ||
import { joinPath } from "../globals.js"; | ||
import { get } from "./index.js"; | ||
|
||
export const update = (newDatasetName, previousDatasetName) => { | ||
//If updataing the dataset, update the old banner image path with a new one | ||
if (previousDatasetName) { | ||
if (previousDatasetName === newDatasetName) return "No changes made to dataset name"; | ||
|
||
if (hasEntry(newDatasetName)) | ||
throw new Error("An existing progress file already exists with that name. Please choose a different name."); | ||
|
||
// update old progress file with new dataset name | ||
const oldProgressFilePath = `${guidedProgressFilePath}/${previousDatasetName}.json`; | ||
const newProgressFilePath = `${guidedProgressFilePath}/${newDatasetName}.json`; | ||
if (fs) fs.renameSync(oldProgressFilePath, newProgressFilePath); | ||
else { | ||
localStorage.setItem(newProgressFilePath, localStorage.getItem(oldProgressFilePath)); | ||
localStorage.removeItem(oldProgressFilePath); | ||
} | ||
|
||
return "Dataset name updated"; | ||
} else throw new Error("No previous dataset name provided"); | ||
}; | ||
|
||
export function updateURLParams(paramsToUpdate) { | ||
const params = new URLSearchParams(location.search); | ||
for (let key in paramsToUpdate) { | ||
const value = paramsToUpdate[key]; | ||
if (value == undefined) params.delete(key); | ||
else params.set(key, value); | ||
} | ||
|
||
// Update browser history state | ||
const value = `${location.pathname}?${params}`; | ||
if (history.state) Object.assign(history.state, paramsToUpdate); | ||
window.history.pushState(history.state, null, value); | ||
} | ||
|
||
export const updateAppProgress = ( | ||
pageId, | ||
dataOrProjectName = {}, | ||
projectName = typeof dataOrProjectName === "string" ? dataOrProjectName : undefined | ||
) => { | ||
const transitionOffPipeline = pageId && pageId.split("/")[0] !== "conversion"; | ||
|
||
if (transitionOffPipeline) { | ||
updateURLParams({ project: undefined }); | ||
return; // Only save last page if within the conversion workflow | ||
} | ||
|
||
if (projectName) updateURLParams({ project: projectName }); | ||
|
||
// Is a project name | ||
if (dataOrProjectName === projectName) updateFile(dataOrProjectName, (data) => (data["page-before-exit"] = pageId)); | ||
// Is a data object | ||
else dataOrProjectName["page-before-exit"] = pageId; | ||
}; | ||
|
||
//Destination: HOMEDIR/NWB_GUIDE/pipelines | ||
export const updateFile = (projectName, callback) => { | ||
let data = get(projectName); | ||
|
||
if (callback) { | ||
const result = callback(data); | ||
if (result && typeof result === "object") data = result; | ||
} | ||
|
||
data["last-modified"] = new Date(); // Always update the last modified time | ||
|
||
var guidedFilePath = joinPath(guidedProgressFilePath, projectName + ".json"); | ||
|
||
// Save the file through the available mechanisms | ||
if (fs) { | ||
if (!fs.existsSync(guidedProgressFilePath)) fs.mkdirSync(guidedProgressFilePath, { recursive: true }); //create progress folder if one does not exist | ||
fs.writeFileSync(guidedFilePath, JSON.stringify(data, null, 2)); | ||
} else localStorage.setItem(guidedFilePath, JSON.stringify(data)); | ||
}; |
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
2 changes: 1 addition & 1 deletion
2
src/renderer/src/stories/pages/guided-mode/setup/GuidedNewDatasetInfo.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { html } from "lit"; | ||
import { JSONSchemaForm } from "../../JSONSchemaForm.js"; | ||
import { Page } from "../Page.js"; | ||
import { onThrow } from "../../../errors"; | ||
import dandiUploadSchema from "../../../../../../schemas/json/dandi/upload.json"; | ||
import dandiStandaloneSchema from "../../../../../../schemas/json/dandi/standalone.json"; | ||
const dandiSchema = merge(dandiStandaloneSchema, dandiUploadSchema, { arrays: true }); | ||
|
||
import { Button } from "../../Button.js"; | ||
import { global } from "../../../progress/index.js"; | ||
import { merge } from "../utils.js"; | ||
|
||
import { run } from "../guided-mode/options/utils.js"; | ||
import { notyf } from "../../../dependencies/globals.js"; | ||
import Swal from "sweetalert2"; | ||
|
||
export async function uploadToDandi(info) { | ||
if (!("api_key" in (global.data.DANDI ?? {}))) { | ||
await Swal.fire({ | ||
title: "Your DANDI API key is not configured.", | ||
html: "Edit your settings to include this value.", | ||
icon: "warning", | ||
confirmButtonText: "Go to Settings", | ||
}); | ||
|
||
return this.to("settings"); | ||
} | ||
|
||
info.staging = parseInt(info.dandiset_id) >= 100000; // Automatically detect staging IDs | ||
info.api_key = global.data.DANDI.api_key; | ||
|
||
return await run("upload", info, { title: "Uploading to DANDI" }).catch((e) => { | ||
this.notify(e.message, "error"); | ||
throw e; | ||
}); | ||
} | ||
|
||
export class UploadsPage extends Page { | ||
constructor(...args) { | ||
super(...args); | ||
} | ||
|
||
render() { | ||
const globalState = (global.data.uploads = global.data.uploads ?? {}); | ||
const defaultButtonMessage = "Upload Files"; | ||
|
||
const button = new Button({ | ||
label: defaultButtonMessage, | ||
onClick: async () => { | ||
await this.form.validate(); // Will throw an error in the callback | ||
const results = await uploadToDandi.call(this, { ...global.data.uploads }); | ||
if (results) | ||
notyf.open({ | ||
type: "success", | ||
message: `${info.nwb_folder_path} successfully uploaded to Dandiset ${info.dandiset_id}`, | ||
}); | ||
}, | ||
}); | ||
|
||
const folderPathKey = "nwb_folder_path"; | ||
// NOTE: API Keys and Dandiset IDs persist across selected project | ||
this.form = new JSONSchemaForm({ | ||
results: globalState, | ||
schema: dandiSchema, | ||
onUpdate: ([id]) => { | ||
if (id === folderPathKey) { | ||
for (let key in dandiSchema.properties) { | ||
const input = this.form.getInput([key]); | ||
if (key !== folderPathKey) input.updateData(""); // Clear the results of the form | ||
} | ||
} | ||
|
||
global.save(); | ||
}, | ||
onThrow, | ||
}); | ||
|
||
return html` | ||
<div style="display: flex; align-items: end; justify-content: space-between; margin-bottom: 10px;"> | ||
<h1 style="margin: 0;">DANDI Uploads</h1> | ||
</div> | ||
<p>This page allows you to upload folders with NWB files to the DANDI Archive.</p> | ||
<hr /> | ||
<div> | ||
${this.form} | ||
<hr /> | ||
${button} | ||
</div> | ||
`; | ||
} | ||
} | ||
|
||
customElements.get("nwbguide-uploads-page") || customElements.define("nwbguide-uploads-page", UploadsPage); |
Oops, something went wrong.