feat(frontend): always-visible gun bays, idle/plugged/charging lamp language, self-service password
- Control renders every gun declared in the chargers registry, even when the charger is offline or has not reported that connector yet (state shows Offline / No status yet in gray) - owner-specified state language: gray = idle, pulsing blue = cable in the socket (Preparing), green = charging; suspended/finishing = steady blue; fault = red - POST /api/me/password (requires current password) + /account page, username in the topbar links to it - smoke test: 58 checks (password change round-trip incl. old-password invalidation)
This commit is contained in:
@@ -9,6 +9,7 @@ import Dashboard from "./pages/Dashboard";
|
||||
import History from "./pages/History";
|
||||
import Cards from "./pages/Cards";
|
||||
import Users from "./pages/Users";
|
||||
import Account from "./pages/Account";
|
||||
|
||||
export default function App() {
|
||||
const { me, authChecked, setMe } = useApp();
|
||||
@@ -46,6 +47,7 @@ export default function App() {
|
||||
<Route element={<Layout />}>
|
||||
<Route path="/" element={<Dashboard />} />
|
||||
<Route path="/history" element={<History />} />
|
||||
<Route path="/account" element={<Account />} />
|
||||
{admin && <Route path="/cards" element={<Cards />} />}
|
||||
{admin && <Route path="/users" element={<Users />} />}
|
||||
<Route path="*" element={<Navigate to="/" replace state={{ from: location }} />} />
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
/** The signature element: a physical indicator lamp, like the ones on the
|
||||
* charger cabinet itself. Tone encodes state everywhere in the app. */
|
||||
export type LampTone = "off" | "green" | "amber" | "red" | "pulse";
|
||||
* charger cabinet itself. Owner-specified state language:
|
||||
* gray = idle · pulsing blue = cable plugged · green = charging · red = fault */
|
||||
export type LampTone = "off" | "green" | "blue" | "bluepulse" | "amber" | "red";
|
||||
|
||||
const TONE_CLASS: Record<LampTone, string> = {
|
||||
off: "lamp",
|
||||
green: "lamp lamp--green",
|
||||
blue: "lamp lamp--blue",
|
||||
bluepulse: "lamp lamp--blue lamp--pulse-blue",
|
||||
amber: "lamp lamp--amber",
|
||||
red: "lamp lamp--red",
|
||||
pulse: "lamp lamp--green lamp--pulse",
|
||||
};
|
||||
|
||||
export function Lamp({ tone, title }: { tone: LampTone; title?: string }) {
|
||||
@@ -15,20 +17,20 @@ export function Lamp({ tone, title }: { tone: LampTone; title?: string }) {
|
||||
}
|
||||
|
||||
export function statusTone(ocppStatus: string, charging: boolean): LampTone {
|
||||
if (charging) return "pulse";
|
||||
if (charging || ocppStatus === "Charging") return "green";
|
||||
switch (ocppStatus) {
|
||||
case "Charging":
|
||||
return "pulse";
|
||||
case "Preparing":
|
||||
return "bluepulse"; // cable in the socket, waiting to start
|
||||
case "SuspendedEV":
|
||||
case "SuspendedEVSE":
|
||||
case "Finishing":
|
||||
return "blue"; // still plugged, not delivering
|
||||
case "Reserved":
|
||||
return "amber";
|
||||
case "Available":
|
||||
return "green";
|
||||
case "Faulted":
|
||||
case "Unavailable":
|
||||
return "red";
|
||||
default:
|
||||
return "off";
|
||||
return "off"; // Available (idle), Offline, no status yet
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,9 @@ export default function Layout() {
|
||||
))}
|
||||
</nav>
|
||||
<div className="topbar__user">
|
||||
<span className="topbar__who">{me?.name}</span>
|
||||
<NavLink to="/account" className="topbar__who" title="Account settings">
|
||||
{me?.name}
|
||||
</NavLink>
|
||||
<button className="btn btn--ghost btn--sm" onClick={logout}>
|
||||
Log out
|
||||
</button>
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
import { FormEvent, useState } from "react";
|
||||
import { api } from "../api";
|
||||
import { useApp } from "../store";
|
||||
|
||||
export default function Account() {
|
||||
const me = useApp((s) => s.me)!;
|
||||
const toast = useApp((s) => s.toast);
|
||||
const [current, setCurrent] = useState("");
|
||||
const [next, setNext] = useState("");
|
||||
const [repeat, setRepeat] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
async function submit(e: FormEvent) {
|
||||
e.preventDefault();
|
||||
if (next !== repeat) {
|
||||
toast("New passwords do not match", "error");
|
||||
return;
|
||||
}
|
||||
setBusy(true);
|
||||
try {
|
||||
await api.post("/me/password", { current_password: current, new_password: next });
|
||||
toast("Password changed");
|
||||
setCurrent("");
|
||||
setNext("");
|
||||
setRepeat("");
|
||||
} catch (err) {
|
||||
toast((err as Error).message, "error");
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="panel" style={{ maxWidth: 440 }}>
|
||||
<header className="panel__head">
|
||||
<h2>Account</h2>
|
||||
<span className="panel__meta mono">{me.name}</span>
|
||||
</header>
|
||||
<form onSubmit={submit} className="cardform" style={{ marginTop: 0 }}>
|
||||
<label className="field">
|
||||
<span>Current password</span>
|
||||
<input
|
||||
type="password"
|
||||
value={current}
|
||||
onChange={(e) => setCurrent(e.target.value)}
|
||||
autoComplete="current-password"
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
<label className="field">
|
||||
<span>New password</span>
|
||||
<input
|
||||
type="password"
|
||||
value={next}
|
||||
onChange={(e) => setNext(e.target.value)}
|
||||
autoComplete="new-password"
|
||||
required
|
||||
minLength={4}
|
||||
/>
|
||||
</label>
|
||||
<label className="field">
|
||||
<span>Repeat new password</span>
|
||||
<input
|
||||
type="password"
|
||||
value={repeat}
|
||||
onChange={(e) => setRepeat(e.target.value)}
|
||||
autoComplete="new-password"
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
<div className="cardform__actions">
|
||||
<button className="btn btn--primary" disabled={busy}>
|
||||
{busy ? "Changing…" : "Change password"}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -14,31 +14,80 @@ interface Gun {
|
||||
connector: number;
|
||||
label: string;
|
||||
chargerLabel: string;
|
||||
ocppStatus: string;
|
||||
ocppStatus: string; // OCPP status, or "Offline" / "NoStatus" synthesized here
|
||||
tx: (ActiveTx & { txId: string }) | null;
|
||||
}
|
||||
|
||||
/** Every gun the system knows about is ALWAYS shown: the chargers registry
|
||||
* defines the cards, live connector reports and transactions overlay state. */
|
||||
function gunsFrom(status: Status): Gun[] {
|
||||
const txByGun = new Map<string, ActiveTx & { txId: string }>();
|
||||
for (const [txId, tx] of Object.entries(status.active_transactions))
|
||||
txByGun.set(`${tx.cp}/${tx.connector}`, { ...tx, txId });
|
||||
const guns = new Map<string, Gun>();
|
||||
|
||||
return Object.entries(status.connectors)
|
||||
.map(([key, ocppStatus]) => {
|
||||
const [cp, conn] = [key.slice(0, key.lastIndexOf("/")), key.slice(key.lastIndexOf("/") + 1)];
|
||||
return { cp, connector: Number(conn), ocppStatus };
|
||||
})
|
||||
.filter((g) => g.connector > 0)
|
||||
.sort((a, b) => a.cp.localeCompare(b.cp) || a.connector - b.connector)
|
||||
.map((g) => {
|
||||
const meta = status.chargers[g.cp] ?? {};
|
||||
return {
|
||||
...g,
|
||||
label: meta.guns?.[String(g.connector)] ?? `Gun ${g.connector}`,
|
||||
chargerLabel: meta.label ?? g.cp,
|
||||
tx: txByGun.get(`${g.cp}/${g.connector}`) ?? null,
|
||||
};
|
||||
});
|
||||
for (const [cp, meta] of Object.entries(status.chargers)) {
|
||||
const online = cp in status.connected;
|
||||
for (const [conn, label] of Object.entries(meta.guns ?? {})) {
|
||||
guns.set(`${cp}/${conn}`, {
|
||||
cp,
|
||||
connector: Number(conn),
|
||||
label,
|
||||
chargerLabel: meta.label ?? cp,
|
||||
ocppStatus: online ? "NoStatus" : "Offline",
|
||||
tx: null,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for (const [key, ocppStatus] of Object.entries(status.connectors)) {
|
||||
const cp = key.slice(0, key.lastIndexOf("/"));
|
||||
const connector = Number(key.slice(key.lastIndexOf("/") + 1));
|
||||
if (connector <= 0) continue; // connector 0 = the whole charge point
|
||||
const existing = guns.get(`${cp}/${connector}`);
|
||||
if (existing) existing.ocppStatus = ocppStatus;
|
||||
else
|
||||
guns.set(`${cp}/${connector}`, {
|
||||
cp,
|
||||
connector,
|
||||
label: `Gun ${connector}`,
|
||||
chargerLabel: status.chargers[cp]?.label ?? cp,
|
||||
ocppStatus,
|
||||
tx: null,
|
||||
});
|
||||
}
|
||||
|
||||
for (const [txId, tx] of Object.entries(status.active_transactions)) {
|
||||
const gun = guns.get(`${tx.cp}/${tx.connector}`);
|
||||
if (gun) gun.tx = { ...tx, txId };
|
||||
}
|
||||
|
||||
return [...guns.values()].sort(
|
||||
(a, b) => a.cp.localeCompare(b.cp) || a.connector - b.connector,
|
||||
);
|
||||
}
|
||||
|
||||
/** Chip text + tone per the owner's state language. */
|
||||
function gunState(gun: Gun): { label: string; cls: string } {
|
||||
if (gun.tx) return { label: "Charging", cls: "charging" };
|
||||
switch (gun.ocppStatus) {
|
||||
case "Charging":
|
||||
return { label: "Charging", cls: "charging" };
|
||||
case "Preparing":
|
||||
return { label: "Plugged in", cls: "plugged" };
|
||||
case "SuspendedEV":
|
||||
case "SuspendedEVSE":
|
||||
return { label: "Paused", cls: "plugged" };
|
||||
case "Finishing":
|
||||
return { label: "Finishing", cls: "plugged" };
|
||||
case "Available":
|
||||
return { label: "Idle", cls: "idle" };
|
||||
case "Offline":
|
||||
return { label: "Offline", cls: "offline" };
|
||||
case "NoStatus":
|
||||
return { label: "No status yet", cls: "offline" };
|
||||
case "Faulted":
|
||||
return { label: "Fault", cls: "faulted" };
|
||||
default:
|
||||
return { label: gun.ocppStatus, cls: "idle" };
|
||||
}
|
||||
}
|
||||
|
||||
function GunBay({ gun, scopes }: { gun: Gun; scopes: string[] }) {
|
||||
@@ -60,19 +109,18 @@ function GunBay({ gun, scopes }: { gun: Gun; scopes: string[] }) {
|
||||
(r) => toast(`Stop command: ${r.remote_stop}`),
|
||||
);
|
||||
|
||||
const state = gunState(gun);
|
||||
return (
|
||||
<article className="bay">
|
||||
<header className="bay__head">
|
||||
<span className="bay__eyebrow">{gun.chargerLabel}</span>
|
||||
<Lamp tone={statusTone(gun.ocppStatus, !!gun.tx)} title={gun.ocppStatus} />
|
||||
<Lamp tone={statusTone(gun.ocppStatus, !!gun.tx)} title={state.label} />
|
||||
</header>
|
||||
<h2 className="bay__title">{gun.label}</h2>
|
||||
<div className="bay__status">
|
||||
<span className={`chip chip--${gun.tx ? "live" : gun.ocppStatus.toLowerCase()}`}>
|
||||
{gun.tx ? "Charging" : gun.ocppStatus}
|
||||
</span>
|
||||
<span className={`chip chip--${state.cls}`}>{state.label}</span>
|
||||
{gun.ocppStatus === "Preparing" && !gun.tx && (
|
||||
<span className="bay__hint">cable plugged — ready to start</span>
|
||||
<span className="bay__hint">cable in the socket — ready to start</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -184,10 +232,13 @@ export default function Dashboard() {
|
||||
<Lamp tone="red" />
|
||||
<div>
|
||||
<h2>Charger offline</h2>
|
||||
<p>Waiting for the charge point to dial in. Guns appear here as soon as it connects.</p>
|
||||
<p>Waiting for the charge point to dial in — controls enable as soon as it connects.</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{!guns.length && !offline && (
|
||||
<p className="empty">Connected, waiting for the first gun status report…</p>
|
||||
)}
|
||||
<div className="bays">
|
||||
{guns.map((g) => (
|
||||
<GunBay key={`${g.cp}/${g.connector}`} gun={g} scopes={me.scopes} />
|
||||
|
||||
+27
-8
@@ -14,7 +14,8 @@
|
||||
--line: #d8ddda;
|
||||
--copper: #b25c28; /* busbar copper — the accent */
|
||||
--copper-deep: #8f4a20;
|
||||
--live: #178a5c; /* DC-on green */
|
||||
--live: #178a5c; /* DC-on green: charging */
|
||||
--blue: #2160c4; /* plugged-in blue */
|
||||
--amber: #c07f00;
|
||||
--red: #bf3527;
|
||||
--lamp-off: #c4ccc8;
|
||||
@@ -35,6 +36,7 @@
|
||||
--copper: #d07a3e;
|
||||
--copper-deep: #b25c28;
|
||||
--live: #2fae7c;
|
||||
--blue: #4f8ee8;
|
||||
--amber: #d99a1b;
|
||||
--red: #d8503f;
|
||||
--lamp-off: #39433f;
|
||||
@@ -90,13 +92,23 @@ button, input, select { font: inherit; color: inherit; }
|
||||
background: radial-gradient(circle at 35% 30%, #ff9d8f, var(--red) 70%);
|
||||
box-shadow: inset 0 0 2px rgb(0 0 0 / 0.25), 0 0 8px color-mix(in srgb, var(--red) 55%, transparent);
|
||||
}
|
||||
.lamp--pulse { animation: lamp-pulse 1.6s ease-in-out infinite; }
|
||||
@keyframes lamp-pulse {
|
||||
0%, 100% { box-shadow: inset 0 0 2px rgb(0 0 0 / 0.25), 0 0 4px color-mix(in srgb, var(--live) 40%, transparent); }
|
||||
50% { box-shadow: inset 0 0 2px rgb(0 0 0 / 0.25), 0 0 14px color-mix(in srgb, var(--live) 85%, transparent); }
|
||||
.lamp--blue {
|
||||
background: radial-gradient(circle at 35% 30%, #9ec4ff, var(--blue) 70%);
|
||||
box-shadow: inset 0 0 2px rgb(0 0 0 / 0.25), 0 0 8px color-mix(in srgb, var(--blue) 55%, transparent);
|
||||
}
|
||||
.lamp--pulse-blue { animation: lamp-pulse-blue 1.5s ease-in-out infinite; }
|
||||
@keyframes lamp-pulse-blue {
|
||||
0%, 100% {
|
||||
box-shadow: inset 0 0 2px rgb(0 0 0 / 0.25), 0 0 3px color-mix(in srgb, var(--blue) 35%, transparent);
|
||||
filter: brightness(0.85);
|
||||
}
|
||||
50% {
|
||||
box-shadow: inset 0 0 2px rgb(0 0 0 / 0.25), 0 0 15px color-mix(in srgb, var(--blue) 90%, transparent);
|
||||
filter: brightness(1.15);
|
||||
}
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.lamp--pulse { animation: none; }
|
||||
.lamp--pulse-blue { animation: none; }
|
||||
* { transition: none !important; }
|
||||
}
|
||||
|
||||
@@ -140,7 +152,12 @@ button, input, select { font: inherit; color: inherit; }
|
||||
}
|
||||
|
||||
.topbar__user { display: flex; align-items: center; gap: 10px; }
|
||||
.topbar__who { font-family: var(--font-mono); font-size: 13px; color: var(--ink-dim); }
|
||||
.topbar__who {
|
||||
font-family: var(--font-mono); font-size: 13px; color: var(--ink-dim);
|
||||
text-decoration: none; padding: 4px 8px; border-radius: 6px;
|
||||
}
|
||||
.topbar__who:hover { color: var(--ink); background: var(--panel-inset); }
|
||||
.topbar__who.active { color: var(--copper-deep); }
|
||||
|
||||
.alert {
|
||||
display: flex; align-items: center; gap: 10px;
|
||||
@@ -263,7 +280,9 @@ button, input, select { font: inherit; color: inherit; }
|
||||
border: 1px solid var(--line);
|
||||
}
|
||||
.chip--live, .chip--charging { background: color-mix(in srgb, var(--live) 14%, transparent); color: var(--live); border-color: color-mix(in srgb, var(--live) 40%, transparent); }
|
||||
.chip--preparing, .chip--finishing { background: color-mix(in srgb, var(--amber) 14%, transparent); color: var(--amber); border-color: color-mix(in srgb, var(--amber) 40%, transparent); }
|
||||
.chip--plugged { background: color-mix(in srgb, var(--blue) 13%, transparent); color: var(--blue); border-color: color-mix(in srgb, var(--blue) 40%, transparent); }
|
||||
.chip--idle { /* the quiet gray default */ }
|
||||
.chip--offline { opacity: 0.7; }
|
||||
.chip--faulted, .chip--unavailable { background: color-mix(in srgb, var(--red) 12%, transparent); color: var(--red); border-color: color-mix(in srgb, var(--red) 40%, transparent); }
|
||||
.chip--card { background: color-mix(in srgb, var(--copper) 13%, transparent); color: var(--copper-deep); border-color: color-mix(in srgb, var(--copper) 40%, transparent); }
|
||||
.chip--app { background: color-mix(in srgb, var(--live) 12%, transparent); color: var(--live); border-color: color-mix(in srgb, var(--live) 35%, transparent); }
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"root":["./src/app.tsx","./src/api.ts","./src/main.tsx","./src/queries.ts","./src/store.ts","./src/types.ts","./src/components/lamp.tsx","./src/components/layout.tsx","./src/pages/cards.tsx","./src/pages/dashboard.tsx","./src/pages/history.tsx","./src/pages/login.tsx","./src/pages/users.tsx"],"version":"5.9.3"}
|
||||
{"root":["./src/app.tsx","./src/api.ts","./src/main.tsx","./src/queries.ts","./src/store.ts","./src/types.ts","./src/components/lamp.tsx","./src/components/layout.tsx","./src/pages/account.tsx","./src/pages/cards.tsx","./src/pages/dashboard.tsx","./src/pages/history.tsx","./src/pages/login.tsx","./src/pages/users.tsx"],"version":"5.9.3"}
|
||||
Reference in New Issue
Block a user