Replace the old Lisp-like array expression representation (["AND", ["PARAM", ...], ...]) with a class hierarchy rooted in an abstract Expression class (Literal, Parameter, Binary, Unary, FunctionCall, Conditional). This gives compile-time type safety to expression construction, evaluation, and pattern matching. Key changes: - New lib/common/expression.ts defines the class hierarchy with map/evaluate/toString methods - Rewrite parser as hand-rolled recursive descent, removing the parsimmon dependency - Extend Path with a colon separator to unify parameter identity and attributes into a single address space (e.g. "Device.WiFi.SSID.1.Name:writable"). The colon field tracks how many trailing segments are attribute qualifiers. PathSet rewritten with separate param/attr segment indexes - Flatten device attribute representation in the UI to colon-delimited keys mirroring the new path syntax
92 lines
3.1 KiB
TypeScript
92 lines
3.1 KiB
TypeScript
import { ClosureComponent, Component } from "mithril";
|
|
import { m } from "../components.ts";
|
|
import * as taskQueue from "../task-queue.ts";
|
|
import * as notifications from "../notifications.ts";
|
|
import * as store from "../store.ts";
|
|
|
|
const component: ClosureComponent = (): Component => {
|
|
return {
|
|
view: (vnode) => {
|
|
const device = vnode.attrs["device"];
|
|
|
|
const buttons = [];
|
|
|
|
buttons.push(
|
|
m(
|
|
"button.px-4 py-2 border border-stone-300 shadow-xs text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed",
|
|
{
|
|
title: "Reboot device",
|
|
onclick: () => {
|
|
taskQueue.queueTask({
|
|
name: "reboot",
|
|
device: device["DeviceID.ID"],
|
|
});
|
|
},
|
|
},
|
|
"Reboot",
|
|
),
|
|
);
|
|
|
|
buttons.push(
|
|
m(
|
|
"button.px-4 py-2 border border-stone-300 shadow-xs text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed",
|
|
{
|
|
title: "Factory reset device",
|
|
onclick: () => {
|
|
taskQueue.queueTask({
|
|
name: "factoryReset",
|
|
device: device["DeviceID.ID"],
|
|
});
|
|
},
|
|
},
|
|
"Reset",
|
|
),
|
|
);
|
|
|
|
buttons.push(
|
|
m(
|
|
"button.px-4 py-2 border border-stone-300 shadow-xs text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed",
|
|
{
|
|
title: "Push a firmware or a config file",
|
|
onclick: () => {
|
|
taskQueue.stageDownload({
|
|
name: "download",
|
|
devices: [device["DeviceID.ID"]],
|
|
});
|
|
},
|
|
},
|
|
"Push file",
|
|
),
|
|
);
|
|
|
|
buttons.push(
|
|
m(
|
|
"button.px-4 py-2 border border-stone-300 shadow-xs text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed",
|
|
{
|
|
title: "Delete device",
|
|
onclick: () => {
|
|
if (!confirm("Deleting this device. Are you sure?")) return;
|
|
const deviceId = device["DeviceID.ID"];
|
|
|
|
store
|
|
.deleteResource("devices", deviceId)
|
|
.then(() => {
|
|
notifications.push("success", `${deviceId}: Device deleted`);
|
|
m.route.set("/devices");
|
|
})
|
|
.catch((err) => {
|
|
notifications.push("error", err.message);
|
|
});
|
|
},
|
|
},
|
|
"Delete",
|
|
),
|
|
);
|
|
|
|
return m("div.flex gap-3 mt-4", buttons);
|
|
},
|
|
};
|
|
};
|
|
|
|
export default component;
|