feat(ui): срез 6.1 — панель сметы (просмотр): событие estimate → таблица + итоги
addEstimatePanel рендерит структурированную смету (событие estimate стрима, как files): таблица позиций, итоги СТРОГО из data.totals (JS не считает), нерассчитанные позиции подсвечены, warnings/missing показаны честно, XSS-safe (textContent), таблица со своим горизонт-скроллом. Инфраструктура для панели — инертна пока бэкенд не эмитит estimate. APP_VERSION 2026-07-17m. Браузер-verified.
This commit is contained in:
@@ -138,7 +138,7 @@ MAX_MESSAGE_LEN = 10_000
|
||||
|
||||
# ⚠️ Версия UI — единый источник. БАМПАТЬ ПРИ КАЖДОМ ДЕПЛОЕ (формат: YYYY-MM-DD + буква).
|
||||
# Фронт берёт её через GET /api/version (chat.html + admin.html, элемент .app-version).
|
||||
APP_VERSION = "2026-07-17l"
|
||||
APP_VERSION = "2026-07-17m"
|
||||
|
||||
# Audit: path → action name mapping
|
||||
_AUDIT_MAP = [
|
||||
|
||||
@@ -108,6 +108,19 @@ button { font-family: inherit; }
|
||||
#quick-actions.hide { display: none; }
|
||||
.qa-chip { font-size: .8rem; padding: .35rem .7rem; border: 1px solid var(--border); border-radius: 999px; background: var(--bg-sunken); color: var(--text-muted); cursor: pointer; transition: border-color .15s, color .15s; }
|
||||
.qa-chip:hover { border-color: var(--accent); color: var(--accent); }
|
||||
.est-panel { align-self: stretch; max-width: 100%; margin: .5rem 0; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-card); overflow: hidden; }
|
||||
.est-head { padding: .6rem .9rem; font-weight: 700; font-size: .95rem; color: var(--text); background: var(--bg-sunken); border-bottom: 1px solid var(--border); }
|
||||
.est-scroll { overflow-x: auto; }
|
||||
.est-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
|
||||
.est-table th, .est-table td { padding: .35rem .55rem; border-bottom: 1px solid var(--border-light, var(--border)); text-align: left; color: var(--text); vertical-align: top; }
|
||||
.est-table th { position: sticky; top: 0; background: var(--bg-sunken); color: var(--text-muted); font-weight: 600; white-space: nowrap; }
|
||||
.est-table td.num, .est-table th:nth-child(n+5) { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
|
||||
.est-table tr.est-unresolved td { background: var(--error-bg); }
|
||||
.est-totals { padding: .5rem .9rem; border-top: 1px solid var(--border); }
|
||||
.est-tot-row { display: flex; justify-content: space-between; gap: 1rem; font-size: .85rem; padding: .12rem 0; color: var(--text-muted); }
|
||||
.est-tot-row .num { font-variant-numeric: tabular-nums; }
|
||||
.est-tot-strong { font-weight: 700; color: var(--text); font-size: .95rem; }
|
||||
.est-warn { padding: .5rem .9rem; border-top: 1px solid var(--border); background: var(--error-bg); color: var(--error-text, var(--text)); font-size: .8rem; display: flex; flex-direction: column; gap: .25rem; }
|
||||
.msg-system { align-self: center; background: var(--system-bg); border: none; font-size: .8rem; color: var(--system-text); box-shadow: none; padding: .4rem .8rem; }
|
||||
.typing { align-self: flex-start; color: var(--text-light); font-style: italic; font-size: .85rem; padding: .4rem 0; }
|
||||
|
||||
@@ -1182,6 +1195,9 @@ async function runChat(text) {
|
||||
} else if (eventType === 'files') {
|
||||
// Агент подготовил файлы — кнопки скачивания прямо в чате
|
||||
if (data.files && data.files.length) addFilesMsg(data.files);
|
||||
} else if (eventType === 'estimate') {
|
||||
// Структурированная смета — панель с таблицей (срез 6.1, JS НЕ считает)
|
||||
if (data && data.positions) addEstimatePanel(data);
|
||||
}
|
||||
eventType = '';
|
||||
}
|
||||
@@ -1209,6 +1225,84 @@ async function runChat(text) {
|
||||
}
|
||||
}
|
||||
|
||||
// --- Панель сметы (срез 6.1, read-only): показывает числа ИЗ данных, сама НЕ считает ---
|
||||
function fmtMoney(v) {
|
||||
if (typeof v !== 'number' || !isFinite(v)) return v == null ? '' : String(v);
|
||||
return v.toLocaleString('ru-RU', {minimumFractionDigits: 2, maximumFractionDigits: 2});
|
||||
}
|
||||
function addEstimatePanel(data) {
|
||||
const panel = document.createElement('div');
|
||||
panel.className = 'est-panel';
|
||||
panel.setAttribute('role', 'region');
|
||||
panel.setAttribute('aria-label', 'Смета');
|
||||
const head = document.createElement('div');
|
||||
head.className = 'est-head';
|
||||
head.textContent = data.title || 'Смета';
|
||||
panel.appendChild(head);
|
||||
|
||||
const scroll = document.createElement('div');
|
||||
scroll.className = 'est-scroll';
|
||||
const table = document.createElement('table');
|
||||
table.className = 'est-table';
|
||||
const thead = document.createElement('tr');
|
||||
['№', 'Код', 'Наименование', 'Ед.', 'Кол-во', 'Цена/ед', 'Стоимость'].forEach(h => {
|
||||
const th = document.createElement('th'); th.textContent = h; thead.appendChild(th);
|
||||
});
|
||||
table.appendChild(thead);
|
||||
(data.positions || []).forEach((p, i) => {
|
||||
const tr = document.createElement('tr');
|
||||
const cells = [i + 1, p.code || '', p.name || '', p.unit || '',
|
||||
p.qty != null ? p.qty : '', fmtMoney(p.unit_cost), fmtMoney(p.total)];
|
||||
cells.forEach((c, ci) => {
|
||||
const td = document.createElement('td');
|
||||
td.textContent = c;
|
||||
if (ci >= 4) td.className = 'num'; // числовые колонки — правое выравнивание/tabular
|
||||
tr.appendChild(td);
|
||||
});
|
||||
if (p.unresolved) tr.classList.add('est-unresolved'); // подсветить нерассчитанную позицию
|
||||
table.appendChild(tr);
|
||||
});
|
||||
scroll.appendChild(table);
|
||||
panel.appendChild(scroll);
|
||||
|
||||
// Итоги — строго из data.totals (JS не пересчитывает)
|
||||
const t = data.totals || {};
|
||||
const rows = [
|
||||
['Прямые затраты', t.grand_pz], ['Накладные расходы', t.grand_nr],
|
||||
['Сметная прибыль', t.grand_sp], ['ИТОГО', t.grand_total],
|
||||
['НДС', t.vat], ['Всего с НДС', t.total_with_vat],
|
||||
].filter(r => r[1] != null);
|
||||
if (rows.length) {
|
||||
const tot = document.createElement('div');
|
||||
tot.className = 'est-totals';
|
||||
rows.forEach(([label, val]) => {
|
||||
const row = document.createElement('div');
|
||||
row.className = 'est-tot-row' + (label === 'ИТОГО' || label === 'Всего с НДС' ? ' est-tot-strong' : '');
|
||||
const l = document.createElement('span'); l.textContent = label;
|
||||
const v = document.createElement('span'); v.className = 'num'; v.textContent = fmtMoney(val) + ' ₽';
|
||||
row.appendChild(l); row.appendChild(v); tot.appendChild(row);
|
||||
});
|
||||
panel.appendChild(tot);
|
||||
}
|
||||
|
||||
// Предупреждения/нерасчитанное — честно, не прячем
|
||||
if (data.ok === false || (data.warnings && data.warnings.length) || (data.missing && data.missing.length)) {
|
||||
const warn = document.createElement('div');
|
||||
warn.className = 'est-warn';
|
||||
const items = [];
|
||||
if (data.ok === false) items.push('⚠ Смета не полная: часть позиций не рассчитана — не подавать как готовую.');
|
||||
(data.warnings || []).forEach(w => items.push(typeof w === 'string' ? w : (w.rule || JSON.stringify(w))));
|
||||
(data.missing || []).forEach(m => items.push('Не рассчитано: ' + (m.code || '') + ' — ' + (m.reason || '')));
|
||||
items.forEach(txt => { const d = document.createElement('div'); d.textContent = txt; warn.appendChild(d); });
|
||||
panel.appendChild(warn);
|
||||
}
|
||||
|
||||
const ob = document.getElementById('onboarding'); if (ob) ob.remove();
|
||||
msgs.appendChild(panel);
|
||||
scrollIfPinned();
|
||||
return panel;
|
||||
}
|
||||
|
||||
// --- Session ---
|
||||
async function newChat() {
|
||||
// New tab = new session, old one stays in DB and in the sidebar
|
||||
|
||||
@@ -51,12 +51,23 @@ function _json(o, status=200){ return new Response(JSON.stringify(o),{status,hea
|
||||
window.fetch = async (url, opts={}) => {
|
||||
url = String(url); opts = opts || {};
|
||||
if (url.includes('/api/chat')) {
|
||||
const msg = (()=>{ try { return JSON.parse(opts.body||'{}').message||''; } catch(e){ return ''; } })();
|
||||
const evs = [
|
||||
'event: tool\ndata: {"tool":"mcp__smeta__verify_estimate_file"}\n\n',
|
||||
'event: text\ndata: {"text":"Считаю смету"}\n\n',
|
||||
'event: text\ndata: {"text":" — готово."}\n\n',
|
||||
'event: done\ndata: {"result":"ok"}\n\n',
|
||||
];
|
||||
if (/смет|estimate/i.test(msg)) {
|
||||
const est = {title:'Смета №1', ok:false,
|
||||
positions:[
|
||||
{code:'01-01-001-01', name:'Разработка грунта', unit:'м3', qty:100, unit_cost:150.5, total:15050},
|
||||
{code:'06-01-001-02', name:'Бетон', unit:'м3', qty:20, unit_cost:5000, total:100000, unresolved:true}],
|
||||
totals:{grand_pz:115050, grand_nr:10000, grand_sp:5000, grand_total:130050, vat:28611, total_with_vat:158661},
|
||||
warnings:['Проверьте объёмы по ведомости'],
|
||||
missing:[{code:'06-01-001-02', reason:'цена материала не найдена'}]};
|
||||
evs.push('event: estimate\ndata: ' + JSON.stringify(est) + '\n\n');
|
||||
}
|
||||
evs.push('event: done\ndata: {"result":"ok"}\n\n');
|
||||
return new Response(_sse(evs, opts.signal), {status:200, headers:{'Content-Type':'text/event-stream'}});
|
||||
}
|
||||
if (url.includes('/api/feedback')) { window._fb++; return _json({}); }
|
||||
|
||||
Reference in New Issue
Block a user