Skip to content

Commit

Permalink
Merge branch 'main' into CaimanSegmentationInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyCBakerPhD authored Oct 2, 2023
2 parents 24669ae + 754f753 commit db23a8c
Show file tree
Hide file tree
Showing 13 changed files with 330 additions and 72 deletions.
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.6",
"version": "0.0.7",
"description": "",
"main": "./build/main/main.js",
"engine": {
Expand Down
32 changes: 27 additions & 5 deletions pyflask/apis/neuroconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
inspect_nwb_file,
inspect_nwb_folder,
inspect_multiple_filesystem_objects,
upload_to_dandi,
upload_folder_to_dandi,
upload_multiple_filesystem_objects_to_dandi,
)

from errorHandlers import notBadRequestException
Expand Down Expand Up @@ -112,13 +115,11 @@ def post(self):
neuroconv_api.abort(500, str(e))


@neuroconv_api.route("/upload")
@neuroconv_api.route("/upload/project")
class Upload(Resource):
@neuroconv_api.doc(responses={200: "Success", 400: "Bad Request", 500: "Internal server error"})
def post(self):
try:
from manageNeuroconv import upload_to_dandi

return upload_to_dandi(**neuroconv_api.payload)

except Exception as e:
Expand All @@ -131,15 +132,36 @@ class Upload(Resource):
@neuroconv_api.doc(responses={200: "Success", 400: "Bad Request", 500: "Internal server error"})
def post(self):
try:
from manageNeuroconv import upload_folder_to_dandi

return upload_folder_to_dandi(**neuroconv_api.payload)

except Exception as e:
if notBadRequestException(e):
neuroconv_api.abort(500, str(e))


@neuroconv_api.route("/upload")
class Upload(Resource):
@neuroconv_api.doc(responses={200: "Success", 400: "Bad Request", 500: "Internal server error"})
def post(self):
from os.path import isdir

try:
paths = neuroconv_api.payload["filesystem_paths"]

if len(paths) == 1 and isdir(paths[0]):
kwargs = {**neuroconv_api.payload}
del kwargs["filesystem_paths"]
kwargs["nwb_folder_path"] = paths[0]
return upload_folder_to_dandi(**kwargs)

else:
return upload_multiple_filesystem_objects_to_dandi(**neuroconv_api.payload)

except Exception as e:
if notBadRequestException(e):
neuroconv_api.abort(500, str(e))


@neuroconv_api.route("/inspect_file")
class InspectNWBFile(Resource):
@neuroconv_api.doc(responses={200: "Success", 400: "Bad Request", 500: "Internal server error"})
Expand Down
1 change: 1 addition & 0 deletions pyflask/manageNeuroconv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
validate_metadata,
upload_to_dandi,
upload_folder_to_dandi,
upload_multiple_filesystem_objects_to_dandi,
listen_to_neuroconv_events,
generate_dataset,
inspect_nwb_file,
Expand Down
10 changes: 10 additions & 0 deletions pyflask/manageNeuroconv/manage_neuroconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,16 @@ def update_conversion_progress(**kwargs):
return dict(file=str(resolved_output_path))


def upload_multiple_filesystem_objects_to_dandi(**kwargs):
tmp_folder_path = aggregate_symlinks_in_new_directory(kwargs["filesystem_paths"], "upload")
innerKwargs = {**kwargs}
del innerKwargs["filesystem_paths"]
innerKwargs["nwb_folder_path"] = tmp_folder_path
result = upload_folder_to_dandi(**innerKwargs)
rmtree(tmp_folder_path)
return result


def upload_folder_to_dandi(
dandiset_id: str,
api_key: str,
Expand Down
11 changes: 7 additions & 4 deletions schemas/json/dandi/standalone.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"properties": {
"nwb_folder_path": {
"type": "string",
"format": "directory"
"filesystem_paths": {
"type": "array",
"items":{
"type": "string",
"format": ["file", "directory"]
}
}
},
"required": ["nwb_folder_path"]
"required": ["filesystem_paths"]
}
35 changes: 35 additions & 0 deletions src/renderer/src/stories/CodeBlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { LitElement, css, html } from "lit";

export class CodeBlock extends LitElement {
static get styles() {
return css`
:host {
display: block;
font-size: 85%;
background: #f2f1f1;
border-radius: 10px;
border: 1px solid gray;
overflow: hidden;
}
pre {
overflow: auto;
padding: 5px 10px;
box-sizing: border-box;
user-select: text;
margin: 0;
}
`;
}

constructor({ text = "" }) {
super();
this.text = text;
}

render() {
return html`<pre>${this.text}</pre>`;
}
}

customElements.get("code-block") || customElements.define("code-block", CodeBlock);
4 changes: 4 additions & 0 deletions src/renderer/src/stories/FileSystemSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ const componentCSS = css`
gap: 5px;
}
#button-div > nwb-button {
margin-bottom: 10px;
}
button {
background: WhiteSmoke;
border: 1px solid #c3c3c3;
Expand Down
51 changes: 27 additions & 24 deletions src/renderer/src/stories/InfoBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,37 +76,40 @@ export class InfoBox extends LitElement {
`;
}

