/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]>
49 lines
1.8 KiB
JavaScript
49 lines
1.8 KiB
JavaScript
// Run history: runs grouped into days (local time), as shown in the dashboard's job detail and in reports.
|
|
import { parseDate } from './format.js';
|
|
import { STATUS, normalizeStatus } from './status.js';
|
|
|
|
// Colour of a day cell: the worst thing that happened that day
|
|
export const DAY_SEVERITY = ['failed', 'warning', 'unknown', 'running', 'success'];
|
|
|
|
const pad2 = (n) => String(n).padStart(2, '0');
|
|
export const localDayKey = (d) => `${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())}`;
|
|
export const dayLabelFmt = new Intl.DateTimeFormat(undefined, { weekday: 'short', month: 'short', day: 'numeric' });
|
|
export const dayTickFmt = new Intl.DateTimeFormat(undefined, { month: 'short', day: 'numeric' });
|
|
|
|
export function normalizeRun(r) {
|
|
return {
|
|
id: String(r.id),
|
|
status: normalizeStatus(r.status),
|
|
startedAt: parseDate(r.started_at),
|
|
finishedAt: parseDate(r.finished_at),
|
|
duration: r.duration_seconds,
|
|
size: r.size_bytes,
|
|
};
|
|
}
|
|
|
|
export function buildDays(runs, count) {
|
|
const today = new Date();
|
|
today.setHours(0, 0, 0, 0);
|
|
const days = [];
|
|
for (let i = count - 1; i >= 0; i--) {
|
|
const date = new Date(today);
|
|
date.setDate(date.getDate() - i);
|
|
days.push({ key: localDayKey(date), date, counts: {}, total: 0 });
|
|
}
|
|
const byKey = new Map(days.map((d) => [d.key, d]));
|
|
for (const run of runs) {
|
|
const day = byKey.get(localDayKey(run.startedAt));
|
|
if (!day) continue;
|
|
day.counts[run.status] = (day.counts[run.status] ?? 0) + 1;
|
|
day.total++;
|
|
}
|
|
for (const day of days) day.status = day.total ? DAY_SEVERITY.find((s) => day.counts[s]) : 'none';
|
|
return days;
|
|
}
|
|
|
|
export function describeCounts(counts) {
|
|
return DAY_SEVERITY.filter((s) => counts[s])
|
|
.map((s) => `${counts[s]} ${STATUS[s].label.toLowerCase()}`)
|
|
.join(', ');
|
|
}
|