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")!);