Skip to content

Commit

Permalink
Merge branch 'inspector-files-or-folders' into dandi-files-or-folders
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettmflynn committed Oct 2, 2023
2 parents a48d7a1 + 07a7dfb commit 0a3cf27
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 16 deletions.
4 changes: 3 additions & 1 deletion guideGlobalMetadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"ScanImageImagingInterface",
"TiffImagingInterface",
"MiniscopeImagingInterface",
"SbxImagingInterface"
"SbxImagingInterface",
"MCSRawRecordingInterface",
"MEArecRecordingInterface"
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "nwb-guide",
"productName": "NWB GUIDE",
"version": "0.0.5",
"version": "0.0.6",
"description": "",
"main": "./build/main/main.js",
"engine": {
Expand Down
5 changes: 3 additions & 2 deletions pyflask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import sys
import json
import multiprocessing
from os.path import sep
from os import kill, getpid
from signal import SIGINT
from logging import Formatter, DEBUG
from logging.handlers import RotatingFileHandler
from pathlib import Path
Expand Down Expand Up @@ -96,7 +97,7 @@ def get(self):
api.logger.info("Shutting down server")

if func is None:
print("Not running with the Werkzeug Server")
kill(getpid(), SIGINT)
return

func()
Expand Down
33 changes: 33 additions & 0 deletions schemas/json/generated/MCSRawRecordingInterface.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"required": [],
"properties": {
"MCSRawRecordingInterface": {
"required": [
"file_path"
],
"properties": {
"file_path": {
"format": "file",
"type": "string"
},
"verbose": {
"type": "boolean",
"default": true
},
"es_key": {
"type": "string",
"default": "ElectricalSeries"
}
},
"type": "object",
"additionalProperties": false
}
},
"type": "object",
"additionalProperties": false,
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "source.schema.json",
"title": "Source data schema",
"description": "Schema for the source data, files and directories",
"version": "0.1.0"
}
33 changes: 33 additions & 0 deletions schemas/json/generated/MEArecRecordingInterface.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"required": [],
"properties": {
"MEArecRecordingInterface": {
"required": [
"file_path"
],
"properties": {
"file_path": {
"format": "file",
"type": "string"
},
"verbose": {
"type": "boolean",
"default": true
},
"es_key": {
"type": "string",
"default": "ElectricalSeries"
}
},
"type": "object",
"additionalProperties": false
}
},
"type": "object",
"additionalProperties": false,
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "source.schema.json",
"title": "Source data schema",
"description": "Schema for the source data, files and directories",
"version": "0.1.0"
}
9 changes: 4 additions & 5 deletions src/renderer/src/stories/FileSystemSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class FilesystemSelector extends LitElement {
this.#onThrow("Incorrect filesystem object", `Please provide a <b>${this.type}</b> instead.`);
};

#handleFiles = async (pathOrPaths) => {
#handleFiles = async (pathOrPaths, type) => {
if (!pathOrPaths)
this.#onThrow(
"No paths detected",
Expand All @@ -148,7 +148,7 @@ export class FilesystemSelector extends LitElement {
);

