Карточка записи на «Плане»: источник, факты из памяти бренда, внутренний кейс, канал, время выхода, картинки и видео, призыв к действию, версия и история правок. Статусы идея → … → результат замерен и исходы с причиной; «опубликовано» только со ссылкой; непроверенное согласует только Татьяна; рутина по правилу стратегии; задача на ручную публикацию для канала без автопубликации. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
95 lines
8.2 KiB
JavaScript
95 lines
8.2 KiB
JavaScript
// BRM-58: карточка записи на «Плане и банке идей» — путь от идеи до замера результата.
|
||
// Собирает сервер (приёмка смотрит страницу до скриптов); кнопки — формы POST /plan/material.
|
||
import { t } from "./i18n.js";
|
||
import { almatyTime } from "./deploy-status.js";
|
||
import { publicStatus } from "./facts.js";
|
||
import { PATH, OUTCOMES, RULE, CHANNEL_IDS, actionsFor, risks, ensure, MOVES } from "./material.js";
|
||
import { APPROVERS } from "./approval.js";
|
||
|
||
const esc = (s) => String(s ?? "").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
||
const OFFSET = 5 * 3600e3; // Алматы
|
||
// Время для поля «дата и время» по Алматы и обратно.
|
||
export const toLocal = (iso) => (iso ? new Date(Date.parse(iso) + OFFSET).toISOString().slice(0, 16) : "");
|
||
export const fromLocal = (v) => (v && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$/.test(v) ? new Date(Date.parse(v + ":00Z") - OFFSET).toISOString() : "");
|
||
const MEDIA = ["image", "video", "link"];
|
||
|
||
export function materialCard(lang, { idea, getFact, facts = [], assets = [], routine = false, q = "", msg = null }) {
|
||
const L = (k, v) => esc(t(lang, "mat." + k, v));
|
||
const S = (s) => esc(t(lang, "ap.status." + s));
|
||
const C = (c) => esc(t(lang, "ui.ch.name." + c));
|
||
const head = `<h2 id="math">${L("h")}</h2><p class="hint">${L("lead")}</p>`;
|
||
if (!idea) return `${head}<div id="matcard" class="card"><p>${L("empty")}</p></div>`;
|
||
const m = ensure(idea);
|
||
const r = risks(idea, getFact);
|
||
const isRisky = r.length > 0;
|
||
const acts = actionsFor(idea, { routine, isRisky });
|
||
const action = `/plan/material${q}`;
|
||
const hid = `<input type="hidden" name="id" value="${idea.id}">`;
|
||
const note = msg ? `<p id="matmsg" class="st ${msg === "ok" ? "ok" : "off"}" role="status">${esc(t(lang, msg === "ok" ? "mat.saved" : msg))}</p>` : "";
|
||
|
||
// Путь: пройденные шаги, текущий, исход (если запись сошла с пути).
|
||
const reached = new Set(idea.history.map((h) => h.to).concat(idea.status));
|
||
const outcome = OUTCOMES.includes(idea.status);
|
||
const path = `<ol id="matpath">${PATH.map((s) => `<li class="${s === idea.status ? "cur" : reached.has(s) ? "done" : ""}">${s === idea.status ? `<b>${S(s)}</b>` : S(s)}</li>`).join("")}</ol>`;
|
||
const last = [...m.reasons].reverse()[0];
|
||
const now = `<p id="matnow">${L("now")}: <b>${S(idea.status)}</b>${outcome ? ` — ${L("outcome")}${last ? ". " + L("why", { text: last.text }) : ""}` : ""}</p>`;
|
||
|
||
const gate = isRisky
|
||
? `<p id="matgate" class="st off">${L("gate.risky")} ${r.map((x) => L("risk." + x.code, { title: x.title ?? x.key ?? "" })).join(" ")}</p>`
|
||
: routine ? `<p id="matgate" class="st ok">${L("gate.routine")}</p>`
|
||
: `<p id="matgate">${L("gate.each")}</p>`;
|
||
|
||
const task = m.manualTask
|
||
? `<p id="mattask" class="st ${m.manualTask.open ? "off" : "ok"}">${m.manualTask.open
|
||
? L("task.open", { channel: t(lang, "ui.ch.name." + m.manualTask.channel), time: almatyTime(m.manualTask.publishAt) })
|
||
: L("task.done", { channel: t(lang, "ui.ch.name." + m.manualTask.channel) })}</p>`
|
||
: m.channel && ["approved", "scheduled"].includes(idea.status) ? `<p id="mattask">${L("task.later")}</p>` : "";
|
||
const url = m.url ? `<p id="maturl">${L("url")}: <a href="${esc(m.url)}" target="_blank" rel="noopener">${esc(m.url)}</a></p>` : "";
|
||
const results = m.results.length ? `<p>${L("results")}:</p><ul id="matresults">${m.results.map((x) => `<li>${esc(almatyTime(x.at))} — ${esc(x.text)}</li>`).join("")}</ul>` : "";
|
||
|
||
// Поля карточки.
|
||
const factRows = facts.filter((f) => !f.forbidden).map((f) => {
|
||
const ok = publicStatus(f).ok;
|
||
return `<li><label><span>${esc(f.title)} — ${L(ok ? "fact.ok" : "fact.no")}</span><input type="checkbox" name="facts" value="${esc(f.key)}"${m.facts.includes(f.key) ? " checked" : ""}></label> <a href="/facts.html${q}#fact-${esc(f.key)}">${L("fact.link")}</a></li>`;
|
||
}).join("");
|
||
const media = assets.filter((a) => MEDIA.includes(a.kind));
|
||
const mediaLine = `<p id="matmedia">${L("media")}: ${media.length ? media.map((a) => `«${esc(a.title)}»`).join(", ") : L("media.none")} <a href="/assets.html${q}">${L("media.link")}</a></p>`;
|
||
const opts = (list, cur, label) => list.map(([v, txt]) => `<option value="${esc(v)}"${v === cur ? " selected" : ""}>${esc(txt)}</option>`).join("");
|
||
const fields = `<form method="post" action="${action}" id="matform">${hid}<input type="hidden" name="op" value="edit">
|
||
<label><span>${L("f.source")}</span><input name="source" value="${esc(m.source)}" placeholder="${L("f.sourcePh")}"></label>
|
||
<p>${L("f.facts")}:</p><ul id="matfacts">${factRows}</ul>
|
||
<label><span>${L("f.internal")}</span><input type="checkbox" name="internalCase" value="1"${m.internalCase ? " checked" : ""}></label>
|
||
<label><span>${L("f.channel")}</span><select name="channel">${opts([["", t(lang, "mat.f.noChannel")], ...CHANNEL_IDS.map((c) => [c, t(lang, "ui.ch.name." + c)])], m.channel ?? "")}</select></label>
|
||
<label><span>${L("f.time")}</span><input type="datetime-local" name="publishAt" value="${toLocal(m.publishAt)}"></label>
|
||
<label><span>${L("f.cta")}</span><input name="cta" value="${esc(m.cta)}" placeholder="${L("f.ctaPh")}"></label>
|
||
${mediaLine}
|
||
<p><button type="submit" title="${L("f.saveTip")}">${L("f.save")}</button></p><p><small>${L("f.versionHint")}</small></p></form>`;
|
||
|
||
// Действия на пути: только доступные сейчас.
|
||
const needReason = acts.some((a) => MOVES[a].reason);
|
||
const moveForm = acts.length
|
||
? `<form method="post" action="${action}" id="matmove">${hid}<input type="hidden" name="op" value="move">
|
||
<label><span>${L("m.by")}</span><select name="by">${opts(APPROVERS.map((a) => [a, a]), idea.approver ?? "Татьяна")}</select></label>
|
||
${acts.includes("submit") ? `<label><span>${L("m.approver")}</span><select name="approver">${opts(APPROVERS.map((a) => [a, a]), isRisky ? "Татьяна" : idea.approver ?? "Татьяна")}</select></label>` : ""}
|
||
${needReason ? `<label><span>${L("m.reason")}</span><input name="reason" placeholder="${L("m.reasonPh")}"></label>` : ""}
|
||
${acts.includes("publish") ? `<label><span>${L("m.url")}</span><input type="url" name="url" placeholder="https://"></label>` : ""}
|
||
${acts.includes("measure") ? `<label><span>${L("m.result")}</span><input name="result" placeholder="${L("m.resultPh")}"></label>` : ""}
|
||
<p>${acts.map((a) => `<button type="submit" name="action" value="${a}" title="${L("a." + a + ".tip")}">${L("a." + a)}</button>`).join(" ")}</p></form>`
|
||
: `<p id="matmove">${L("m.none")}</p>`;
|
||
|
||
// История: статусы, правки, причины.
|
||
const who = (by) => (by === RULE ? t(lang, "mat.byRule") : by === "system" ? t(lang, "ap.system") : by || "—");
|
||
const hist = idea.history.length ? `<ul id="mathist">${idea.history.map((h) => `<li>${esc(almatyTime(h.at))} — ${esc(who(h.by))}: ${S(h.from)} → ${S(h.to)}${h.reason ? " (" + esc(h.reason) + ")" : ""}</li>`).join("")}</ul>` : `<p id="mathist">${L("hist.none")}</p>`;
|
||
const edits = m.edits.length ? `<ul id="matedits">${m.edits.map((e) => `<li>${esc(almatyTime(e.at))} — ${L("edit", { version: e.version, fields: e.fields.map((f) => t(lang, "mat.field." + f)).join(", ") })}${e.by ? ", " + esc(e.by) : ""}</li>`).join("")}</ul>` : `<p id="matedits">${L("edits.none")}</p>`;
|
||
const reasons = m.reasons.length ? `<ul id="matreasons">${m.reasons.map((x) => `<li>${esc(almatyTime(x.at))} — ${L("a." + x.action)}, ${esc(x.by || "—")}: ${esc(x.text)}</li>`).join("")}</ul>` : `<p id="matreasons">${L("reasons.none")}</p>`;
|
||
const comments = (idea.comments ?? []).length ? `<ul id="matcomments">${idea.comments.map((c) => `<li>${esc(almatyTime(c.at))} — ${esc(c.by)}: ${esc(c.text)}</li>`).join("")}</ul>` : "";
|
||
|
||
return `${head}${note}<div id="matcard" class="card"><p>${L("record")}: <b id="mattitle">${esc(idea.title)}</b> · <span id="matversion">${L("version", { n: m.version })}</span></p>
|
||
${path}${now}${gate}${task}${url}${results}
|
||
<h3>${L("h.card")}</h3>${fields}
|
||
<h3>${L("h.move")}</h3>${moveForm}
|
||
<h3>${L("h.hist")}</h3>${hist}
|
||
<h3>${L("h.edits")}</h3>${edits}
|
||
<h3>${L("h.reasons")}</h3>${reasons}${comments}</div>`;
|
||
}
|