brendmanager/src/strategy-view.js
peppa-bot 019a64bd35
All checks were successful
peppa/lint lint: success за 1с
peppa/test test: success за 13с
ci / checks (pull_request) Successful in 36s
deploy / deploy (pull_request) Successful in 46s
BRM-169: стратегия на 90 дней наверху страницы — версия, все разделы, бюджет-рекомендация, дни 1–60 подробно
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 16:44:06 +00:00

51 lines
3.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// BRM-169: стратегия на 90 дней на странице «Стратегия и правила» — версия, все разделы, бюджет-рекомендация
// и программа (дни 1–60 подробно, 61–90 крупными шагами). Собирает сервер: видно до скриптов.
import { t } from "./i18n.js";
import { almatyTime } from "./deploy-status.js";
import { SECTIONS } from "./strategy.js";
// Сначала то, что нужно для решения, затем остальное.
export const ORDER = ["main", "alternatives", "sources", "kpi", "budget", "plan90", "positioning", "audience", "channels", "tone"];
export const DETAIL_DAYS = 60;
const esc = (s) => String(s ?? "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
const linesOf = (s) => String(s ?? "").split("\n").map((l) => l.trim()).filter(Boolean);
const ul = (lines) => `<ul>${lines.map((l) => `<li>${esc(l)}</li>`).join("")}</ul>`;
// Первый день строки «Дни 8–14: …» (null — строка без дней).
export const startDay = (line) => { const m = String(line).match(/^(?:Дни|Күндер|Days)\s+(\d+)/i); return m ? Number(m[1]) : null; };
// Пометка «утверждён / не утверждён» ставит сервер по решению Татьяны, а не текст раздела.
const RECO = /^\s*Рекомендация,?\s*не утвержден[аоы]?\s*:\s*/i;
export function strategyView(lang, version, stage = null) {
const T = (k, v) => esc(t(lang, "strat." + k, v));
const out = [`<section id="strat">`];
if (!version) {
out.push(`<h2>${T("h")}</h2><p id="stratver">${T("none")}</p><p id="stratnext">${T("noneNext")}</p></section>`);
return out.join("");
}
const approved = version.status === "approved";
const st = stage ?? (approved ? "approved" : version.status === "revision" ? "revision" : "draft");
out.push(`<h2>${T("h")} <span id="stratver" class="ver">${T("version", { n: version.n })}</span></h2>`);
out.push(`<p id="stratstage" class="st-${esc(st)}">${T("version", { n: version.n })}: <b>${esc(t(lang, "sv.stage." + st))}</b>${approved ? " " + esc(almatyTime(version.approvedAt)) + " " + esc(t(lang, "sv.almaty")) : ""}</p>`);
out.push(`<p id="stratnext" class="hint">${T("next." + (approved ? "approved" : version.status === "revision" ? "revision" : "draft"))}</p>`);
for (const s of ORDER.filter((x) => SECTIONS.includes(x))) {
let lines = linesOf(version.sections[s]);
const head = s === "plan90" ? T("plan.h") : esc(t(lang, "ui.str.sec." + s));
let body;
if (s === "budget") {
const mark = approved ? `<p id="stratbudget" class="ok">${T("budget.approved", { date: almatyTime(version.approvedAt).slice(0, 10) })}</p>` : `<p id="stratbudget" class="reco">${T("budget.reco")}</p>`;
lines = lines.map((l, i) => (i === 0 ? l.replace(RECO, "") : l)).filter(Boolean);
if (lines[0]) lines[0] = lines[0][0].toUpperCase() + lines[0].slice(1);
body = mark + (lines.length ? ul(lines) : `<p class="none">${esc(t(lang, "sv.empty"))}</p>`);
} else if (!lines.length) body = `<p class="none">${esc(t(lang, "sv.empty"))}</p>`;
else if (s === "plan90") {
const late = lines.filter((l) => (startDay(l) ?? 0) > DETAIL_DAYS);
const early = lines.filter((l) => !late.includes(l));
body = `<h4>${T("plan.early")}</h4>${ul(early)}` + (late.length ? `<h4>${T("plan.late")}</h4>${ul(late)}` : "");
} else body = lines.length > 1 ? ul(lines) : `<p>${esc(lines[0])}</p>`;
out.push(`<div id="strat-${s}"><h3>${head}</h3>${body}</div>`);
}
out.push(`</section>`);
return out.join("");
}