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:
@@ -138,7 +138,7 @@ MAX_MESSAGE_LEN = 10_000
|
|||||||
|
|
||||||
# ⚠️ Версия UI — единый источник. БАМПАТЬ ПРИ КАЖДОМ ДЕПЛОЕ (формат: YYYY-MM-DD + буква).
|
# ⚠️ Версия UI — единый источник. БАМПАТЬ ПРИ КАЖДОМ ДЕПЛОЕ (формат: YYYY-MM-DD + буква).
|
||||||
# Фронт берёт её через GET /api/version (chat.html + admin.html, элемент .app-version).
|
# Фронт берёт её через 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: path → action name mapping
|
||||||
_AUDIT_MAP = [
|
_AUDIT_MAP = [
|
||||||
|
|||||||
+58
-8
@@ -325,6 +325,20 @@ html { color-scheme: light; }
|
|||||||
</div>
|
</div>
|
||||||
</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), иначе стрим-перерисовка
|
<!-- role=log имеет неявный aria-live=polite; глушим его (aria-live=off), иначе стрим-перерисовка
|
||||||
innerHTML на каждый чанк зачитывала бы весь растущий ответ. Объявления — через #sr-status. -->
|
innerHTML на каждый чанк зачитывала бы весь растущий ответ. Объявления — через #sr-status. -->
|
||||||
<div id="messages" role="log" aria-live="off" aria-label="История сообщений"></div>
|
<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); }
|
if (r.ok) { const d = await r.json(); updateDateBadge(d.date, d.pinned); }
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
async function openDatePicker() {
|
function _localToday() {
|
||||||
const hasMsgs = !!(document.getElementById('messages') || {}).querySelector?.('.msg, .message');
|
const d = new Date();
|
||||||
let msg = 'Дата, на которую считать нормативы этой сметы.\nФормат ГГГГ-ММ-ДД. Оставьте пустым = «сегодня».';
|
return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0');
|
||||||
if (hasMsgs) msg += '\n\n⚠ В диалоге уже есть ответы. Ранее посчитанное НЕ пересчитается автоматически — попросите ассистента пересчитать по новой дате.';
|
}
|
||||||
const val = prompt(msg, '');
|
function openDatePicker() {
|
||||||
if (val === null) return; // отмена — ничего не меняем
|
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 {
|
try {
|
||||||
const r = await fetch('/api/sessions/' + encodeURIComponent(tabId) + '/date',
|
const r = await fetch('/api/sessions/' + encodeURIComponent(tabId) + '/date',
|
||||||
{method:'POST', headers:{...authHeaders(), 'Content-Type':'application/json'},
|
{method: 'POST', headers: {...authHeaders(), 'Content-Type': 'application/json'},
|
||||||
body: JSON.stringify({date: val.trim() || null})});
|
body: JSON.stringify({date})});
|
||||||
const d = await r.json().catch(() => ({}));
|
const d = await r.json().catch(() => ({}));
|
||||||
if (!r.ok) { alert(d.detail || 'Не удалось задать дату'); return; }
|
if (!r.ok) { alert(d.detail || 'Не удалось задать дату'); return; }
|
||||||
updateDateBadge(d.date, d.pinned);
|
updateDateBadge(d.date, d.pinned);
|
||||||
|
|||||||
Reference in New Issue
Block a user