/** * =============================================================================== * FILE: modules/web_api/static/js/chat/cards.js * ROLE: Рендеринг специализированных карточек чата: * - Скачивание Word-документов * - Инспекция срезов (таблица сотрудников) * - Инлайн-редакторы промпта и правил * =============================================================================== */ window.ChatCardsRenderer = { renderActionPayload(actionPayload) { if (!actionPayload) return ''; if (actionPayload.type === 'SNAPSHOTS_CARD' && typeof renderSnapshotsCard === 'function') { return renderSnapshotsCard(actionPayload.data); } if (actionPayload.type === 'TASK_INTERACTIVE_CARD' && typeof renderInteractiveTaskCard === 'function') { return renderInteractiveTaskCard(actionPayload.tasks); } if (actionPayload.type === 'FILE_DOWNLOAD_CARD') { const dlUrl = actionPayload.download_url || '#'; const fName = actionPayload.filename || 'document.docx'; const count = actionPayload.tasks_count || ''; return `
${escapeHtml(fName)}
${count ? count + ' · ' : ''}Документ MS Word (.docx)
Скачать файл
`; } if (actionPayload.type === 'SNAPSHOT_INSPECT_CARD') { const records = actionPayload.records || []; const inspectTableId = 'inspect-table-' + Date.now(); const searchInputId = 'inspect-search-' + Date.now(); const rowsHtml = records.map((r, idx) => ` ${idx + 1} ${escapeHtml(r.fio)} ${escapeHtml(r.department)} ${escapeHtml(r.time_in)} ${escapeHtml(r.first_activity)} ${escapeHtml(r.time_out)} ${escapeHtml(r.in_building)} ${r.is_present ? '✓ Да' : 'Нет'} `).join(''); return `
Срез #${escapeHtml(actionPayload.snapshot_id)} · Всего: ${records.length} чел. (Присутствуют: ${actionPayload.present_count || 0})
${rowsHtml}
№ Сотрудник Отдел Вход Активность Выход В здании Статус
`; } if (actionPayload.type === 'PROMPT_EDITOR') { const draftText = actionPayload.raw_draft || actionPayload.baseline_prompt || ''; const editorId = 'prompt-editor-' + Date.now(); return `
Инлайн-редактор системного промпта: Прямое редактирование текста
`; } if (actionPayload.type === 'RULES_EDITOR') { const draftText = actionPayload.raw_draft || actionPayload.baseline_prompt || ''; const editorId = 'rules-editor-' + Date.now(); return `
Редактор базы знаний: Прямое изменение правил
`; } return ''; } }; window.filterInspectTable = function(tableId, query) { const table = document.getElementById(tableId); if (!table) return; const q = (query || '').trim().toLowerCase(); const rows = table.querySelectorAll('.inspect-row'); rows.forEach(r => { const fio = r.getAttribute('data-fio') || ''; const dept = r.getAttribute('data-dept') || ''; if (!q || fio.includes(q) || dept.includes(q)) { r.classList.remove('hidden'); } else { r.classList.add('hidden'); } }); }; window.submitPromptDraftToDiff = function(editorId) { const textarea = document.getElementById(editorId); if (!textarea) return; const newText = textarea.value.trim(); if (!newText) { alert("Текст системного промпта не может быть пустым"); return; } const input = document.getElementById("user-input"); if (input) input.value = `action:save_draft_prompt:::${newText}`; window.sendMessage(); }; window.submitRulesDraftToDiff = function(editorId) { const textarea = document.getElementById(editorId); if (!textarea) return; const newText = textarea.value.trim(); if (!newText) { alert("Правила не могут быть пустыми"); return; } const input = document.getElementById("user-input"); if (input) input.value = `action:save_draft_rules:::${newText}`; window.sendMessage(); };