Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
Admin-Dashboard: jede Karte sagt in einem Satz, wofuer sie da ist
Duarte Santos9d7abdab4428
diff --git a/frontend/src/admin.css b/frontend/src/admin.cssnew file mode 100644index 000000000..a4b96bd0b--- /dev/null+++ b/frontend/src/admin.css@@ -0,0 +1,32 @@+/* Admin dashboard — operator-facing, English-only. Sits on top of the app's tokens; nothing+ here is used outside views/Admin.jsx. The page is looked at maybe twice a year, so every+ card says what it is for in a sentence and every state is a word, not a colour to decode. */++.adm-intro{color:var(--label-2);font-size:14px;line-height:1.45;margin:-6px 0 16px}++/* one sentence under a card heading that says what the card is for */+.adm-lead{color:var(--label-2);font-size:13px;line-height:1.45;margin:2px 0 12px}++/* status pill: a word and a colour, never a paragraph */+.adm-pill{+ display:inline-flex;align-items:center;gap:6px;padding:3px 10px;border-radius:999px;+ font-size:12.5px;font-weight:600;letter-spacing:-.004em;line-height:1.5;white-space:nowrap;+ background:var(--surface-2);color:var(--label-2)+}+.adm-pill::before{content:'';width:7px;height:7px;border-radius:50%;background:currentColor;flex:none}+.adm-pill.bad{background:color-mix(in srgb,var(--red) 16%,transparent);color:var(--red)}+.adm-pill.acc{background:var(--acc-soft);color:var(--acc)}++/* a dim explainer that reads like a sentence, not a footnote */+.adm-hint{font-size:13px;color:var(--label-2);line-height:1.45;margin:6px 0 10px}++/* a small heading over a group of rows ("Unused · tap to copy") */+.adm-group-t{font-size:11.5px;font-weight:600;letter-spacing:.04em;text-transform:uppercase;color:var(--label-3);margin:0 0 7px}++/* an invite code, sized to be tapped and read out loud */+.adm-code{+ font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-weight:600;letter-spacing:.08em;+ background:var(--surface-2);padding:4px 9px;border-radius:8px;font-size:14px+}+.adm-iconbtn{width:44px;height:44px;border-radius:12px;font-size:17px}+.adm-empty{color:var(--label-3);font-size:13.5px;padding:10px 2px}diff --git a/frontend/src/views/Admin.jsx b/frontend/src/views/Admin.jsxindex b7447fcad..ae00dcf5b 100644--- a/frontend/src/views/Admin.jsx+++ b/frontend/src/views/Admin.jsx@@ -9,20 +9,25 @@ import { workoutVolume, setsDone } from '../lib/history.js'import { confirmSheet } from '../sheets.jsx'import Icon from '../components/Icon.jsx'import { Button } from '../components/ui.jsx'+import '../admin.css'// Admin-only operator dashboard (owner passkey + admin flag; guarded again server-side).// Deliberately English-only — it isn't part of the translated end-user surface, so it stays// out of the per-language string packs.+//+// One page of cards, each opening with a sentence that says what it is for. An operator who+// looks at this twice a year should not have to remember what "synced 3d ago" or an invite+// code means.const rel = ts => {if (!ts) return 'never'const s = Math.max(0, (Date.now() - ts) / 1000)if (s < 60) return 'just now'- if (s < 3600) return Math.floor(s / 60) + 'm ago'- if (s < 86400) return Math.floor(s / 3600) + 'h ago'- return Math.floor(s / 86400) + 'd ago'+ if (s < 3600) return Math.floor(s / 60) + ' min ago'+ if (s < 86400) return Math.floor(s / 3600) + ' h ago'+ return Math.floor(s / 86400) + ' d ago'}-const dur = ms => { const m = Math.max(0, Math.floor(ms / 60000)); return m < 60 ? m + 'm' : Math.floor(m / 60) + 'h' + (m % 60) + 'm' }+const dur = ms => { const m = Math.max(0, Math.floor(ms / 60000)); return m < 60 ? m + ' min' : Math.floor(m / 60) + ' h ' + (m % 60) + ' min' }function UserDetail({ id, onChanged, close }) {const [d, setD] = useState(null)@@ -38,10 +43,10 @@ function UserDetail({ id, onChanged, close }) {return <><h3 className="capitalize">{u.name}</h3><div className="row" style={{ gap: 6, flexWrap: 'wrap', margin: '8px 0 12px' }}>- {u.admin && <span className="tag acc">admin</span>}- {u.disabled && <span className="tag" style={{ color: 'var(--red)' }}>disabled</span>}- {u.invitedBy && <span className="tag">invite {u.invitedBy}</span>}- <span className="tag">joined {u.created ? fmtDate(u.created.slice(0, 10)) : '—'}</span>+ {u.admin && <span className="adm-pill acc">admin</span>}+ {u.disabled && <span className="adm-pill bad">disabled</span>}+ {u.invitedBy && <span className="adm-pill">invite {u.invitedBy}</span>}+ <span className="adm-pill">joined {u.created ? fmtDate(u.created.slice(0, 10)) : '—'}</span></div><div className="tiles" style={{ textAlign: 'left' }}><div className="tile"><div className="l">Workouts</div><div className="v" style={{ fontSize: '1.1rem' }}>{d.workouts.length}</div></div>@@ -49,10 +54,13 @@ function UserDetail({ id, onChanged, close }) {<div className="tile"><div className="l">Routines</div><div className="v" style={{ fontSize: '1.1rem' }}>{d.routines.length}</div></div><div className="tile"><div className="l">Last sync</div><div className="v" style={{ fontSize: '.95rem' }}>{rel(d.lastSync)}</div></div></div>- {!u.admin && <button className={'btn ' + (u.disabled ? 'primary' : 'danger')} style={{ margin: '12px 0 4px' }}- onClick={() => u.disabled ? setDisabled(false)- : confirmSheet({ title: 'Disable ' + u.name + '?', message: 'They are signed out everywhere and can no longer sync or log in until re-enabled.', confirmText: 'Disable', danger: true, onConfirm: () => setDisabled(true) })}>- {u.disabled ? 'Enable account' : 'Disable account'}</button>}+ {!u.admin && <>+ <button className={'btn ' + (u.disabled ? 'primary' : 'danger')} style={{ margin: '12px 0 4px' }}+ onClick={() => u.disabled ? setDisabled(false)+ : confirmSheet({ title: 'Disable ' + u.name + '?', message: 'They are signed out everywhere and can no longer sync or log in until re-enabled. Their data stays.', confirmText: 'Disable', danger: true, onConfirm: () => setDisabled(true) })}>+ {u.disabled ? 'Enable account' : 'Disable account'}</button>+ <div className="adm-hint">{u.disabled ? 'Enabling lets them sign in and sync again.' : 'Disabling signs them out everywhere and blocks sign-in. Nothing is deleted.'}</div>+ </>}<h4 className="sec">Workout history</h4>{d.workouts.length ? <div className="list" style={{ gap: 0 }}>{d.workouts.slice(0, 60).map(w => <div key={w.id} className="row between" style={{ padding: '9px 2px', borderBottom: '1px solid var(--sep)' }}>@@ -60,32 +68,49 @@ function UserDetail({ id, onChanged, close }) {<div className="dim" style={{ fontSize: '.72rem' }}>{fmtDate(w.d, true)} · {fmtDur((w.end || w.start) - w.start)} · {setsDone(w)} sets{w.prs?.length ? ' · ' + w.prs.length + ' PR' : ''}</div></div><span className="small muted">{fmtVol(w.vol ?? workoutVolume(w), d.unit)}</span></div>)}- </div> : <div className="empty small">No workouts logged.</div>}+ </div> : <div className="adm-empty">No workouts logged.</div>}</>}-function InvitesCard({ invites, reload }) {+function InvitesCard({ invites, reload, inviteOnly }) {const toast = useUI(s => s.toast)const gen = () => api('/api/admin/invites/new', { method: 'POST', body: '{}' }).then(({ invite }) => { navigator.clipboard?.writeText(invite.code).catch(() => {}); toast('Code ' + invite.code + ' created & copied'); reload() }).catch(e => toast(e.message))- const revoke = code => api('/api/admin/invites/revoke', { method: 'POST', body: JSON.stringify({ code }) })- .then(() => { toast('Code revoked'); reload() }).catch(e => toast(e.message))+ const revoke = code => confirmSheet({+ title: 'Revoke code ' + code + '?', message: 'Anyone who has it can no longer use it. People who already signed up with it are not affected.',+ confirmText: 'Revoke', danger: true,+ onConfirm: () => api('/api/admin/invites/revoke', { method: 'POST', body: JSON.stringify({ code }) })+ .then(() => { toast('Code revoked'); reload() }).catch(e => toast(e.message))+ })+ const copy = code => { navigator.clipboard?.writeText(code).catch(() => {}); toast('Copied ' + code) }const open = (invites || []).filter(i => !i.usedBy)const used = (invites || []).filter(i => i.usedBy)return <div className="card"><div className="row between"><h2 style={{ margin: 0 }}>Invite codes</h2>- <Button variant="primary" size="sm" onClick={gen} icon="plus">Generate</Button></div>- <div className="small muted" style={{ margin: '6px 0 10px' }}>{open.length} unused · {used.length} redeemed</div>- {open.map(i => <div key={i.code} className="row between" style={{ padding: '7px 2px', borderBottom: '1px solid var(--sep)' }}>- <span style={{ fontFamily: 'ui-monospace,SFMono-Regular,Menlo,monospace', fontWeight: 500, letterSpacing: '.06em' }}- onClick={() => { navigator.clipboard?.writeText(i.code).catch(() => {}); toast('Copied ' + i.code) }}>{i.code}</span>- <button className="iconbtn" style={{ width: 32, height: 30, borderRadius: 8, fontSize: 15, color: 'var(--red)' }} onClick={() => revoke(i.code)} aria-label="revoke"><Icon name="trash" /></button>- </div>)}- {used.map(i => <div key={i.code} className="row between dim" style={{ padding: '7px 2px', fontSize: '.8rem' }}>- <span style={{ fontFamily: 'monospace' }}>{i.code}</span><span>→ {i.usedByName || 'used'}</span>- </div>)}- {!open.length && !used.length && <div className="dim small">No codes yet — generate one to invite someone.</div>}+ <Button variant="primary" size="sm" onClick={gen} icon="plus">New code</Button></div>+ <div className="adm-lead">+ {inviteOnly+ ? 'Sign-up is invite-only: someone needs one of these codes to create a profile. Each code works once.'+ : 'Sign-up is open, so codes are optional here — they only record who invited whom.'}+ </div>+ {open.length ? <>+ <div className="adm-group-t">Unused · tap to copy</div>+ {open.map(i => <div key={i.code} className="row between" style={{ padding: '6px 0', borderBottom: 'var(--hair) solid var(--sep)' }}>+ <button className="adm-code" onClick={() => copy(i.code)} aria-label={'copy ' + i.code}>{i.code}</button>+ <div className="row" style={{ gap: 4 }}>+ <button className="iconbtn adm-iconbtn" onClick={() => copy(i.code)} aria-label="copy"><Icon name="clipboard" /></button>+ <button className="iconbtn adm-iconbtn" style={{ color: 'var(--red)' }} onClick={() => revoke(i.code)} aria-label="revoke"><Icon name="trash" /></button>+ </div>+ </div>)}+ </> : null}+ {used.length ? <>+ <div className="adm-group-t" style={{ marginTop: open.length ? 12 : 0 }}>Already used</div>+ {used.map(i => <div key={i.code} className="row between dim" style={{ padding: '6px 0', fontSize: '.82rem' }}>+ <span style={{ fontFamily: 'ui-monospace,SFMono-Regular,Menlo,monospace', letterSpacing: '.06em' }}>{i.code}</span><span>→ {i.usedByName || 'used'}</span>+ </div>)}+ </> : null}+ {!open.length && !used.length && <div className="adm-empty">No codes yet. "New code" makes one and copies it to your clipboard.</div>}</div>}@@ -118,30 +143,31 @@ function AuditCard({ tick }) {return <div className="card"><div className="row between"><h2 style={{ margin: 0 }}>Activity log</h2>- <button className="iconbtn" style={{ width: 32, height: 30, borderRadius: 8, fontSize: 15, color: 'var(--red)' }}- onClick={clear} aria-label="clear log"><Icon name="trash" /></button></div>- <div className="small muted" style={{ margin: '6px 0 10px' }}>- {meta ? fmtNum(meta.total) + ' events'- + (meta.retention.days ? ' · last ' + meta.retention.days + ' days' : '')- + (meta.ip_mode === 'off' ? ' · no IP addresses' : '') : 'Loading…'}</div>+ <button className="iconbtn adm-iconbtn" style={{ color: 'var(--red)' }} onClick={clear} aria-label="clear log"><Icon name="trash" /></button></div>+ <div className="adm-lead">+ Who signed in, what failed, and what an admin changed.+ {meta ? ' ' + fmtNum(meta.total) + ' events'+ + (meta.retention.days ? ', kept for ' + meta.retention.days + ' days' : '')+ + (meta.ip_mode === 'off' ? ', without IP addresses' : '') + '.' : ''}+ </div><div className="chips" style={{ marginBottom: 10 }}>{[['', 'All'], ['auth', 'Sign-ins'], ['admin', 'Admin'], ['fail', 'Failed']].map(([v, l]) =><button key={v} className={'chip' + (cat === v ? ' on' : '')} onClick={() => pick(v)}>{l}</button>)}</div>{rows.map(e => {const line = auditLine(e)- return <div key={e.id} className="row between" style={{ padding: '8px 2px', borderBottom: '1px solid var(--sep)' }}>+ return <div key={e.id} className="row between" style={{ padding: '8px 2px', borderBottom: 'var(--hair) solid var(--sep)' }}><div className="grow"><div className="small" style={{ fontWeight: 600 }}>{line.title}{/* a red pill, not a red row: twenty fumbled Face IDs in a row shouldn't read as an incident */}- {!e.ok && <span className="tag" style={{ marginLeft: 6, color: 'var(--red)' }}>failed</span>}- {auditCat(e.ev) === 'admin' && <span className="tag acc" style={{ marginLeft: 6 }}>admin</span>}</div>+ {!e.ok && <span className="adm-pill bad" style={{ marginLeft: 6 }}>failed</span>}+ {auditCat(e.ev) === 'admin' && <span className="adm-pill acc" style={{ marginLeft: 6 }}>admin</span>}</div>{line.sub && <div className="dim" style={{ fontSize: '.72rem' }}>{line.sub}</div>}</div><span className="small muted" style={{ flex: 'none', marginLeft: 8 }}>{fmtWhen(e.ts, meta?.now)}</span></div>})}- {meta && !rows.length && <div className="dim small">Nothing logged yet.</div>}+ {meta && !rows.length && <div className="adm-empty">Nothing logged yet.</div>}{meta?.nextBefore && <div style={{ marginTop: 10 }}><Button size="sm" onClick={() => load(cat, meta.nextBefore)}>Show more</Button></div>}</div>@@ -175,33 +201,40 @@ export default function Admin() {<div className="sub">{users ? users.length + ' users · ' + activeCount + ' active this week' : 'Loading…'}</div></div><button className="iconbtn" onClick={() => { loadUsers(); loadInvites(); setTick(n => n + 1) }} aria-label="refresh">↻</button></div>+ <div className="adm-intro">+ Everything about running this instance: who uses it, how they get in, and what has happened on it. Nothing here shows anyone's training data beyond counts.+ </div><div className="tiles" style={{ marginBottom: 12 }}><div className="tile"><div className="l">Users</div><div className="v">{users ? users.length : '—'}</div></div><div className="tile"><div className="l">Training now</div><div className="v" style={{ color: liveUsers.length ? 'var(--acc)' : undefined }}>{users ? liveUsers.length : '—'}</div></div>- <div className="tile"><div className="l">Active 7d</div><div className="v">{users ? activeCount : '—'}</div></div>+ <div className="tile"><div className="l">Active 7 days</div><div className="v">{users ? activeCount : '—'}</div></div><div className="tile"><div className="l">Disabled</div><div className="v">{users ? disabledCount : '—'}</div></div></div>{liveUsers.length > 0 && <div className="card" style={{ borderColor: 'var(--acc)' }}>- <h2 className="row" style={{ margin: '0 0 8px', gap: 6 }}><Icon name="dot" style={{ fontSize: 10, color: 'var(--green)' }} />Training now</h2>- {liveUsers.map(u => <div key={u.id} className="row between" style={{ padding: '8px 2px', borderBottom: '1px solid var(--sep)' }} onClick={() => openUser(u.id)}>+ <h2 className="row" style={{ margin: '0 0 2px', gap: 6 }}><Icon name="dot" style={{ fontSize: 10, color: 'var(--green)' }} />Training now</h2>+ <div className="adm-lead">Sessions running at this moment. Tap a name for details.</div>+ {liveUsers.map(u => <div key={u.id} className="row between" style={{ padding: '8px 2px', borderBottom: 'var(--hair) solid var(--sep)' }} onClick={() => openUser(u.id)}><div><div className="small" style={{ fontWeight: 600 }}>{u.name}</div>- <div className="dim" style={{ fontSize: '.72rem' }}>{u.live.name} · ex {u.live.exIdx}/{u.live.exTotal} · {u.live.setsDone}/{u.live.setsTotal} sets</div></div>- <span className="tag acc">{dur(Date.now() - u.live.startedAt)}</span>+ <div className="dim" style={{ fontSize: '.72rem' }}>{u.live.name} · exercise {u.live.exIdx} of {u.live.exTotal} · {u.live.setsDone}/{u.live.setsTotal} sets</div></div>+ <span className="adm-pill acc">{dur(Date.now() - u.live.startedAt)}</span></div>)}</div>}- <InvitesCard invites={invites} reload={loadInvites} />-- <h4 className="sec">Users</h4>- <div className="list">- {(users || []).map(u => <div key={u.id} className="item" onClick={() => openUser(u.id)} style={u.disabled ? { opacity: .55 } : null}>- <div className="grow"><div className="tt">{u.live && <Icon name="dot" style={{ fontSize: 9, color: 'var(--green)', display: 'inline-block', marginRight: 5 }} />}{u.name} {u.admin && <span className="tag acc" style={{ marginLeft: 4 }}>admin</span>}{u.disabled && <span className="tag" style={{ marginLeft: 4, color: 'var(--red)' }}>off</span>}</div>- <div className="ss">{u.live ? 'training now · ' + u.live.name : u.workouts + ' workouts' + (u.lastWorkout ? ' · last ' + fmtDate(u.lastWorkout) : '') + ' · synced ' + rel(u.lastSync)}</div></div>- {u.hasPush && <Icon name="bell" title="push enabled" style={{ fontSize: 15, color: 'var(--label-3)' }} />}<Icon name="chevronRight" className="chev" />- </div>)}- {users && !users.length && <div className="empty">No users yet.</div>}+ <InvitesCard invites={invites} reload={loadInvites} inviteOnly={inviteOnly} />++ <div className="card">+ <h2 style={{ margin: 0 }}>Users</h2>+ <div className="adm-lead">Everyone with a profile on this instance. Tap one to see their activity or to disable the account — their data is never deleted from here.</div>+ <div className="list">+ {(users || []).map(u => <div key={u.id} className="item" onClick={() => openUser(u.id)} style={u.disabled ? { opacity: .55 } : null}>+ <div className="grow"><div className="tt">{u.live && <Icon name="dot" style={{ fontSize: 9, color: 'var(--green)', display: 'inline-block', marginRight: 5 }} />}{u.name} {u.admin && <span className="adm-pill acc" style={{ marginLeft: 4 }}>admin</span>}{u.disabled && <span className="adm-pill bad" style={{ marginLeft: 4 }}>disabled</span>}</div>+ <div className="ss">{u.live ? 'training now · ' + u.live.name : u.workouts + ' workouts' + (u.lastWorkout ? ' · last ' + fmtDate(u.lastWorkout) : '') + ' · last sync ' + rel(u.lastSync)}</div></div>+ {u.hasPush && <Icon name="bell" title="push notifications on" style={{ fontSize: 15, color: 'var(--label-3)' }} />}<Icon name="chevronRight" className="chev" />+ </div>)}+ {users && !users.length && <div className="adm-empty">No users yet.</div>}+ </div></div><div style={{ marginTop: 14 }}><AuditCard tick={tick} /></div>