From d4e5b11f71cfc2551e78f8c5933b60f3b4eebf54 Mon Sep 17 00:00:00 2001 From: Davide Scaini Date: Thu, 21 May 2026 20:32:54 +0200 Subject: [PATCH] admin: add Total imported and Last sync columns to Garmin sync table Matches the Strava sync table layout. Accumulates total_imported in garmin_sync.json state on each sync run; admin API exposes last_sync_at and total_imported from that file. --- bincio/extract/garmin_sync.py | 1 + bincio/serve/routers/admin.py | 13 +++++++++++++ site/src/pages/admin/index.astro | 14 ++++++++------ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/bincio/extract/garmin_sync.py b/bincio/extract/garmin_sync.py index 395c886..a27b24e 100644 --- a/bincio/extract/garmin_sync.py +++ b/bincio/extract/garmin_sync.py @@ -174,6 +174,7 @@ def garmin_sync_iter( # ── Persist sync state ───────────────────────────────────────────────────── state["last_sync_at"] = datetime.now(timezone.utc).strftime("%Y-%m-%d") + state["total_imported"] = state.get("total_imported", 0) + imported _save_sync_state(user_dir, state) yield { diff --git a/bincio/serve/routers/admin.py b/bincio/serve/routers/admin.py index ede2d27..953e0c8 100644 --- a/bincio/serve/routers/admin.py +++ b/bincio/serve/routers/admin.py @@ -607,6 +607,17 @@ async def admin_garmin_sync_status( user_dir = cf.parent handle = user_dir.name + last_sync: str | None = None + total_imported = 0 + sync_path = user_dir / "garmin_sync.json" + if sync_path.exists(): + try: + sc = json.loads(sync_path.read_text(encoding="utf-8")) + last_sync = sc.get("last_sync_at") + total_imported = sc.get("total_imported", 0) + except (OSError, json.JSONDecodeError): + pass + run_status: str | None = None run_imported = 0 run_errors = 0 @@ -626,6 +637,8 @@ async def admin_garmin_sync_status( users.append({ "handle": handle, + "last_sync": last_sync, + "total_imported": total_imported, "run_status": run_status, "run_imported": run_imported, "run_errors": run_errors, diff --git a/site/src/pages/admin/index.astro b/site/src/pages/admin/index.astro index 4d8c45d..05841e1 100644 --- a/site/src/pages/admin/index.astro +++ b/site/src/pages/admin/index.astro @@ -67,13 +67,14 @@ import Base from '../../layouts/Base.astro'; Handle - Imported (last run) + Total imported + Last sync Last run Status - Loading… + Loading… @@ -662,7 +663,7 @@ import Base from '../../layouts/Base.astro'; try { const r = await fetch('/api/admin/garmin-sync', { credentials: 'include' }); if (!r.ok) { - garminTbody.innerHTML = `Error ${r.status}`; + garminTbody.innerHTML = `Error ${r.status}`; return; } const { running, users } = await r.json(); @@ -682,19 +683,20 @@ import Base from '../../layouts/Base.astro'; } if (!users.length) { - garminTbody.innerHTML = 'No users with Garmin connected.'; + garminTbody.innerHTML = 'No users with Garmin connected.'; return; } garminTbody.innerHTML = users.map((u: any) => ` @${u.handle} - ${u.run_imported ?? '—'} + ${u.total_imported} + ${fmtDate(u.last_sync)} ${fmtDate(u.last_run)} ${garminStatusBadge(u.run_status, u.run_error_message)} `).join(''); } catch (err) { - garminTbody.innerHTML = `${String(err)}`; + garminTbody.innerHTML = `${String(err)}`; } }