Skip to content

Commit

Permalink
Merge branch 'rebase_flask_refactor' of https://github.com/neurodataw…
Browse files Browse the repository at this point in the history
…ithoutborders/nwb-guide into rebase_flask_refactor
  • Loading branch information
CodyCBakerPhD committed May 24, 2024
2 parents c70954e + 18b7229 commit b54df9f
Show file tree
Hide file tree
Showing 4 changed files with 300 additions and 325 deletions.
101 changes: 49 additions & 52 deletions src/electron/renderer/src/stories/pages/preview/PreviewPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,59 +6,56 @@ import { Neurosift } from "../../preview/Neurosift.js";
import { baseUrl } from "../../../server/globals";

export class PreviewPage extends Page {
header = {
title: "NWB File Exploration",
subtitle: "Visualize your NWB file using Neurosift.",
};

constructor(...args) {
super(...args);
this.style.height = "100%"; // Fix main section
}

updatePath = async (path) => {
if (path) {
// Enable access to the explicit file path
const result = await fetch(`${baseUrl}/files/${path}`, {
method: "POST",
}).then((res) => res.text());

// Set Neurosift to access the returned URL
if (result) this.neurosift.url = result;
} else this.neurosift.url = undefined;
};

neurosift = new Neurosift();

input = new JSONSchemaInput({
path: ["file_path"],
schema: {
type: "string",
format: "file",
description:
"Please provide a file path that you'd like to visualize using Neurosift. The GUIDE will serve this file and access the appropriate URL automatically.",
},
onUpdate: this.updatePath,
onThrow,
});

render() {
const urlFilePath = new URL(document.location).searchParams.get("file");

if (urlFilePath) {
this.updatePath(urlFilePath);
this.input.value = urlFilePath;
header = {
title: "NWB File Exploration",
subtitle: "Visualize your NWB file using Neurosift.",
};

constructor(...args) {
super(...args);
this.style.height = "100%"; // Fix main section
}

return html`
<div
style="display: grid; width: 100%; height: 100%; grid-template-rows: min-content 1fr; gap: 10px;"
>
${this.input} ${this.neurosift}
</div>
`;
}
updatePath = async (path) => {
if (path) {
// Enable access to the explicit file path
const result = await fetch(`${baseUrl}/files/${path}`, {
method: "POST",
}).then((res) => res.text());

// Set Neurosift to access the returned URL
if (result) this.neurosift.url = result;
} else this.neurosift.url = undefined;
};

neurosift = new Neurosift();

input = new JSONSchemaInput({
path: ["file_path"],
schema: {
type: "string",
format: "file",
description:
"Please provide a file path that you'd like to visualize using Neurosift. The GUIDE will serve this file and access the appropriate URL automatically.",
},
onUpdate: this.updatePath,
onThrow,
});

render() {
const urlFilePath = new URL(document.location).searchParams.get("file");

if (urlFilePath) {
this.updatePath(urlFilePath);
this.input.value = urlFilePath;
}

return html`
<div style="display: grid; width: 100%; height: 100%; grid-template-rows: min-content 1fr; gap: 10px;">
${this.input} ${this.neurosift}
</div>
`;
}
}

customElements.get("nwbguide-preview-page") ||
customElements.define("nwbguide-preview-page", PreviewPage);
customElements.get("nwbguide-preview-page") || customElements.define("nwbguide-preview-page", PreviewPage);
Loading

0 comments on commit b54df9f

Please sign in to comment.