From d10b817fdc88022b735fae2d915b2b330635e511 Mon Sep 17 00:00:00 2001 From: Inferencebot Date: Fri, 13 Nov 2026 21:01:38 +0000 Subject: [PATCH] dashboard: the co-op charts come from the shared definitions (Money included) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The dashboard kept its own TREND_CONF with its own titles ("The co-op over time", "What the co-op spent (members + the co-op's own accounts)") and its own toggles — the other half of the drift the panel just lost. The metric list is now CoOpChart.CHART_METRICS, the chart is drawn by the shared renderChart(), and the buttons are built from the shared list, so members and stewards read the same charts with the same names. Money arrives as a metric here too, fed by a new /api/money-series proxy to the portal's /broker/money-series — the co-op's cumulative revenue, cumulative token spend and OC balance (a gap before snapshots began, never a zero). Deleting the local TREND_CONF/trendVal/trendLabel also removes the second set of formatters. Two page-blanking bugs caught by check-page-js.sh before they could ship: a destructured fmtMoney colliding with this page's own (duplicate const), and `esc` (which the panel defines and this page does not — it uses escapeHtml). Harness extended: the money metric draws 2 lines + a single-point balance marker, the tooltip lists every series and reports the unmeasured balance as not measured, the metric row equals the shared list filtered by METRIC_SOURCE, and a metric with no source says so. Geometry proof: 15 captured renders (5 metrics x 3 ranges) byte-identical to the predecessor with aria stripped. --- app/main.py | 193 +++++++++++++++++++++++-------------- dashboard-chart-harness.js | 47 +++++++++ 2 files changed, 169 insertions(+), 71 deletions(-) diff --git a/app/main.py b/app/main.py index 033cb29..9d09c94 100644 --- a/app/main.py +++ b/app/main.py @@ -196,6 +196,25 @@ async def api_metrics(request: Request): return JSONResponse({"error": e.detail}, status_code=e.status_code) +@app.get("/api/money-series") +async def api_money_series(request: Request): + """Revenue / token-spend / OC-balance series, for the Co-op usage view. + + Aggregate and non-personal, exactly like /api/metrics: cumulative revenue, + cumulative token spend, and the co-op's Open Collective balance — no member + identities. The co-op's finances are charted beside its other charts so + members and stewards see the same picture, from the same shared chart + definition (CoOpChart.CHART_METRICS "money"). + """ + identity = get_user_identity(request) + if not identity: + return JSONResponse({"error": "unauthenticated"}, status_code=401) + try: + return await broker_get(identity, "/broker/money-series") + except HTTPException as e: + return JSONResponse({"error": e.detail}, status_code=e.status_code) + + @app.post("/api/keys") async def api_create_key(request: Request): identity = get_user_identity(request) @@ -579,6 +598,9 @@ PAGE_HTML = """ .coop-stats .lbl { font-size: 12px; color: var(--muted); } .trend-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; } .coop-trend-body svg { display: block; width: 100%; height: auto; overflow: visible; } + .coop-legend { display: inline-flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); font-weight: 600; margin-left: auto; } + .coop-legend .key { display: inline-flex; align-items: center; gap: 5px; } + .coop-legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; } .board-row { display: flex; align-items: flex-start; gap: 14px; padding: 12px 0; border-top: 1px solid #f0ede6; @@ -811,20 +833,19 @@ PAGE_HTML = """