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.
This commit is contained in:
Davide Scaini
2026-05-21 20:32:54 +02:00
parent 418e3a13e8
commit d4e5b11f71
3 changed files with 22 additions and 6 deletions
+8 -6
View File
@@ -67,13 +67,14 @@ import Base from '../../layouts/Base.astro';
<thead>
<tr class="text-left text-zinc-500 text-xs border-b border-zinc-800">
<th class="px-4 py-2 font-medium">Handle</th>
<th class="px-4 py-2 font-medium text-right">Imported (last run)</th>
<th class="px-4 py-2 font-medium text-right">Total imported</th>
<th class="px-4 py-2 font-medium">Last sync</th>
<th class="px-4 py-2 font-medium">Last run</th>
<th class="px-4 py-2 font-medium">Status</th>
</tr>
</thead>
<tbody id="garmin-sync-list">
<tr><td colspan="4" class="px-4 py-6 text-zinc-500 text-center">Loading…</td></tr>
<tr><td colspan="5" class="px-4 py-6 text-zinc-500 text-center">Loading…</td></tr>
</tbody>
</table>
</div>
@@ -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 = `<tr><td colspan="4" class="px-4 py-4 text-red-400 text-center">Error ${r.status}</td></tr>`;
garminTbody.innerHTML = `<tr><td colspan="5" class="px-4 py-4 text-red-400 text-center">Error ${r.status}</td></tr>`;
return;
}
const { running, users } = await r.json();
@@ -682,19 +683,20 @@ import Base from '../../layouts/Base.astro';
}
if (!users.length) {
garminTbody.innerHTML = '<tr><td colspan="4" class="px-4 py-6 text-zinc-500 text-center">No users with Garmin connected.</td></tr>';
garminTbody.innerHTML = '<tr><td colspan="5" class="px-4 py-6 text-zinc-500 text-center">No users with Garmin connected.</td></tr>';
return;
}
garminTbody.innerHTML = users.map((u: any) => `
<tr class="border-b border-zinc-800/50">
<td class="px-4 py-3 text-white font-mono text-xs">@${u.handle}</td>
<td class="px-4 py-3 text-right text-zinc-300 tabular-nums">${u.run_imported ?? '—'}</td>
<td class="px-4 py-3 text-right text-zinc-300 tabular-nums">${u.total_imported}</td>
<td class="px-4 py-3 text-zinc-400 text-xs">${fmtDate(u.last_sync)}</td>
<td class="px-4 py-3 text-zinc-400 text-xs">${fmtDate(u.last_run)}</td>
<td class="px-4 py-3">${garminStatusBadge(u.run_status, u.run_error_message)}</td>
</tr>`).join('');
} catch (err) {
garminTbody.innerHTML = `<tr><td colspan="4" class="px-4 py-4 text-red-400 text-center">${String(err)}</td></tr>`;
garminTbody.innerHTML = `<tr><td colspan="5" class="px-4 py-4 text-red-400 text-center">${String(err)}</td></tr>`;
}
}