Gear can be added, edited and removed on Computers > Gear, with an optional watching key; Check now sits on the Map tab
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
+18
-2
@@ -497,6 +497,16 @@ class Site:
|
||||
for s in cfg.get("dante_switches", []):
|
||||
rows.setdefault("Netgear " + s, {"name": "Netgear " + s, "kind": "Dante switch", "address": s, "watched_by": {"dante"}, "light": "unknown",
|
||||
"reason": "", "location": gear.get("Netgear " + s, {}).get("location", ""), "notes": ""})
|
||||
for name, g in gear.items(): # gear added by hand, watched by no key
|
||||
if not isinstance(g, dict):
|
||||
continue
|
||||
row = rows.setdefault(name, {"name": name, "kind": g.get("kind") or "device", "address": g.get("address"), "watched_by": set(), "light": "not_needed",
|
||||
"reason": "not watched", "location": g.get("location", ""), "notes": g.get("notes", "")})
|
||||
if g.get("kind"):
|
||||
row["kind"] = g["kind"]
|
||||
if g.get("address") and not row.get("address"):
|
||||
row["address"] = g["address"]
|
||||
row["own"] = True
|
||||
out = []
|
||||
for r in rows.values():
|
||||
r["watched_by"] = sorted(r["watched_by"])
|
||||
@@ -877,8 +887,14 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
||||
if path == "/api/gear":
|
||||
cfg = site.load()
|
||||
gear = dict(cfg.get("gear") or {})
|
||||
name = str(body.get("name", ""))[:80]
|
||||
gear[name] = {"location": str(body.get("location", ""))[:120], "notes": str(body.get("notes", ""))[:300]}
|
||||
name = str(body.get("name", "")).strip()[:80]
|
||||
if not name:
|
||||
return self.send(400, {"error": "a name is needed"})
|
||||
if body.get("remove"):
|
||||
gear.pop(name, None)
|
||||
else:
|
||||
entry = {k: str(body.get(k, "")).strip()[:300] for k in ("location", "notes", "kind", "address")}
|
||||
gear[name] = {k: v for k, v in entry.items() if v}
|
||||
draft = site.draft.read() or {"config": cfg}
|
||||
draft_cfg = dict(draft["config"], gear=gear)
|
||||
d, _ = site.draft.update(draft_cfg, who, site.cfg_sha)
|
||||
|
||||
Reference in New Issue
Block a user