- Replace all hand-written CSS with Tailwind utility classes - Upgrade CodeMirror 5 to CodeMirror 6 (scoped @codemirror/* packages) - Redesign layout with responsive sidebar navigation using JSX/Mithril - Flatten admin routes (e.g. /admin/presets -> /presets) - Add "remember me" login option with 2-week persistent cookie - Add delete confirmation dialogs across admin pages - Upgrade esbuild from 0.21 to 0.27 and update browser targets - Add Inter and Roboto Mono variable fonts with subset script
79 lines
2.7 KiB
TypeScript
79 lines
2.7 KiB
TypeScript
import { ClosureComponent, Component } from "mithril";
|
|
import { m } from "../components.ts";
|
|
import * as taskQueue from "../task-queue.ts";
|
|
import * as store from "../store.ts";
|
|
import * as notifications from "../notifications.ts";
|
|
|
|
const component: ClosureComponent = (): Component => {
|
|
return {
|
|
view: (vnode) => {
|
|
const device = vnode.attrs["device"];
|
|
|
|
return m(
|
|
"button",
|
|
{
|
|
class:
|
|
"px-2.5 py-1.5 border border-transparent text-xs font-medium rounded-sm shadow-xs text-white bg-cyan-600 hover:bg-cyan-700 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500",
|
|
title: "Initiate session and refresh basic parameters",
|
|
onclick: (e) => {
|
|
e.target.disabled = true;
|
|
const params = Object.values(vnode.attrs["parameters"])
|
|
.map((exp) => {
|
|
if (!Array.isArray(exp) || exp[0] !== "PARAM") return null;
|
|
return store.evaluateExpression(exp[1], device) as string;
|
|
})
|
|
.filter((exp) => !!exp);
|
|
|
|
const task = {
|
|
name: "getParameterValues",
|
|
parameterNames: params,
|
|
device: device["DeviceID.ID"].value[0],
|
|
};
|
|
|
|
taskQueue
|
|
.commit(
|
|
[task],
|
|
(deviceId, err, connectionRequestStatus, tasks2) => {
|
|
if (err) {
|
|
notifications.push("error", `${deviceId}: ${err.message}`);
|
|
return;
|
|
}
|
|
|
|
for (const t of tasks2)
|
|
if (t.status === "stale") taskQueue.deleteTask(t);
|
|
|
|
if (connectionRequestStatus !== "OK") {
|
|
notifications.push(
|
|
"error",
|
|
`${deviceId}: ${connectionRequestStatus}`,
|
|
);
|
|
} else if (tasks2[0].status === "stale") {
|
|
notifications.push(
|
|
"error",
|
|
`${deviceId}: No contact from device`,
|
|
);
|
|
} else if (tasks2[0].status === "fault") {
|
|
notifications.push("error", `${deviceId}: Refresh faulted`);
|
|
} else {
|
|
notifications.push("success", `${deviceId}: Summoned`);
|
|
}
|
|
},
|
|
)
|
|
.then(() => {
|
|
e.target.disabled = false;
|
|
store.setTimestamp(Date.now());
|
|
})
|
|
.catch((err) => {
|
|
e.target.disabled = false;
|
|
notifications.push("error", err.message);
|
|
});
|
|
},
|
|
},
|
|
"Summon",
|
|
);
|
|
},
|
|
};
|
|
};
|
|
|
|
export default component;
|