if (Array.isArray(pathOrPaths)) pathOrPaths.forEach(this.#checkType);
else this.#checkType(pathOrPaths);
else if (!type) this.#checkType(pathOrPaths);

let resolvedValue = pathOrPaths;

Expand All @@ -173,16 +173,15 @@ export class FilesystemSelector extends LitElement {
if (dialog) {
const results = await this.#useElectronDialog(type);
// const path = file.filePath ?? file.filePaths?.[0];
this.#handleFiles(results.filePath ?? results.filePaths);
this.#handleFiles(results.filePath ?? results.filePaths, type);
} else {
let handles = await (type === "directory"
? window.showDirectoryPicker()
: window.showOpenFilePicker({ multiple: this.multiple })
).catch((e) => this.#onCancel()); // Call using the same options

const result = Array.isArray(handles) ? handles.map((o) => o.name) : handles.name;
console.log(result, handles);
this.#handleFiles(result);
this.#handleFiles(result, type);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/renderer/src/stories/JSONSchemaInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { Modal } from "./Modal";

import { capitalize } from "./forms/utils";

const isFilesystemSelector = (format) => {
if (Array.isArray(format)) return format.map(isFilesystemSelector).every(Boolean) ? format : null;
const isFilesystemSelector = (name, format) => {
if (Array.isArray(format)) return format.map((f) => isFilesystemSelector(name, f)).every(Boolean) ? format : null;

const matched = name.match(/(.+_)?(.+)_paths?/);
if (!format && matched) format = matched[2] === "folder" ? "directory" : matched[2];
Expand Down Expand Up @@ -186,7 +186,7 @@ export class JSONSchemaInput extends LitElement {
const itemSchema = this.form ? this.form.getSchema("items", info) : info["items"];
const isTable = itemSchema.type === "object";

const fileSystemFormat = isFilesystemSelector(itemSchema.format);
const fileSystemFormat = isFilesystemSelector(name, itemSchema.format);
if (fileSystemFormat) return createFilesystemSelector(fileSystemFormat);
else if (isTable) {
const tableMetadata = {
Expand Down Expand Up @@ -308,7 +308,7 @@ export class JSONSchemaInput extends LitElement {
@change=${(ev) => validateOnChange && this.#triggerValidation(name, ev.target, path)}
/>`;
} else if (info.type === "string" || info.type === "number") {
const fileSystemFormat = isFilesystemSelector(info.format);
const fileSystemFormat = isFilesystemSelector(name, info.format);
if (fileSystemFormat) return createFilesystemSelector(fileSystemFormat);
// Handle long string formats
else if (info.format === "long" || isArray)
Expand Down
12 changes: 9 additions & 3 deletions src/renderer/src/stories/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class Search extends LitElement {
this.list.appendChild(slot);

if (this.options) {
this.options
const unsupported = this.options
.sort((a, b) => {
if (a.label < b.label) return -1;
if (a.label > b.label) return 1;
Expand All @@ -122,7 +122,7 @@ export class Search extends LitElement {
else if (a.disabled) return 1;
else if (b.disabled) return -1;
}) // Sort with the disabled options at the bottom
.forEach((option) => {
.filter((option) => {
const li = document.createElement("li");
li.classList.add("option");
li.setAttribute("hidden", "");
Expand All @@ -142,7 +142,13 @@ export class Search extends LitElement {
li.appendChild(keywords);

this.list.appendChild(li);
});

return option.disabled;
})
.map((o) => o.value);

console.warn(`Enabled: ${this.options.length - unsupported.length}/${this.options.length}`);
console.warn("Disabled Options:", unsupported);
}

return html`
Expand Down
18 changes: 18 additions & 0 deletions src/renderer/src/stories/pages/guided-mode/SourceData.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import ScanImageImagingInterfaceSchema from "../../../../../../schemas/json/gene
import TiffImagingInterfaceSchema from "../../../../../../schemas/json/generated/TiffImagingInterface.json";
import MiniscopeImagingInterfaceSchema from "../../../../../../schemas/json/generated/MiniscopeImagingInterface.json";
import SbxImagingInterfaceSchema from "../../../../../../schemas/json/generated/SbxImagingInterface.json";
import MCSRawRecordingInterfaceSchema from "../../../../../../schemas/json/generated/MCSRawRecordingInterface.json";
import MEArecRecordingInterfaceSchema from "../../../../../../schemas/json/generated/MEArecRecordingInterface.json";

export default {
title: "Pages/Guided Mode/Source Data",
Expand Down Expand Up @@ -73,6 +75,10 @@ globalStateCopy.schema.source_data.properties.MiniscopeImagingInterface =
MiniscopeImagingInterfaceSchema.properties.MiniscopeImagingInterface;
globalStateCopy.schema.source_data.properties.SbxImagingInterface =
SbxImagingInterfaceSchema.properties.SbxImagingInterface;
globalStateCopy.schema.source_data.properties.MCSRawRecordingInterface =
MCSRawRecordingInterfaceSchema.properties.MCSRawRecordingInterface;
globalStateCopy.schema.source_data.properties.MEArecRecordingInterface =
MEArecRecordingInterfaceSchema.properties.MEArecRecordingInterface;

const results = globalStateCopy.results;
for (let sub in results) {
Expand Down Expand Up @@ -211,3 +217,15 @@ const SbxImagingInterfaceGlobalCopy = JSON.parse(JSON.stringify(globalState));
SbxImagingInterfaceGlobalCopy.interfaces.interface = SbxImagingInterface;
SbxImagingInterfaceGlobalCopy.schema.source_data = SbxImagingInterfaceSchema;
SbxImagingInterface.args = { activePage, globalState: SbxImagingInterfaceGlobalCopy };

export const MCSRawRecordingInterface = PageTemplate.bind({});
const MCSRawRecordingInterfaceGlobalCopy = JSON.parse(JSON.stringify(globalState));
MCSRawRecordingInterfaceGlobalCopy.interfaces.interface = MCSRawRecordingInterface;
MCSRawRecordingInterfaceGlobalCopy.schema.source_data = MCSRawRecordingInterfaceSchema;
MCSRawRecordingInterface.args = { activePage, globalState: MCSRawRecordingInterfaceGlobalCopy };

export const MEArecRecordingInterface = PageTemplate.bind({});
const MEArecRecordingInterfaceGlobalCopy = JSON.parse(JSON.stringify(globalState));
MEArecRecordingInterfaceGlobalCopy.interfaces.interface = MEArecRecordingInterface;
MEArecRecordingInterfaceGlobalCopy.schema.source_data = MEArecRecordingInterfaceSchema;
MEArecRecordingInterface.args = { activePage, globalState: MEArecRecordingInterfaceGlobalCopy };

0 comments on commit 0a3cf27

Please sign in to comment.