Add per-company backup reports (printable page and CSV)

/report.html shows one company's backups over the last 7, 30 or 90
days, chosen in the page and kept in the URL so reports can be
bookmarked or linked. Reached from Reports in the top bar, or a
company's name in a job's detail.

- Summary (jobs, runs, success rate, warnings, failures, overdue now);
  per job: run counts, success rate (successful / finished runs), last
  result and last successful backup; a day-by-day strip; every warning
  and failure with its message
- Print / Save as PDF: a print stylesheet prints light whatever the
  screen theme, hides the controls, keeps rows and strips whole across
  pages, and keeps the coloured cells and badges
- Days before a job was first known show as "Not monitored yet"
  rather than as missed backups, so a 90-day report for a newly added
  client doesn't look like 60 days of failures
- CSV of every run (full messages, times in the browser's time zone,
  UTF-8 BOM for Excel, formula-like values defused with a leading ')

Backend: GET /api/v1/tenants, /api/v1/reports/tenant and
/api/v1/reports/tenant.csv; periods capped at retention. tzdata added
for systems without time zone data. Frontend status and day-strip
helpers moved out of app.js into status.js / history.js for reuse.

Tested: 9 new backend tests; in the browser against the API with 30
days of demo history (summary, issues, strips, 7/30/90 switching,
CSV download with BOM, print styles applied on screen), mock mode and
phone width.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-08 14:56:54 -06:00
co-authored by Claude Opus 5.5
parent abb684ff0d
commit 2297187f88
15 changed files with 925 additions and 75 deletions
+40
View File
@@ -143,6 +143,46 @@ export const mockApi = {
return { email: null, name: null, is_admin: true };
},
async listTenants() {
await delay(150);
const counts = new Map();
for (const j of JOBS) counts.set(j.company_name, (counts.get(j.company_name) ?? 0) + 1);
return { tenants: [...counts].map(([name, jobs]) => ({ name, jobs })).sort((a, b) => a.name.localeCompare(b.name)) };
},
async tenantReport(tenant, days) {
await delay(250);
const jobs = JOBS.filter((j) => j.company_name.toLowerCase() === tenant.toLowerCase());
if (!jobs.length) throw new Error(`No company named '${tenant}'`);
const since = now - days * DAY;
return {
tenant: jobs[0].company_name, days,
since: new Date(since).toISOString(), until: new Date(now).toISOString(), generated_at: new Date(now).toISOString(),
jobs: jobs.map(({ details, every_h, ...job }) => ({
...job,
// Earliest run on record, as the API reports it
tracked_since: (RUNS.get(String(job.id)) ?? []).map((r) => r.started_at).sort()[0] ?? new Date(now).toISOString(),
runs: (RUNS.get(String(job.id)) ?? [])
.filter((r) => Date.parse(r.started_at) >= since)
.map(({ id, details: _d, message, ...r }) => ({ ...r, message: ['warning', 'failed'].includes(r.status) ? message : null }))
.reverse(), // oldest first, like the API
})),
};
},
// No server in mock mode: build the CSV here and link to it as a blob
async tenantReportCsvUrl(tenant, days, tz) {
const report = await this.tenantReport(tenant, days);
const quoteCell = (v) => `"${String(v ?? '').replaceAll('"', '""')}"`;
// Times stay in UTC here (the real API converts them to `tz`)
const rows = [['Company', 'Job', 'Source', 'Started (UTC)', 'Finished (UTC)', 'Status', 'Message']];
for (const job of report.jobs) {
for (const run of job.runs) {
rows.push([report.tenant, job.job_name, job.source_system, run.started_at, run.finished_at ?? '', run.status, run.message ?? '']);
}
}
const csv = rows.map((r) => r.map(quoteCell).join(',')).join('\r\n');
return URL.createObjectURL(new Blob(['\ufeff' + csv], { type: 'text/csv' }));
},
async listKeys() {
await delay(200);
return { keys: [...KEYS].sort((a, b) => (!!a.revoked_at - !!b.revoked_at) || a.name.localeCompare(b.name)) };