ADR-013 Phase 3: generic map-overlays renderer (Path A)

Wires the ADR-010 get_map_overlays hook into the floor map so a plugin decorates
markers as JSON, no map code. ShopFloorMap fetches /api/pluginui/map-overlays,
then each overlay's endpoint (per-asset [{assetid, color, label}]), joins by
assetid, and draws a ring or badge circleMarker on matching markers plus a
legend entry - all as extra Leaflet layers cleared and redrawn with the markers.

Aligned the measuringtools calibration overlay endpoint to the documented
contract: it now returns {assetid, color, label} (was {calibrationstatus,
statuscolor}) and only decorates due/overdue tools.

Additive + guarded (assetid null check, per-endpoint try/catch, cleanup on
re-render), so the map degrades to no decorations on any failure. Verified: the
overlay endpoint serves the contract shape, the map renders without error, and
the frontend builds. A populated badge needs a site that actually places
measuring tools on its map (this dataset places none). 38 measuringtools/pluginui
tests, 58 vitest, build + naming green.
This commit is contained in:
cproudlock
2026-07-18 23:10:09 -04:00
parent 8a2f984393
commit 296b6e024b
3 changed files with 105 additions and 6 deletions

View File

@@ -363,13 +363,18 @@ def map_overlay():
"""
today = date.today()
query = db.session.query(MeasuringTool).join(Asset).filter(Asset.isactive == True)
# Overlay contract (ADR-010): [{assetid, color, label}] joined by assetid.
# Only decorate tools that are actually due/overdue - a marker with no entry
# gets no badge.
data = []
for tool in query.all():
status = derive_status(tool.nextcalibrationdate, today)
if status not in ('overdue', 'duesoon'):
continue
data.append({
'assetid': tool.assetid,
'calibrationstatus': status,
'statuscolor': STATUS_COLORS.get(status, STATUS_COLORS['unknown']),
'color': STATUS_COLORS.get(status, STATUS_COLORS['unknown']),
'label': 'Overdue' if status == 'overdue' else 'Due soon',
})
return success_response(data)