65 lines
4.8 KiB
JavaScript
65 lines
4.8 KiB
JavaScript
// BRM-145: «Итог проверки за 7 дней» — одна страница, целиком собирается сервером, без скриптов.
|
|
import { t } from "./i18n.js";
|
|
import { almatyTime } from "./deploy-status.js";
|
|
|
|
const esc = (s) => String(s ?? "").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
const dayText = (lang, date) => new Date(date + "T00:00:00Z").toLocaleDateString(lang === "kk" ? "kk-KZ" : lang === "en" ? "en-GB" : "ru-RU", { day: "numeric", month: "long", weekday: "short", timeZone: "UTC" });
|
|
|
|
export function weekPage(lang = "ru", view, q = "") {
|
|
const L = (k, v) => esc(t(lang, "tw." + k, v));
|
|
const mark = (k) => ` <b class="mk ${k}" title="${L("markTip." + k)}">${L("mark." + k)}</b>`;
|
|
const link = (href, text) => `<a href="${esc(href)}" target="_blank" rel="noopener">${text}</a>`;
|
|
const reason = (d) => (d.reason === "blocked" ? d.problems.map((p) => esc(view.why(p))).join("<br>") : L("reason." + d.reason));
|
|
|
|
function card(c) {
|
|
const marks = mark("test") + (c.status !== "sent" ? mark("draft") : "") + (c.sample ? mark("sample") : "");
|
|
const appr = c.approvedAt ? L("ev.approved", { time: almatyTime(c.approvedAt) }) : L("state." + c.status);
|
|
const sent = c.status === "sent"
|
|
? `${L("ev.sent", { id: c.messageId, time: almatyTime(c.sentAt) })} ${link(c.link, L("open"))}`
|
|
: c.approvedAt ? L("state." + c.status) : "—";
|
|
return { what: `${L("ev.card", { id: c.id, title: c.title || L("noTitle"), time: almatyTime(c.createdAt) })}<br><small>${L("trigger." + c.trigger)}</small>${marks}`, appr, sent };
|
|
}
|
|
function summary(d) {
|
|
const s = d.summary;
|
|
if (d.open) return L("sum.open");
|
|
if (d.future || !s) return "—";
|
|
if (s.state === "sent") return `<span class="ok">${L("sumState.sent", { time: almatyTime(s.at) })}</span>`;
|
|
return `<span class="off">${L("sumState." + s.state)}</span>${s.reason ? `<br><small>${esc(view.why(s.reason))}</small>` : ""}`;
|
|
}
|
|
function rows(d) {
|
|
const head = `<th scope="row">${L("day", { n: d.n, total: view.totals.days })}<br><small>${esc(dayText(lang, d.date))}</small>${d.open ? `<br><small>${L("open.now")}</small>` : ""}</th>`;
|
|
if (d.future) return `<tr id="day-${d.n}" class="future">${head}<td colspan="4">${L("future")}</td></tr>`;
|
|
if (!d.cards.length) return `<tr id="day-${d.n}">${head}<td colspan="3"><span class="off">${L("noCard")}</span><br>${reason(d)}</td><td>${summary(d)}</td></tr>`;
|
|
return d.cards.map((c, i) => {
|
|
const x = card(c);
|
|
const extra = i === 0 && d.problems.length ? `<br><small>${L("alsoBlocked")} ${reason({ ...d, reason: "blocked" })}</small>` : "";
|
|
return `<tr id="day-${d.n}${i ? "-" + i : ""}">${i ? "<th></th>" : head}<td>${x.what}${extra}</td><td>${x.appr}</td><td>${x.sent}</td><td>${i ? "" : summary(d)}</td></tr>`;
|
|
}).join("");
|
|
}
|
|
const tt = view.totals;
|
|
const body = !view.start
|
|
? `<p id="notStarted" class="box">${L("notStarted")}</p>`
|
|
: `<p id="period">${L("period", { from: dayText(lang, view.start), to: dayText(lang, view.end) })} ${view.finished ? L("finished") : L("going", { n: tt.closed, total: tt.days })}</p>
|
|
<ul id="totals" class="box">
|
|
<li>${L("tot.cards", { n: tt.withCard, total: tt.days })}</li>
|
|
<li>${L("tot.approved", { n: tt.approved })}</li>
|
|
<li>${L("tot.sent", { n: tt.sent })}</li>
|
|
<li>${L("tot.summaries", { n: tt.summaries, total: tt.closed })}</li>
|
|
</ul>
|
|
${view.armedAt ? `<p id="armed">${L("ev.armed", { time: almatyTime(view.armedAt) })}</p>` : ""}
|
|
<table id="days"><thead><tr><th>${L("col.day")}</th><th>${L("col.card")}</th><th>${L("col.approval")}</th><th>${L("col.sent")}</th><th>${L("col.summary")}</th></tr></thead>
|
|
<tbody>${view.days.map(rows).join("")}</tbody></table>
|
|
<p id="legend"><small>${mark("test")} ${L("markTip.test")}<br>${mark("draft")} ${L("markTip.draft")}<br>${mark("sample")} ${L("markTip.sample")}</small></p>`;
|
|
return `<!doctype html><html lang="${lang}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${L("title")}</title>
|
|
<style>body{font:16px/1.5 system-ui,sans-serif;max-width:980px;margin:auto;padding:16px;color:#222}h1{font-size:24px}
|
|
.box{background:#f3f6ff;border-radius:8px;padding:10px 14px}.ok{color:#14532d;font-weight:600}.off{color:#8a1c1c;font-weight:600}
|
|
table{border-collapse:collapse;width:100%;font-size:15px}th,td{border-bottom:1px solid #ddd;padding:8px;text-align:left;vertical-align:top}small{color:#555}
|
|
.mk{font-size:12px;border-radius:4px;padding:0 6px;margin-left:4px;white-space:nowrap}.mk.test{background:#e6ecff}.mk.draft{background:#fff3cd}.mk.sample{background:#eee}
|
|
tr.future td{color:#777}</style></head><body>
|
|
<p><a href="/bot.html${q}">${L("back")}</a></p>
|
|
<h1>${L("title")}</h1>
|
|
<p class="box">${L("lead")}</p>
|
|
${body}
|
|
</body></html>`;
|
|
}
|