feat(chat): нормальный date-picker вместо prompt() (нативный, попап, тёмная тема)

Юрий: prompt() — отстой. Заменён на попап под бейджем:
- нативный <input type="date"> с max=сегодня (будущее недоступно), предзаполнение текущей датой;
- кнопки «Применить»/«На сегодня»/«Отмена», Enter применяет, Escape/клик-вне закрывают;
- предупреждение о непересчёте при непустом диалоге inline;
- тёмная тема через var(--card/border/accent/text), без библиотек.
Bump APP_VERSION 2026-07-18e.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
anor
2026-07-18 18:14:25 +10:00
co-authored by Claude Opus 4.8
parent f8b379b973
commit 4dcd198dd4
2 changed files with 59 additions and 9 deletions
+1 -1
View File
@@ -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 = [
+58 -8
View File
@@ -325,6 +325,20 @@ html { color-scheme: light; }
</div>
</div>
<!-- Попап выбора даты сметы: нативный date-picker, тёмная тема через var(), без библиотек -->
<div id="date-popover" role="dialog" aria-label="Дата сметы" style="display:none;position:fixed;z-index:2000;background:var(--card);border:1px solid var(--border);border-radius:12px;padding:14px 16px;box-shadow:0 8px 30px rgba(0,0,0,.22);min-width:264px">
<div style="font-size:.85rem;font-weight:600">Дата сметы</div>
<div style="font-size:.72rem;color:var(--text-muted);margin:2px 0 10px">На эту дату считаются нормативные документы (методики, ГСН, коэффициенты).</div>
<input type="date" id="date-input" onkeydown="if(event.key==='Enter')applySessionDate()"
style="width:100%;box-sizing:border-box;padding:7px 9px;border:1px solid var(--border);border-radius:7px;background:transparent;color:var(--text);font-size:.9rem">
<div id="date-warn" style="display:none;font-size:.72rem;color:var(--accent);margin-top:8px;line-height:1.35"></div>
<div style="display:flex;gap:8px;margin-top:12px;justify-content:flex-end;flex-wrap:wrap">
<button type="button" onclick="closeDatePopover()" style="padding:5px 12px;font-size:.8rem;background:transparent;border:1px solid var(--border);border-radius:7px;color:var(--text-muted);cursor:pointer">Отмена</button>
<button type="button" onclick="clearSessionDate()" style="padding:5px 12px;font-size:.8rem;background:transparent;border:1px solid var(--border);border-radius:7px;color:var(--text);cursor:pointer">На сегодня</button>
<button type="button" onclick="applySessionDate()" style="padding:5px 14px;font-size:.8rem;background:var(--accent);color:#fff;border:none;border-radius:7px;cursor:pointer;font-weight:600">Применить</button>
</div>
</div>
<!-- role=log имеет неявный aria-live=polite; глушим его (aria-live=off), иначе стрим-перерисовка
innerHTML на каждый чанк зачитывала бы весь растущий ответ. Объявления — через #sr-status. -->
<div id="messages" role="log" aria-live="off" aria-label="История сообщений"></div>
@@ -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);