brendmanager/public/summary.html

32 lines
3.3 KiB
HTML
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.

<!doctype html>
<html lang="ru"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>Сводка владельцу</title>
<style>
body{font:15px system-ui,sans-serif;padding:16px;max-width:760px;margin:auto;color:#222}
h1{font-size:20px}h2{font-size:16px;margin-top:24px}table{border-collapse:collapse;width:100%}td,th{border:1px solid #ddd;padding:4px 8px;text-align:left}
.row{display:flex;gap:6px;flex-wrap:wrap;margin:8px 0}textarea{width:100%;box-sizing:border-box}pre{background:#f5f5f5;padding:12px;white-space:pre-wrap}#err{color:#b00}#ok{color:#070}
</style></head><body>
<h1>Сводка владельцу</h1>
<h2>Показатели (до 5)</h2>
<table id="list"></table>
<div class="row"><input id="name" placeholder="Название (напр. Подписчики Telegram)"><input id="value" placeholder="Значение" size="8"><input type="date" id="mdate"><button id="add">Сохранить</button></div>
<h2>Сводка</h2>
<div class="row">Период: <select id="period"><option value="day">День</option><option value="week">Неделя</option></select> На дату: <input type="date" id="date"></div>
<label>Сделано<textarea id="done"></textarea></label><label>Возможность<textarea id="opportunity"></textarea></label>
<label>Риск<textarea id="risk"></textarea></label><label>Нужно решение<textarea id="decision"></textarea></label>
<label>Следующий шаг<textarea id="next"></textarea></label>
<div class="row"><button id="preview">Сформировать</button><button id="send">Отправить в Telegram</button></div>
<div id="err"></div><div id="ok"></div><pre id="text"></pre>
<script>
const $=id=>document.getElementById(id);const today=new Date().toISOString().slice(0,10);$("mdate").value=$("date").value=today;
const esc=s=>String(s).replace(/[&<>"']/g,c=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"}[c]));
async function api(m,u,b){const r=await fetch(u,{method:m,headers:{"content-type":"application/json"},body:b&&JSON.stringify(b)});return[r.ok,await r.json()]}
async function load(){const[,d]=await api("GET","/api/metrics");$("list").innerHTML="<tr><th>Показатель</th><th>Последнее значение</th><th>Дата</th></tr>"+
(d.metrics.map(m=>{const e=[...m.entries].sort((a,b)=>a.date<b.date?1:-1)[0];return`<tr><td>${esc(m.name)}</td><td>${esc(e.value)}</td><td>${esc(e.date)}</td></tr>`}).join("")||"<tr><td colspan=3><i>пока пусто</i></td></tr>")}
$("add").onclick=async()=>{const[ok,d]=await api("POST","/api/metrics",{name:$("name").value,value:$("value").value,date:$("mdate").value});$("err").textContent=ok?"":d.error;if(ok)load()};
const payload=()=>({period:$("period").value,date:$("date").value,sections:Object.fromEntries(["done","opportunity","risk","decision","next"].map(k=>[k,$(k).value]))});
async function run(kind){$("ok").textContent=$("err").textContent="";const[ok,d]=await api("POST","/api/summary/"+kind,payload());
if(d.text!==undefined)$("text").textContent=d.text;if(!ok)$("err").textContent=d.error;else if(kind==="send")$("ok").textContent="Отправлено в Telegram"}
$("preview").onclick=()=>run("preview");$("send").onclick=()=>run("send");load();
</script></body></html>