# HG changeset patch
# User drewp@bigasterisk.com
# Date 2024-05-19 04:02:32
# Node ID 7e7874fed2e32f02816d4e09c3d5aae586202dd3
# Parent 9cbc93f80b055d2ea306e9ebd4d006e4c78e7f29
buttons to add panels to the layout
diff --git a/web/TiledHome.ts b/web/TiledHome.ts
--- a/web/TiledHome.ts
+++ b/web/TiledHome.ts
@@ -1,40 +1,15 @@
import debug from "debug";
import * as FlexLayout from "flexlayout-react";
-import { LitElement, html } from "lit";
+import { LitElement, TemplateResult, html } from "lit";
import { customElement } from "lit/decorators.js";
import * as React from "react";
import { createRoot } from "react-dom/client";
import { getTopGraph } from "./RdfdbSyncedGraph";
import { SyncedGraph } from "./SyncedGraph";
+import { panelDisplayName, panelElementNames, panelUrl } from "./panels";
export { RdfdbSyncedGraph } from "./RdfdbSyncedGraph";
-export { Light9CollectorUi } from "./collector/Light9CollectorUi";
-export { Light9FadeUi } from "./fade/Light9FadeUi";
-export { Light9DeviceSettings } from "./live/Light9DeviceSettings";
const log = debug("home");
-const config: FlexLayout.IJsonModel = {
- global: {
- tabEnableRename: false,
- },
- borders: [],
- layout: {
- type: "row",
- weight: 100,
- children: [
- {
- type: "tabset",
- weight: 50,
- children: [{ type: "tab", name: "devsettings", component: "light9-device-settings" }],
- },
- {
- type: "tabset",
- weight: 50,
- children: [{ type: "tab", name: "collector", component: "light9-collector-ui" }],
- },
- ],
- },
-};
-
// see https://github.com/lit/lit/tree/main/packages/labs/react
// Store flexlayout panels in per-browser localstorage.
@@ -46,7 +21,7 @@ class PersistentLayout {
{
type: "tabset",
weight: 50,
- children: [{ type: "tab", name: "devsettings", component: "light9-device-settings" }],
+ children: [{ type: "tab", name: "fade", component: "light9-fade-ui" }],
},
{
type: "tabset",
@@ -68,6 +43,9 @@ class PersistentLayout {
}
}
+// This lets lit call a method on a react element.
+let addTab: (component: string) => void;
+
class Main extends React.Component {
state: { model: FlexLayout.Model; persistence: PersistentLayout };
constructor(props: any) {
@@ -90,6 +68,15 @@ class Main extends React.Component {
};
render() {
+ addTab = (component) => {
+ const name = panelDisplayName(component);
+ if (name === undefined) throw new Error("no such panel: " + component);
+ const newTab = { type: "tab", name: name, component: component };
+ const firstTabSet = this.state.model.getRoot().getChildren()[0];
+ const action = FlexLayout.Actions.addNode(newTab, firstTabSet.getId(), FlexLayout.DockLocation.LEFT, 0);
+ this.state.model.doAction(action);
+ };
+
return React.createElement(FlexLayout.Layout, {
model: this.state.model,
realtimeResize: true,
@@ -107,15 +94,31 @@ class Main extends React.Component {
export class Light9HomeStatus extends LitElement {
graph!: SyncedGraph;
render() {
- return html`
- metrics `;
+ return html`
+
+ metrics
+ Open tab or new window: ${panelElementNames().map((elem) => this.linkToPanelPage(elem))}
+ `;
}
+
+ linkToPanelPage(elem: string): TemplateResult {
+ return html` ${panelDisplayName(elem)} `;
+ }
+
constructor() {
super();
getTopGraph().then((g) => {
this.graph = g;
});
}
+
+ onClickPanelLink(ev: MouseEvent) {
+ ev.preventDefault();
+
+ const a = ev.target as HTMLAnchorElement;
+ const elem = a.dataset.panelElem!;
+ addTab(elem);
+ }
}
const root = createRoot(document.getElementById("container")!);
diff --git a/web/panels.ts b/web/panels.ts
new file mode 100644
--- /dev/null
+++ b/web/panels.ts
@@ -0,0 +1,29 @@
+export { Light9AscoltamiUi } from "./ascoltami/Light9AscoltamiUi";
+export { Light9CollectorUi } from "./collector/Light9CollectorUi";
+export { Light9EffectListing } from "./effects/Light9EffectListing";
+export { Light9FadeUi } from "./fade/Light9FadeUi";
+export { Light9DeviceSettings } from "./live/Light9DeviceSettings";
+
+const panels: Map> = new Map([
+ ["light9-ascoltami-ui", ["ascoltami", "ascoltami"]],
+ ["light9-collector-ui", ["collector", "collector"]],
+ ["light9-device-settings", ["device-settings", "live"]],
+ ["light9-effect-listing", ["effect-listing" , "effectListing"]],
+ ["light9-fade-ui", ["fade", "fade"]],
+]);
+
+export function panelElementNames(): string[] {
+ return Array.from(panels.keys());
+}
+
+export function panelUrl(elem: string): string {
+ const row = panels.get(elem);
+ if (!row) throw new Error("No panel: " + elem);
+ return "/" + row[1] + "/";
+ }
+
+export function panelDisplayName(elem: string): string {
+ const row = panels.get(elem);
+ if (!row) throw new Error("No panel: " + elem);
+ return row[0];
+}
\ No newline at end of file