54 lines
3.2 KiB
JavaScript
54 lines
3.2 KiB
JavaScript
// BRM-196: «План по неделям» на «Плане и банке идей» — собирает сервер, видно до скриптов.
|
||
// Неделя = 7 дней от даты старта (последняя — остаток до 60 дней); задача недели — строки программы стратегии
|
||
// («Дни A–B: …»), чьи дни пересекают неделю.
|
||
import { t } from "./i18n.js";
|
||
import { addDays, DAYS, inWindow } from "./plan.js";
|
||
|
||
const esc = (s) => String(s ?? "").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
||
const dm = (date) => date.slice(8, 10) + "." + date.slice(5, 7);
|
||
|
||
// Строки программы: [{from, to, text}] — дни с 1.
|
||
export function programme(plan90) {
|
||
return String(plan90 ?? "").split("\n").map((l) => l.match(/^\s*Дни\s+(\d+)\s*[–-]\s*(\d+)\s*:\s*(.+)$/)).filter(Boolean)
|
||
.map(([, a, b, text]) => ({ from: Number(a), to: Number(b), text: text.trim() }));
|
||
}
|
||
|
||
export function weeks(plan, plan90) {
|
||
const prog = programme(plan90);
|
||
const out = [];
|
||
for (let k = 0; k * 7 < DAYS; k++) {
|
||
const d0 = k * 7, d1 = Math.min(d0 + 6, DAYS - 1);
|
||
const from = addDays(plan.start, d0), to = addDays(plan.start, d1);
|
||
const ideas = plan.ideas.filter((i) => i.date && i.date >= from && i.date <= to && inWindow(plan.start, i.date)).sort((a, b) => a.date.localeCompare(b.date) || a.id - b.id);
|
||
const task = prog.filter((p) => p.from <= d1 + 1 && p.to >= d0 + 1).map((p) => p.text);
|
||
out.push({ n: k + 1, from, to, task, ideas });
|
||
}
|
||
return out;
|
||
}
|
||
|
||
export function weeksBox(lang, plan, plan90, q = "") {
|
||
const T = (k, v) => esc(t(lang, "ui.plan.wk." + k, v));
|
||
const rn = (id) => plan.settings.rubrics.find((r) => r.id === id)?.name ?? "";
|
||
const ws = weeks(plan, plan90);
|
||
const all = ws.flatMap((w) => w.ideas);
|
||
const count = (s) => all.filter((i) => i.status === s).length;
|
||
const out = [`<section id="weeks"><h2>${T("h")}</h2>`];
|
||
if (!all.length) { out.push(`<p id="wktotal" class="none">${T("empty")}</p></section>`); return out.join(""); }
|
||
out.push(`<p id="wktotal">${T("total", { n: all.length, draft: count("draft"), review: count("review"), approved: count("approved") + count("scheduled") + count("published") + count("measured") })}</p>`);
|
||
out.push(`<p class="hint">${T("only")}</p>`);
|
||
const sep = q ? "&" : "?";
|
||
for (const w of ws) {
|
||
out.push(`<h3 id="wk-${w.n}">${T("week", { n: w.n, from: dm(w.from), to: dm(w.to) })}</h3>`);
|
||
if (w.task.length) out.push(`<p class="hint">${T("task")}: ${esc(w.task.join(" "))}</p>`);
|
||
if (!w.ideas.length) { out.push(`<p class="none">${T("none")}</p>`); continue; }
|
||
out.push(`<ul class="wk">`);
|
||
for (const i of w.ideas) {
|
||
const ch = i.material?.channel;
|
||
out.push(`<li><b>${dm(i.date)}</b> — <a href="/plan.html${q}${sep}id=${i.id}#apcardh">${esc(i.title)}</a> · ${esc(rn(i.rubric))} · ${T("channel")}: ${ch ? esc(t(lang, "ap.channel." + ch)) : T("noChannel")} · <span class="st st-${esc(i.status)}">${esc(t(lang, "ap.status." + i.status))}</span>${i.description ? `<br><span class="hint">${esc(i.description)}</span>` : ""}</li>`);
|
||
}
|
||
out.push(`</ul>`);
|
||
}
|
||
out.push(`</section>`);
|
||
return out.join("");
|
||
}
|