From 3387f8689e5253cd945d695ca15c7e02104c3a60 Mon Sep 17 00:00:00 2001 From: Julian Cuni Date: Sun, 12 Jul 2026 08:37:20 +0200 Subject: [PATCH] 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) --- backend/routes.py | 21 ++++++ frontend/src/App.tsx | 2 + frontend/src/components/Lamp.tsx | 20 +++--- frontend/src/components/Layout.tsx | 4 +- frontend/src/pages/Account.tsx | 79 ++++++++++++++++++++++ frontend/src/pages/Dashboard.tsx | 103 +++++++++++++++++++++-------- frontend/src/styles.css | 35 +++++++--- frontend/tsconfig.tsbuildinfo | 2 +- wiki/entities/backend.md | 2 +- wiki/entities/frontend.md | 5 +- wiki/log.md | 4 ++ 11 files changed, 229 insertions(+), 48 deletions(-) create mode 100644 frontend/src/pages/Account.tsx diff --git a/backend/routes.py b/backend/routes.py index f1ba68e..44fa256 100644 --- a/backend/routes.py +++ b/backend/routes.py @@ -107,6 +107,27 @@ async def me(user: dict = Depends(current_user)): return users.public_view(user["name"], user) +class PasswordBody(BaseModel): + current_password: str + new_password: str + + +@router.post("/me/password") +async def change_own_password(body: PasswordBody, user: dict = Depends(current_user)): + """Self-service password change — requires the current password. + (Admins can still reset anyone's via PUT /api/users/.)""" + entry = CONFIG["users"].get(user["name"]) + if entry is None: + raise HTTPException(409, "no user account — the API is in open mode") + if not users.verify_password(body.current_password, entry.get("password", "")): + raise HTTPException(403, "current password is wrong") + if len(body.new_password) < 4: + raise HTTPException(400, "new password must be at least 4 characters") + users.set_user(user["name"], password=body.new_password) + log.info("password changed by %r", user["name"]) + return {"changed": True} + + # ---- status & journals ---- @router.get("/status") async def api_status(user: dict = Depends(current_user)): diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 495b191..f4474ec 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -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() { }> } /> } /> + } /> {admin && } />} {admin && } />} } /> diff --git a/frontend/src/components/Lamp.tsx b/frontend/src/components/Lamp.tsx index 82f6d69..6c1c632 100644 --- a/frontend/src/components/Lamp.tsx +++ b/frontend/src/components/Lamp.tsx @@ -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 = { 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 } } diff --git a/frontend/src/components/Layout.tsx b/frontend/src/components/Layout.tsx index eda7cc9..69c0fb8 100644 --- a/frontend/src/components/Layout.tsx +++ b/frontend/src/components/Layout.tsx @@ -55,7 +55,9 @@ export default function Layout() { ))}
- {me?.name} + + {me?.name} + diff --git a/frontend/src/pages/Account.tsx b/frontend/src/pages/Account.tsx new file mode 100644 index 0000000..ce74d92 --- /dev/null +++ b/frontend/src/pages/Account.tsx @@ -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 ( +
+
+

Account

+ {me.name} +
+
+ + + +
+ +
+
+
+ ); +} diff --git a/frontend/src/pages/Dashboard.tsx b/frontend/src/pages/Dashboard.tsx index 453555a..e0d1ab4 100644 --- a/frontend/src/pages/Dashboard.tsx +++ b/frontend/src/pages/Dashboard.tsx @@ -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(); - for (const [txId, tx] of Object.entries(status.active_transactions)) - txByGun.set(`${tx.cp}/${tx.connector}`, { ...tx, txId }); + const guns = new Map(); - 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 (
{gun.chargerLabel} - +

{gun.label}

- - {gun.tx ? "Charging" : gun.ocppStatus} - + {state.label} {gun.ocppStatus === "Preparing" && !gun.tx && ( - cable plugged — ready to start + cable in the socket — ready to start )}
@@ -184,10 +232,13 @@ export default function Dashboard() {

Charger offline

-

Waiting for the charge point to dial in. Guns appear here as soon as it connects.

+

Waiting for the charge point to dial in — controls enable as soon as it connects.

)} + {!guns.length && !offline && ( +

Connected, waiting for the first gun status report…

+ )}
{guns.map((g) => ( diff --git a/frontend/src/styles.css b/frontend/src/styles.css index be474b8..7d254a8 100644 --- a/frontend/src/styles.css +++ b/frontend/src/styles.css @@ -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); } diff --git a/frontend/tsconfig.tsbuildinfo b/frontend/tsconfig.tsbuildinfo index 483f449..b03717f 100644 --- a/frontend/tsconfig.tsbuildinfo +++ b/frontend/tsconfig.tsbuildinfo @@ -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"} \ No newline at end of file +{"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"} \ No newline at end of file diff --git a/wiki/entities/backend.md b/wiki/entities/backend.md index 1f30615..fab1792 100644 --- a/wiki/entities/backend.md +++ b/wiki/entities/backend.md @@ -26,7 +26,7 @@ backend/ (run: venv\Scripts\python -m backend.main, from the repo root) - `ws://:9000/` — OCPP WebSocket (catch-all path, the JC-6620 dials in) - `GET /` — **the [[frontend|React panel]]** served from `../frontend/dist/` with SPA fallback (deep links land on index.html; `/api/*` + `/docs` excluded; 503 with instructions if not built) -- `POST /api/login|logout`, `GET /api/me` — username/password → 30-day session (cookie + bearer) +- `POST /api/login|logout`, `GET /api/me`, `POST /api/me/password` (self-service change, current password required) — username/password → 30-day session (cookie + bearer) - `GET /api/sessions?limit&cp&connector` — **charging history: who / when / kWh** (visibility: own sessions + guns within scope; admin sees all); `GET /api/sessions/{tx}/samples` — per-minute energy/power/SoC for charts - `GET /api/status` — connected chargers, gun states, active transactions, auth events + pending-card count (admin), relays (filtered to what the caller may control) - `GET /api/events?limit&event=` — tail the journal (admin) diff --git a/wiki/entities/frontend.md b/wiki/entities/frontend.md index 7f8dea1..1f62e72 100644 --- a/wiki/entities/frontend.md +++ b/wiki/entities/frontend.md @@ -18,7 +18,8 @@ The React control panel (built 2026-07-11, replacing the single-file vanilla-JS | Route | Who | What | |---|---|---| -| `/` (Control) | all | one "bay" card per gun (labels from the chargers registry): status lamp, Start/Stop gated by scope **and** gun readiness; live session shows who/via/duration; relay toggles with on-demand live read | +| `/` (Control) | all | one "bay" card per gun — **every registry-declared gun always renders**, even offline; status lamp, Start/Stop gated by scope **and** gun readiness; live session shows who/via/duration; relay toggles with on-demand live read | +| `/account` | all | self-service password change (current password required) | | `/history` | all (filtered by scope) | the audit table: **who charged, via Card or In-app, which gun, when, duration, kWh**; total kWh; live sessions flagged | | `/cards` | admin | **pending cards awaiting review** (approve → name + owner + gun restrictions in one step; reject → silenced), enrolled cards with owner/guns editing, rejected list with un-reject | | `/users` | admin | user CRUD with the **permission matrix** — admin toggle, per-gun and per-relay checkboxes rendered from `GET /api/permissions` (no raw scope strings in the UI) | @@ -27,4 +28,4 @@ An amber **notification banner + nav badge** appears for admins whenever unknown ## Design -Instrument-panel direction grounded in the hardware: porcelain/graphite surfaces (light + dark via `prefers-color-scheme`), **copper-busbar accent**, IBM Plex Mono for telemetry/identifiers, Archivo for UI. Signature element: the **indicator lamp** (radial LED with glow) encoding state everywhere — green=available, pulsing green=charging, amber=preparing/pending, red=fault/denied. Reduced motion respected; keyboard focus visible. +Instrument-panel direction grounded in the hardware: porcelain/graphite surfaces (light + dark via `prefers-color-scheme`), **copper-busbar accent**, IBM Plex Mono for telemetry/identifiers, Archivo for UI. Signature element: the **indicator lamp** (radial LED with glow) encoding state everywhere, in the owner-specified language (2026-07-12): **gray = idle, pulsing blue = cable in the socket, green = charging**, red = fault/offline banner, amber = pending cards. Reduced motion respected; keyboard focus visible. diff --git a/wiki/log.md b/wiki/log.md index 8647061..3987bc9 100644 --- a/wiki/log.md +++ b/wiki/log.md @@ -83,3 +83,7 @@ Owner pushback: two persistence stores (sessions.db + a config.json that doubled ## [2026-07-11] meta | React frontend; pending-card review workflow; auth-method audit Owner: full frontend revision (React + routing + zustand + TanStack Query, Vite proxy in dev, static build served by backend, professional look) and backend fixes: permissions must be understandable, cards must connect to users, unknown card taps must notify the admin for approve/reject, and sessions must audit HOW authorization happened. Backend: learn mode REMOVED -> pending_cards/denied_cards workflow (unknown taps always refused, queued for review; pending count on /api/status as notification); sessions.method column (card|app); GET /api/permissions catalog. Frontend: new ../frontend/ (React 19, instrument-panel design, copper accent, indicator-lamp signature, bundled fonts); pages Control/History/Cards/Users; permission checkbox matrix; approve-with-owner-link in one step. Old backend/static vanilla panel deleted; seen_tags.json gone. Smoke: 54 checks. Created [[frontend]]; updated [[backend]], [[authorization]], [[overview]], [[architecture-plan]], [[index]], root CLAUDE.md. + +## [2026-07-12] meta | Panel live on the owner's phone; gun state language; password self-service + +Owner confirmed the React panel loads on the phone after backend restart. Changes on request: (1) both guns ALWAYS render on Control — gun cards come from the chargers registry, live reports only overlay state (offline/no-status shown gray); (2) new lamp/chip language: gray=idle, pulsing blue=cable plugged, green=charging; (3) POST /api/me/password + /account page — any user changes their own password (current password required; admin reset via PUT /api/users stays). Smoke: 58 checks. Updated [[frontend]], [[backend]].