Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…/nwb-guide into timezone
  • Loading branch information
garrettmflynn committed Jun 3, 2024
2 parents fae3596 + 3e74935 commit 864c2da
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 49 deletions.
11 changes: 2 additions & 9 deletions src/electron/frontend/core/components/DateTimeSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,8 @@ import { LitElement, css } from "lit";
import { getTimezoneOffset, formatTimezoneOffset } from "../../../../schemas/timezone.schema";

// Function to format the GMT offset
export function extractISOString(
date = new Date(),
{
offset = false,
timezone = undefined
} = {}
) {

if (typeof date === 'string') date = new Date()
export function extractISOString(date = new Date(), { offset = false, timezone = undefined } = {}) {
if (typeof date === "string") date = new Date();

// Extract the GMT offset
const offsetMs = getTimezoneOffset(date, timezone);
Expand Down
26 changes: 10 additions & 16 deletions src/electron/frontend/core/components/JSONSchemaForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import { successHue, warningHue, errorHue } from "./globals";
import { Button } from "./Button";
import { extractISOString } from "./DateTimeSelector";
import { timezoneProperties } from "../../../../schemas/timezone.schema";
const timezonePropertyPaths = timezoneProperties.map(arr => arr.join('.'))

const timezonePropertyPaths = timezoneProperties.map((arr) => arr.join("."));

const encode = (str) => {
try {
Expand Down Expand Up @@ -252,7 +251,7 @@ export class JSONSchemaForm extends LitElement {
dialogOptions: { type: Object, reflect: false },
globals: { type: Object, reflect: false },
validateEmptyValues: { type: Boolean, reflect: true },
timezone: { type: String, reflect: true}
timezone: { type: String, reflect: true },
};
}

Expand Down Expand Up @@ -285,7 +284,7 @@ export class JSONSchemaForm extends LitElement {
this.results = (props.base ? structuredClone(props.results) : props.results) ?? {}; // Deep clone results in nested forms
this.globals = props.globals ?? {};

this.timezone = props.timezone ?? undefined
this.timezone = props.timezone ?? undefined;

this.ignore = props.ignore ?? {};
this.required = props.required ?? {};
Expand Down Expand Up @@ -705,7 +704,7 @@ export class JSONSchemaForm extends LitElement {
pattern: propertyType === "pattern" ? name : propertyType ?? undefined,
renderTable: this.renderTable,
renderCustomHTML: this.renderCustomHTML,
showLabel: !("title" in info && !info.title)
showLabel: !("title" in info && !info.title),
});

this.inputs[localPath.join("-")] = interactiveInput;
Expand Down Expand Up @@ -911,20 +910,16 @@ export class JSONSchemaForm extends LitElement {

let value = parent[name];

const { timezone } = this
const { timezone } = this;

// Validate with timezone awareness
const isTimezoneProperty = timezonePropertyPaths.includes(externalPath.join('.'))
const isTimezoneProperty = timezonePropertyPaths.includes(externalPath.join("."));
if (timezone && isTimezoneProperty) {
value = extractISOString(
value,
{
offset: true,
timezone
}
)
value = extractISOString(value, {
offset: true,
timezone,
});
}


const skipValidation = this.validateEmptyValues === null && value === undefined;

Expand All @@ -933,7 +928,6 @@ export class JSONSchemaForm extends LitElement {
// Run validation functions
const jsonSchemaErrors = validateArgs.length === 2 ? this.validateSchema(...validateArgs, name) : [];


const valid = skipValidation ? true : await this.validateOnChange(name, parent, pathToValidate, value);

if (valid === null) return null; // Skip validation / data change if the value is null
Expand Down
7 changes: 3 additions & 4 deletions src/electron/frontend/core/components/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,11 @@ export class Main extends LitElement {
const workflowConfig = page.workflow ?? (page.workflow = {});
const workflowValues = page.info.globalState?.project?.workflow ?? {};

Object.entries(workflowValues).forEach(([ key, value ]) => {

const config = workflowConfig[key] ?? (workflowConfig[key] = {})
Object.entries(workflowValues).forEach(([key, value]) => {
const config = workflowConfig[key] ?? (workflowConfig[key] = {});
config.value = value;

const { elements } = config
const { elements } = config;
if (elements) {
if (value) elements.forEach((el) => el.removeAttribute("hidden"));
else elements.forEach((el) => el.setAttribute("hidden", true));
Expand Down
31 changes: 12 additions & 19 deletions src/electron/frontend/core/components/pages/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ export class Page extends LitElement {
const fileConfiguration = [];

try {

for (let info of toRun) {
const { subject, session, globalState = this.info.globalState } = info;
const file = `sub-${subject}/sub-${subject}_ses-${session}.nwb`;
Expand All @@ -174,21 +173,18 @@ export class Page extends LitElement {
const sourceDataCopy = structuredClone(sessionResults.source_data);

// Resolve the correct session info from all of the metadata for this conversion
const metadata = resolveMetadata(subject, session, globalState)
const metadata = resolveMetadata(subject, session, globalState);

// Add timezone information to relevant metadata
timezoneProperties.forEach(path => {
const name = path.slice(-1)[0]
const pathTo = path.slice(0, -1)
const parent = pathTo.reduce((acc, key) => acc[key], metadata)
parent[name] = extractISOString(
parent[name],
{
offset: true,
timezone: this.workflow.timezone
}
)
})
timezoneProperties.forEach((path) => {
const name = path.slice(-1)[0];
const pathTo = path.slice(0, -1);
const parent = pathTo.reduce((acc, key) => acc[key], metadata);
parent[name] = extractISOString(parent[name], {
offset: true,
timezone: this.workflow.timezone,
});
});

const sessionInfo = {
...sessionResults,
Expand All @@ -205,7 +201,7 @@ export class Page extends LitElement {
...conversionOptions, // Any additional conversion options override the defaults

interfaces: globalState.interfaces,
alignment
alignment,
};

fileConfiguration.push(payload);
Expand Down Expand Up @@ -242,10 +238,7 @@ export class Page extends LitElement {
const subRef = results[subject] ?? (results[subject] = {});
subRef[session] = info;
});

}

finally {
} finally {
await closeProgressPopup();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ export class GuidedMetadataPage extends ManagedPage {

delete results.__generated; // Ignore generated results. NOTE: See if this fails


// Create the form
const form = new JSONSchemaForm({
identifier: instanceId,
Expand Down

0 comments on commit 864c2da

Please sign in to comment.