From f1489716d9bd0394ec364342400b10b4147db961 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Tue, 24 Sep 2024 17:24:26 +0200 Subject: [PATCH] feat: first version of session grid --- frontend/src/js/app.ts | 2 + frontend/src/js/core/api.ts | 1 + frontend/src/js/core/session-grid.ts | 164 +++++++ frontend/src/js/types/session-grid.ts | 57 +++ frontend/src/js/ui/components/box.ts | 3 +- .../ui/components/layout/center-container.ts | 8 +- frontend/src/js/ui/components/layout/grid.ts | 2 + .../src/js/ui/components/modals/prompt.ts | 5 +- .../session-grid/create-edit-grid-button.ts | 296 +++++++++++++ .../session-grid/grid-basic-button.ts | 68 +++ .../ui/components/session-grid/grid-button.ts | 25 ++ .../ui/components/session-grid/grid-edit.ts | 35 ++ .../session-grid/grid-generator-button.ts | 92 ++++ .../session-grid/grid-template-button.ts | 121 +++++ .../js/ui/components/view-layout/side-nav.ts | 5 + frontend/src/js/ui/shoelace/button.ts | 8 +- frontend/src/js/ui/shoelace/color-picker.ts | 29 ++ frontend/src/js/ui/shoelace/divider-vert.ts | 6 +- frontend/src/js/ui/shoelace/input.ts | 2 + frontend/src/js/ui/shoelace/modal.ts | 3 +- frontend/src/js/ui/shoelace/select.ts | 7 +- frontend/src/js/ui/shoelace/util.ts | 21 + frontend/src/js/ui/views/session-grid.ts | 414 ++++++++++++++++++ rpc/misc.go | 21 + server/server.go | 1 + 25 files changed, 1386 insertions(+), 10 deletions(-) create mode 100644 frontend/src/js/core/session-grid.ts create mode 100644 frontend/src/js/types/session-grid.ts create mode 100644 frontend/src/js/ui/components/modals/session-grid/create-edit-grid-button.ts create mode 100644 frontend/src/js/ui/components/session-grid/grid-basic-button.ts create mode 100644 frontend/src/js/ui/components/session-grid/grid-button.ts create mode 100644 frontend/src/js/ui/components/session-grid/grid-edit.ts create mode 100644 frontend/src/js/ui/components/session-grid/grid-generator-button.ts create mode 100644 frontend/src/js/ui/components/session-grid/grid-template-button.ts create mode 100644 frontend/src/js/ui/shoelace/color-picker.ts create mode 100644 frontend/src/js/ui/shoelace/util.ts create mode 100644 frontend/src/js/ui/views/session-grid.ts create mode 100644 rpc/misc.go diff --git a/frontend/src/js/app.ts b/frontend/src/js/app.ts index 00e4373..637e54b 100644 --- a/frontend/src/js/app.ts +++ b/frontend/src/js/app.ts @@ -22,6 +22,7 @@ import GeneratorCreate from 'js/ui/views/generator/create'; import GeneratorEdit from 'js/ui/views/generator/edit'; import GeneratorSingle from 'js/ui/views/generator/single'; import Home from 'js/ui/views/home'; +import SessionGrid from 'js/ui/views/session-grid'; import Settings from 'js/ui/views/settings'; import TemplateAll from 'js/ui/views/template/all'; import TemplateCreate from 'js/ui/views/template/create'; @@ -69,6 +70,7 @@ store.actions.loadAll().then(() => { '/generator/create/:id': GeneratorCreate, '/generator/:id': GeneratorSingle, '/generator/:id/edit': GeneratorEdit, + '/session-grid': SessionGrid, '/data-source': DataSourceAll, '/data-source/:id': DataSourceSingle, '/workshop': WorkshopAll, diff --git a/frontend/src/js/core/api.ts b/frontend/src/js/core/api.ts index 47982f8..90bed63 100644 --- a/frontend/src/js/core/api.ts +++ b/frontend/src/js/core/api.ts @@ -102,3 +102,4 @@ export const GET_DEFAULT_DIRECTORIES = 'getDefaultDirectories'; // Misc function export const FETCH_IMAGE = 'fetchImage'; export const PREVIEW_CACHE = 'previewCache'; +export const GET_LOCAL_URL = 'getLocalURL'; diff --git a/frontend/src/js/core/session-grid.ts b/frontend/src/js/core/session-grid.ts new file mode 100644 index 0000000..75d0b5c --- /dev/null +++ b/frontend/src/js/core/session-grid.ts @@ -0,0 +1,164 @@ +import { buildId } from 'js/types/basic-info'; +import Entry from 'js/types/entry'; +import Generator, { sanitizeConfig } from 'js/types/generator'; +import { + GridElement, + GridGeneratorElement, + GridLinearExecution, + GridTemplateElement, + isGridGeneratorElement, + isGridLinearExecution, + isGridTemplateElement, +} from 'js/types/session-grid'; +import Template from 'js/types/template'; +import * as API from 'js/core/api'; +import { settings } from 'js/core/store'; +import { render } from 'js/core/templating'; + +const TEMPLATE_ENTRIES_CACHE_TIMEOUT = 10000; + +/** + * Gets the name of a grid element. If the element has a name, it will be returned immediately. Otherwise, the name will be fetched from the API. + * @param element The grid element to get the name of + * @returns A promise that resolves to the name of the grid element + */ +export function getGridElementName(element: GridElement): Promise { + return new Promise((resolve, reject) => { + if (element.name) { + resolve(element.name); + return; + } + + if (isGridTemplateElement(element)) { + API.exec