Skip to content

Commit

Permalink
restore previous neurosift behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyCBakerPhD committed May 28, 2024
1 parent 20f86f5 commit 70551f4
Show file tree
Hide file tree
Showing 5 changed files with 427 additions and 367 deletions.
122 changes: 64 additions & 58 deletions src/electron/renderer/src/stories/pages/preview/PreviewPage.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,64 @@
import { html } from "lit";
import { Page } from "../Page.js";
import { onThrow } from "../../../errors";
import { JSONSchemaInput } from "../../JSONSchemaInput.js";
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) {
const result = await fetch(`${baseUrl}/neurosift/files/${path}`, {
method: "POST",
}).then((res) => res.text());
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);
import { html } from "lit";
import { Page } from "../Page.js";
import { onThrow } from "../../../errors";
import { JSONSchemaInput } from "../../JSONSchemaInput.js";
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;
}

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);
Loading

0 comments on commit 70551f4

Please sign in to comment.