diff --git a/main.py b/main.py index bec792a..3b989dc 100644 --- a/main.py +++ b/main.py @@ -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-18d" +APP_VERSION = "2026-07-18e" # Audit: path → action name mapping _AUDIT_MAP = [ diff --git a/static/chat.html b/static/chat.html index b6cc89f..008b7cd 100644 --- a/static/chat.html +++ b/static/chat.html @@ -325,6 +325,20 @@ html { color-scheme: light; } + + +
@@ -783,16 +797,52 @@ async function loadSessionDate() { if (r.ok) { const d = await r.json(); updateDateBadge(d.date, d.pinned); } } catch (e) {} } -async function openDatePicker() { - const hasMsgs = !!(document.getElementById('messages') || {}).querySelector?.('.msg, .message'); - let msg = 'Дата, на которую считать нормативы этой сметы.\nФормат ГГГГ-ММ-ДД. Оставьте пустым = «сегодня».'; - if (hasMsgs) msg += '\n\n⚠ В диалоге уже есть ответы. Ранее посчитанное НЕ пересчитается автоматически — попросите ассистента пересчитать по новой дате.'; - const val = prompt(msg, ''); - if (val === null) return; // отмена — ничего не меняем +function _localToday() { + const d = new Date(); + return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0'); +} +function openDatePicker() { + const pop = document.getElementById('date-popover'); + const badge = document.getElementById('date-badge'); + const input = document.getElementById('date-input'); + input.max = _localToday(); // будущее недоступно в календаре + const m = badge.textContent.match(/(\d{4}-\d{2}-\d{2})/); + input.value = m ? m[1] : _localToday(); // предзаполнить текущей датой диалога + const warn = document.getElementById('date-warn'); + const hasMsgs = !!document.querySelector('#messages .msg'); + warn.style.display = hasMsgs ? 'block' : 'none'; + warn.textContent = hasMsgs ? '⚠ В диалоге уже есть ответы. Ранее посчитанное НЕ пересчитается автоматически — попросите ассистента пересчитать по новой дате.' : ''; + pop.style.display = 'block'; // показать, затем спозиционировать под бейджем + const r = badge.getBoundingClientRect(); + pop.style.top = (r.bottom + 6) + 'px'; + pop.style.left = Math.max(8, Math.min(r.left, window.innerWidth - pop.offsetWidth - 8)) + 'px'; + input.focus(); + setTimeout(() => document.addEventListener('mousedown', _dateOutside, true), 0); + document.addEventListener('keydown', _dateEsc); +} +function closeDatePopover() { + document.getElementById('date-popover').style.display = 'none'; + document.removeEventListener('mousedown', _dateOutside, true); + document.removeEventListener('keydown', _dateEsc); +} +function _dateOutside(e) { + const pop = document.getElementById('date-popover'); + if (!pop.contains(e.target) && e.target.id !== 'date-badge') closeDatePopover(); +} +function _dateEsc(e) { if (e.key === 'Escape') closeDatePopover(); } +async function applySessionDate() { + await _postSessionDate(document.getElementById('date-input').value || null); + closeDatePopover(); +} +async function clearSessionDate() { + await _postSessionDate(null); // вернуть диалог к «сегодня» + closeDatePopover(); +} +async function _postSessionDate(date) { try { const r = await fetch('/api/sessions/' + encodeURIComponent(tabId) + '/date', - {method:'POST', headers:{...authHeaders(), 'Content-Type':'application/json'}, - body: JSON.stringify({date: val.trim() || null})}); + {method: 'POST', headers: {...authHeaders(), 'Content-Type': 'application/json'}, + body: JSON.stringify({date})}); const d = await r.json().catch(() => ({})); if (!r.ok) { alert(d.detail || 'Не удалось задать дату'); return; } updateDateBadge(d.date, d.pinned);