constructor({ header = "Info", content, type = "info" } = {}) {
constructor({ header = "Info", content, type = "info", open = false } = {}) {
super();
this.header = header;
this.content = content;
this.type = type;
this.open = open;
}

updated() {
const infoDropdowns = this.shadowRoot.querySelectorAll(".guided--info-dropdown");
for (const infoDropdown of Array.from(infoDropdowns)) {
const infoTextElement = infoDropdown.querySelector("#header");

// Auto-add icons if they're not there
if (this.type === "info") infoTextElement.insertAdjacentHTML("beforebegin", `<span class="icon">ℹ️</span>`);
if (this.type === "warning")
infoTextElement.insertAdjacentHTML("beforebegin", ` <span class="icon">⚠️</span>`);

infoDropdown.onclick = () => {
const infoContainer = infoDropdown.nextElementSibling;
const infoContainerChevron = infoDropdown.querySelector("nwb-chevron");

const infoContainerIsopen = infoContainer.classList.contains("container-open");

if (infoContainerIsopen) {
infoContainerChevron.direction = "right";
infoContainer.classList.remove("container-open");
} else {
infoContainerChevron.direction = "bottom";
infoContainer.classList.add("container-open");
}
};
const infoDropdown = this.shadowRoot.querySelector(".guided--info-dropdown");
const infoTextElement = infoDropdown.querySelector("#header");

// Auto-add icons if they're not there
if (this.type === "info") infoTextElement.insertAdjacentHTML("beforebegin", `<span class="icon">ℹ️</span>`);
if (this.type === "warning") infoTextElement.insertAdjacentHTML("beforebegin", ` <span class="icon">⚠️</span>`);

const infoContainer = infoDropdown.nextElementSibling;
infoDropdown.onclick = () => this.onToggle(!infoContainer.classList.contains("container-open"));

this.onToggle();
}

onToggle(open = this.open) {
const infoDropdown = this.shadowRoot.querySelector(".guided--info-dropdown");

const infoContainer = infoDropdown.nextElementSibling;
const infoContainerChevron = infoDropdown.querySelector("nwb-chevron");

if (open) {
infoContainerChevron.direction = "bottom";
infoContainer.classList.add("container-open");
} else {
infoContainerChevron.direction = "right";
infoContainer.classList.remove("container-open");
}
}

Expand Down
23 changes: 14 additions & 9 deletions src/renderer/src/stories/JSONSchemaForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ hr {
margin: 1em 0 1.5em 0;
}
pre {
white-space: pre-wrap; /* Since CSS 2.1 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
font-family: unset;
color: DimGray;
}
pre {
white-space: pre-wrap; /* Since CSS 2.1 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
font-family: unset;
color: DimGray;
}
.required label:after {
content: " *";
Expand Down Expand Up @@ -434,6 +434,7 @@ export class JSONSchemaForm extends LitElement {
${interactiveInput}
<div class="errors"></div>
<div class="warnings"></div>
<div class="info"></div>
</div>
`;
};
Expand Down Expand Up @@ -587,6 +588,8 @@ export class JSONSchemaForm extends LitElement {
? valid?.filter((info) => info.type === "error" || (isRequired && info.missing))
: [];

const info = Array.isArray(valid) ? valid?.filter((info) => info.type === "info") : [];

const hasLinks = this.#getLink(externalPath);
if (hasLinks) {
if (checkLinks) {
Expand All @@ -612,6 +615,7 @@ export class JSONSchemaForm extends LitElement {
// Clear old errors and warnings
this.#clearMessages(fullPath, "errors");
this.#clearMessages(fullPath, "warnings");
this.#clearMessages(fullPath, "info");

const isFunction = typeof valid === "function";
const isValid =
Expand All @@ -629,6 +633,7 @@ export class JSONSchemaForm extends LitElement {

// Show aggregated errors and warnings (if any)
warnings.forEach((info) => this.#addMessage(fullPath, info, "warnings"));
info.forEach((info) => this.#addMessage(fullPath, info, "info"));

if (isValid && errors.length === 0) {
element.classList.remove("invalid");
Expand Down
23 changes: 12 additions & 11 deletions src/renderer/src/stories/OptionalSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ export class OptionalSection extends LitElement {
return css`
:host {
display: block;
text-align: center;
}
h2 {
margin: 0;
margin-bottom: 15px;
}
.optional-section__toggle {
padding-bottom: 20px;
}
.optional-section__content {
text-align: left;
}
Expand Down Expand Up @@ -99,17 +102,15 @@ export class OptionalSection extends LitElement {

render() {
return html`
<div class="optional-section">
<div class="optional-section__header">
${this.header ? html`<h2>${this.header}</h2>` : ""}
<div>${this.description}</div>
<div class="optional-section__toggle">${this.yes} ${this.no}</div>
</div>
<div class="optional-section__content" hidden>
<slot>${this.content}</slot>
</div>
<div id="altContent" class="optional-section__content" hidden>${this.altContent}</div>
<div class="optional-section__header">
${this.header ? html`<h2>${this.header}</h2>` : ""}
<div>${this.description}</div>
<div class="optional-section__toggle">${this.yes} ${this.no}</div>
</div>
<div class="optional-section__content" hidden>
<slot>${this.content}</slot>
</div>
<div id="altContent" class="optional-section__content" hidden>${this.altContent}</div>
`;
}
}
Expand Down
Loading

0 comments on commit db23a8c

Please sign in to comment.