feat(feedback): notify on feedback AI ready/error
This commit is contained in:
+2
-1
@@ -584,7 +584,8 @@ INSERT INTO settings (key, value) VALUES ('feedback_ai_prompt','Ты — пом
|
|||||||
- Не придумывай фактов, которых нет в контексте.
|
- Не придумывай фактов, которых нет в контексте.
|
||||||
|
|
||||||
ФОРМАТ ОТВЕТА: только текст отзыва, без лишних элементов.') ON CONFLICT (key) DO NOTHING;
|
ФОРМАТ ОТВЕТА: только текст отзыва, без лишних элементов.') ON CONFLICT (key) DO NOTHING;
|
||||||
INSERT INTO settings (key, value) VALUES ('notify_feedback_ai_ready','false') ON CONFLICT (key) DO NOTHING;
|
INSERT INTO settings (key, value) VALUES ('notify_feedback_ai_ready','true') ON CONFLICT (key) DO NOTHING;
|
||||||
|
INSERT INTO settings (key, value) VALUES ('notify_feedback_ai_error','true') ON CONFLICT (key) DO NOTHING;
|
||||||
INSERT INTO settings (key, value) VALUES ('feedback_imgbb_url','') ON CONFLICT (key) DO NOTHING;
|
INSERT INTO settings (key, value) VALUES ('feedback_imgbb_url','') ON CONFLICT (key) DO NOTHING;
|
||||||
INSERT INTO settings (key, value) VALUES ('feedback_imgbb_key','') ON CONFLICT (key) DO NOTHING;
|
INSERT INTO settings (key, value) VALUES ('feedback_imgbb_key','') ON CONFLICT (key) DO NOTHING;
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -829,7 +829,9 @@ INSERT INTO settings (key, value) VALUES ('feedback_ai_prompt','Ты — пом
|
|||||||
- Не придумывай фактов, которых нет в контексте.
|
- Не придумывай фактов, которых нет в контексте.
|
||||||
|
|
||||||
ФОРМАТ ОТВЕТА: только текст отзыва, без лишних элементов.') ON CONFLICT (key) DO NOTHING;
|
ФОРМАТ ОТВЕТА: только текст отзыва, без лишних элементов.') ON CONFLICT (key) DO NOTHING;
|
||||||
INSERT INTO settings (key, value) VALUES ('notify_feedback_ai_ready','false') ON CONFLICT (key) DO NOTHING;
|
INSERT INTO settings (key, value) VALUES ('notify_feedback_ai_ready','true') ON CONFLICT (key) DO NOTHING;
|
||||||
|
INSERT INTO settings (key, value) VALUES ('notify_feedback_ai_error','true') ON CONFLICT (key) DO NOTHING;
|
||||||
|
UPDATE settings SET value = 'true' WHERE key = 'notify_feedback_ai_ready' AND value IN ('false');
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS user_settings (
|
CREATE TABLE IF NOT EXISTS user_settings (
|
||||||
user_id INT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
user_id INT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
|||||||
@@ -245,6 +245,7 @@ const NOTIFY_ICONS = {
|
|||||||
'lesson.report': 'notebook-pen',
|
'lesson.report': 'notebook-pen',
|
||||||
'lesson.ai.formatted': 'file-check',
|
'lesson.ai.formatted': 'file-check',
|
||||||
'feedback.ai.ready': 'message-square-heart',
|
'feedback.ai.ready': 'message-square-heart',
|
||||||
|
'feedback.ai.error': 'message-square-x',
|
||||||
'face.scan.done': 'scan-face',
|
'face.scan.done': 'scan-face',
|
||||||
'face.recognized': 'user-round-check',
|
'face.recognized': 'user-round-check',
|
||||||
'face.scan.error': 'scan-search',
|
'face.scan.error': 'scan-search',
|
||||||
|
|||||||
+50
-22
@@ -6,45 +6,64 @@
|
|||||||
<title>Дайджест — Админ-панель</title>
|
<title>Дайджест — Админ-панель</title>
|
||||||
<link rel="stylesheet" href="admin.css">
|
<link rel="stylesheet" href="admin.css">
|
||||||
<style>
|
<style>
|
||||||
|
.digest-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
|
||||||
|
.digest-toolbar .search-input { flex: 1; min-width: 240px; max-width: 420px; }
|
||||||
|
.digest-count { font-size: .82rem; color: var(--muted); margin-left: auto; white-space: nowrap; }
|
||||||
.digest-list { display: flex; flex-direction: column; gap: 14px; margin-top: 12px; }
|
.digest-list { display: flex; flex-direction: column; gap: 14px; margin-top: 12px; }
|
||||||
.digest-card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
|
.digest-card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
|
||||||
.digest-card.pinned { border-left: 4px solid #f59e0b; background: rgba(245,158,11,.04); }
|
.digest-card.pinned { border-left: 4px solid #f59e0b; background: rgba(245,158,11,.04); }
|
||||||
.digest-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
|
.digest-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
|
||||||
.digest-title { font-weight: 600; font-size: 1.05rem; word-break: break-word; margin: 0; }
|
.digest-title { font-weight: 600; font-size: 1.05rem; word-break: break-word; margin: 0; }
|
||||||
.digest-meta { font-size: .82rem; color: var(--muted); display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
|
.digest-meta { font-size: .82rem; color: var(--muted); display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
|
||||||
.digest-badge { padding: 1px 8px; border-radius: 999px; font-size: .68rem; font-weight: 600; background: rgba(245,158,11,.12); color: #b45309; }
|
.digest-meta-item { display: inline-flex; align-items: center; gap: 5px; }
|
||||||
|
.digest-meta-item svg { width: 13px; height: 13px; opacity: .7; }
|
||||||
|
.digest-badge { padding: 2px 9px; border-radius: 999px; font-size: .68rem; font-weight: 600; background: rgba(245,158,11,.12); color: #b45309; white-space: nowrap; }
|
||||||
|
.digest-badge.scheduled { background: rgba(37,99,235,.12); color: var(--accent); }
|
||||||
|
.digest-badge.dim { background: var(--bg); color: var(--muted); }
|
||||||
.digest-body { font-size: .95rem; line-height: 1.6; color: var(--text); overflow-wrap: anywhere; white-space: pre-wrap; }
|
.digest-body { font-size: .95rem; line-height: 1.6; color: var(--text); overflow-wrap: anywhere; white-space: pre-wrap; }
|
||||||
|
.digest-body.clamp { max-height: 150px; overflow: hidden; position: relative; }
|
||||||
|
.digest-body.clamp::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 38px; background: linear-gradient(transparent, var(--card)); pointer-events: none; }
|
||||||
|
.digest-body-toggle { align-self: flex-start; background: none; border: none; color: var(--accent); font-size: .8rem; font-weight: 600; cursor: pointer; padding: 0; }
|
||||||
|
.digest-body-toggle:hover { text-decoration: underline; }
|
||||||
.digest-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; border-top: 1px solid var(--border); padding-top: 10px; margin-top: auto; }
|
.digest-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; border-top: 1px solid var(--border); padding-top: 10px; margin-top: auto; }
|
||||||
.digest-actions { display: flex; gap: 6px; flex-wrap: wrap; }
|
.digest-actions { display: flex; gap: 6px; flex-wrap: wrap; }
|
||||||
.digest-empty { color: var(--muted); font-size: .95rem; padding: 16px; }
|
.digest-empty { border: 1px dashed var(--border); border-radius: 12px; padding: 44px 20px; display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; color: var(--muted); }
|
||||||
|
.digest-empty svg { width: 28px; height: 28px; opacity: .55; }
|
||||||
|
.digest-empty.error svg { color: #ef4444; opacity: .8; }
|
||||||
|
.digest-empty p { margin: 0; font-size: .95rem; }
|
||||||
|
.digest-empty .sub { font-size: .82rem; opacity: .8; max-width: 420px; }
|
||||||
|
.digest-empty .btn-primary { margin-top: 10px; }
|
||||||
|
.digest-none { color: var(--muted); font-size: .85rem; font-style: italic; }
|
||||||
|
.digest-hidden { opacity: 0.72; }
|
||||||
|
.digest-highlight { outline: 2px solid #f59e0b; outline-offset: 2px; border-radius: 8px; }
|
||||||
.digest-new-btn { margin-left: auto; }
|
.digest-new-btn { margin-left: auto; }
|
||||||
.digest-preview-img { max-width: 240px; max-height: 150px; border: 1px solid var(--border); border-radius: 8px; margin: 8px 0 4px 0; display: block; }
|
.digest-preview-img { max-width: 240px; max-height: 150px; border: 1px solid var(--border); border-radius: 8px; margin: 8px 0 4px 0; display: block; }
|
||||||
.digest-images { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
|
.digest-images { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
|
||||||
.digest-image { position: relative; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; width: 130px; height: 95px; flex-shrink: 0; }
|
.digest-image { position: relative; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; width: 130px; height: 95px; flex-shrink: 0; }
|
||||||
.digest-image img { width: 100%; height: 100%; object-fit: cover; display: block; }
|
.digest-image img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: pointer; }
|
||||||
.digest-image-remove { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.7); color: #fff; border: none; border-radius: 6px; padding: 2px 7px; font-size: .75rem; cursor: pointer; }
|
.digest-image-remove { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.7); color: #fff; border: none; border-radius: 6px; padding: 2px 7px; font-size: .75rem; cursor: pointer; }
|
||||||
.digest-image-remove:hover { background: #ef4444; }
|
.digest-image-remove:hover { background: #ef4444; }
|
||||||
.digest-date-row { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; }
|
|
||||||
.digest-date-row .settings-field { flex: 1; min-width: 200px; margin: 0; }
|
|
||||||
.field-hint { font-size: .78rem; color: var(--muted); margin-top: 4px; display: block; }
|
|
||||||
.digest-none { color: var(--muted); font-size: .85rem; font-style: italic; }
|
|
||||||
.digest-head-img { margin: 8px 0 10px 0; }
|
.digest-head-img { margin: 8px 0 10px 0; }
|
||||||
.digest-images-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
|
.digest-images-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
|
||||||
.digest-card-thumb { width: 70px; height: 55px; object-fit: cover; border: 1px solid var(--border); border-radius: 6px; flex-shrink: 0; display: block; }
|
.digest-card-thumb { width: 70px; height: 55px; object-fit: cover; border: 1px solid var(--border); border-radius: 6px; flex-shrink: 0; display: block; }
|
||||||
.digest-shot { position: relative; display: inline-flex; align-items: center; justify-content: center; border: none; background: transparent; padding: 0; cursor: pointer; border-radius: 6px; overflow: hidden; }
|
.digest-shot { position: relative; display: inline-flex; align-items: center; justify-content: center; border: none; background: transparent; padding: 0; cursor: pointer; border-radius: 6px; overflow: hidden; }
|
||||||
.digest-shot-zoom { position: absolute; bottom: 4px; right: 4px; background: rgba(0,0,0,.55); color: #fff; border-radius: 4px; padding: 2px 5px; font-size: .65rem; opacity: 0; transition: opacity .15s; }
|
.digest-shot-zoom { position: absolute; bottom: 4px; right: 4px; background: rgba(0,0,0,.55); color: #fff; border-radius: 4px; padding: 2px 5px; font-size: .65rem; opacity: 0; transition: opacity .15s; }
|
||||||
.digest-shot:hover .digest-shot-zoom { opacity: 1; }
|
.digest-shot:hover .digest-shot-zoom { opacity: 1; }
|
||||||
.digest-hidden { opacity: 0.72; }
|
.field-hint { font-size: .78rem; color: var(--muted); margin-top: 4px; display: block; }
|
||||||
.digest-highlight { outline: 2px solid #f59e0b; outline-offset: 2px; border-radius: 8px; }
|
.digest-file-hidden { display: none; }
|
||||||
|
.digest-file-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 6px; }
|
||||||
|
.digest-pick { cursor: pointer; }
|
||||||
#digestModal .edit-modal { width: 1000px; max-width: none; }
|
#digestModal .edit-modal { width: 1000px; max-width: none; }
|
||||||
#digestModal .bookmark-modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
|
#digestModal .bookmark-modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
|
||||||
.digest-modal-body { max-height: 62vh; overflow-y: auto; padding: 12px 0 8px 0; }
|
#digestModal .digest-modal-body { flex: 0 0 auto; max-height: 62vh; overflow-y: auto; padding: 12px 0 8px 0; }
|
||||||
.digest-modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
|
.digest-modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
|
||||||
@media (max-width: 720px) { .digest-modal-grid { grid-template-columns: 1fr; } }
|
@media (max-width: 720px) { .digest-modal-grid { grid-template-columns: 1fr; } }
|
||||||
.digest-modal-col { display: flex; flex-direction: column; gap: 12px; }
|
.digest-modal-col { display: flex; flex-direction: column; gap: 12px; }
|
||||||
.digest-modal-col .settings-field { margin: 0; }
|
.digest-modal-col .settings-field { margin: 0; }
|
||||||
|
.digest-counter { font-size: .75rem; font-weight: 400; color: var(--muted); margin-left: auto; }
|
||||||
|
.digest-check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 400 !important; }
|
||||||
|
.digest-check input { width: auto; }
|
||||||
#digestModal .edit-modal { display: flex; flex-direction: column; max-height: 85vh; }
|
#digestModal .edit-modal { display: flex; flex-direction: column; max-height: 85vh; }
|
||||||
#digestModal .digest-modal-body { flex: 0 0 auto; }
|
|
||||||
#digestModal .card-foot { flex: 0 0 auto; margin-top: 10px; }
|
#digestModal .card-foot { flex: 0 0 auto; margin-top: 10px; }
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
@@ -57,6 +76,10 @@
|
|||||||
<p class="page-sub">Важные сообщения для команды</p>
|
<p class="page-sub">Важные сообщения для команды</p>
|
||||||
<button type="button" class="btn-primary digest-new-btn" id="digestNewBtn"><i data-lucide="plus"></i> Новое сообщение</button>
|
<button type="button" class="btn-primary digest-new-btn" id="digestNewBtn"><i data-lucide="plus"></i> Новое сообщение</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="digest-toolbar">
|
||||||
|
<input type="search" id="digestSearch" class="search-input" placeholder="Поиск по заголовку, тексту или автору" autocomplete="off">
|
||||||
|
<span id="digestCount" class="digest-count"></span>
|
||||||
|
</div>
|
||||||
<div id="digestList" class="digest-list"></div>
|
<div id="digestList" class="digest-list"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -71,20 +94,22 @@
|
|||||||
<div class="digest-modal-grid">
|
<div class="digest-modal-grid">
|
||||||
<div class="digest-modal-col">
|
<div class="digest-modal-col">
|
||||||
<div class="settings-field">
|
<div class="settings-field">
|
||||||
<label>Заголовок <span style="color:#ef4444">*</span></label>
|
<label>Заголовок <span style="color:#ef4444">*</span><span class="digest-counter" id="digestTitleCount">0 / 200</span></label>
|
||||||
<input id="digestTitle" class="settings-input" maxlength="200" placeholder="Например: Мероприятия на этой неделе">
|
<input id="digestTitle" class="settings-input" maxlength="200" placeholder="Например: Мероприятия на этой неделе">
|
||||||
</div>
|
</div>
|
||||||
<div class="settings-field">
|
<div class="settings-field">
|
||||||
<label>Текст сообщения <span style="color:#ef4444">*</span></label>
|
<label>Текст сообщения <span style="color:#ef4444">*</span><span class="digest-counter" id="digestBodyCount">0 / 5000</span></label>
|
||||||
<textarea id="digestBody" class="settings-input" rows="8" placeholder="Что нужно сообщить ученикам и тьюторам..."></textarea>
|
<textarea id="digestBody" class="settings-input" rows="10" maxlength="5000" placeholder="Что нужно сообщить ученикам и тьюторам..."></textarea>
|
||||||
|
<span class="field-hint">Курсор в поле текста + Ctrl+V — вставит картинку из буфера обмена.</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="settings-field">
|
<div class="settings-field">
|
||||||
<label class="digest-check"><input type="checkbox" id="digestPinned"> Закрепить в начале списка (только администратор)</label>
|
<label class="digest-check"><input type="checkbox" id="digestPinned"> Закрепить в начале списка</label>
|
||||||
|
<span class="field-hint">Доступно администраторам. Закреплённые сообщения всегда сверху.</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="settings-field">
|
<div class="settings-field">
|
||||||
<label>Дата публикации</label>
|
<label>Дата публикации</label>
|
||||||
<input type="datetime-local" id="digestPostAt">
|
<input type="datetime-local" id="digestPostAt">
|
||||||
<span class="field-hint">Пусто — опубликовано сразу. Будущая дата — появится автоматически и придет уведомление всем.</span>
|
<span class="field-hint">Пусто — опубликовано сразу. Будущая дата — появится автоматически для всех и придёт уведомление.</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="settings-field">
|
<div class="settings-field">
|
||||||
<label>Скрыть после</label>
|
<label>Скрыть после</label>
|
||||||
@@ -98,18 +123,21 @@
|
|||||||
<div id="digestPreviewWrap" style="position:relative;display:inline-block;margin-top:6px">
|
<div id="digestPreviewWrap" style="position:relative;display:inline-block;margin-top:6px">
|
||||||
<img id="digestPreviewImg" class="digest-preview-img" src="" alt="превью">
|
<img id="digestPreviewImg" class="digest-preview-img" src="" alt="превью">
|
||||||
</div>
|
</div>
|
||||||
<input type="file" id="digestPreviewFile" accept="image/*" style="margin-top:6px;display:block">
|
<div class="digest-file-row">
|
||||||
<button type="button" class="btn-link ghost danger" id="digestPreviewRemove" style="margin-top:4px;display:none">Убрать превью</button>
|
<label class="btn-primary ghost digest-pick" for="digestPreviewFile"><i data-lucide="image-plus"></i> Выбрать файл</label>
|
||||||
|
<button type="button" class="btn-primary danger-ghost" id="digestPreviewRemove" style="display:none"><i data-lucide="trash-2"></i> Убрать превью</button>
|
||||||
|
</div>
|
||||||
|
<input type="file" id="digestPreviewFile" accept="image/*" class="digest-file-hidden">
|
||||||
<span class="field-hint">Обложка сообщения. Загружается при сохранении.</span>
|
<span class="field-hint">Обложка сообщения. Загружается при сохранении.</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="settings-field">
|
<div class="settings-field">
|
||||||
<label>Картинки в сообщение</label>
|
<label>Картинки в сообщение</label>
|
||||||
<div id="digestImagesWrap" class="digest-images"></div>
|
<div id="digestImagesWrap" class="digest-images"></div>
|
||||||
<div style="margin-top:6px">
|
<div class="digest-file-row">
|
||||||
<input type="file" id="digestImageFile" accept="image/*" multiple>
|
<label class="btn-primary ghost digest-pick" id="digestImageAdd" for="digestImageFile"><i data-lucide="images"></i> Добавить картинки</label>
|
||||||
<button type="button" class="btn-link ghost" id="digestImageAdd" style="margin-left:8px">Добавить картинки</button>
|
<input type="file" id="digestImageFile" accept="image/*" multiple class="digest-file-hidden">
|
||||||
</div>
|
</div>
|
||||||
<span class="field-hint">До 20 картинок. Удаление картинки стирает файл с диска. Вставка из буфера — Ctrl+V в поле текста.</span>
|
<span class="field-hint">До 20 картинок. Удаление картинки стирает файл с диска.</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+147
-48
@@ -3,6 +3,8 @@
|
|||||||
let digests = [];
|
let digests = [];
|
||||||
let editingId = null;
|
let editingId = null;
|
||||||
let saving = false;
|
let saving = false;
|
||||||
|
let query = '';
|
||||||
|
let digestLoaded = false;
|
||||||
let previewPath = null;
|
let previewPath = null;
|
||||||
let previewRemoved = false;
|
let previewRemoved = false;
|
||||||
let previewFile = null;
|
let previewFile = null;
|
||||||
@@ -40,6 +42,7 @@
|
|||||||
const pinnedEl = document.getElementById('digestPinned');
|
const pinnedEl = document.getElementById('digestPinned');
|
||||||
const postAtEl = document.getElementById('digestPostAt');
|
const postAtEl = document.getElementById('digestPostAt');
|
||||||
const hideAtEl = document.getElementById('digestHideAt');
|
const hideAtEl = document.getElementById('digestHideAt');
|
||||||
|
let restored = false;
|
||||||
if (titleEl && d.title != null) titleEl.value = d.title;
|
if (titleEl && d.title != null) titleEl.value = d.title;
|
||||||
if (bodyEl && d.body != null) bodyEl.value = d.body;
|
if (bodyEl && d.body != null) bodyEl.value = d.body;
|
||||||
if (pinnedEl && d.isPinned != null) pinnedEl.checked = !!d.isPinned;
|
if (pinnedEl && d.isPinned != null) pinnedEl.checked = !!d.isPinned;
|
||||||
@@ -47,7 +50,9 @@
|
|||||||
if (hideAtEl && d.hideAt != null) hideAtEl.value = d.hideAt;
|
if (hideAtEl && d.hideAt != null) hideAtEl.value = d.hideAt;
|
||||||
previewPath = d.previewPath || null;
|
previewPath = d.previewPath || null;
|
||||||
showPreview(previewPath);
|
showPreview(previewPath);
|
||||||
} catch (e) {}
|
restored = !!(d.title || d.body || d.postAt || d.hideAt || previewPath || d.isPinned);
|
||||||
|
return restored;
|
||||||
|
} catch { return false; }
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearDraft() {
|
function clearDraft() {
|
||||||
@@ -67,12 +72,6 @@
|
|||||||
return String(s || '').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
|
return String(s || '').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
|
||||||
}
|
}
|
||||||
|
|
||||||
function escAttr(s) {
|
|
||||||
const d = document.createElement('textarea');
|
|
||||||
d.textContent = s || '';
|
|
||||||
return d.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
function tzOffsetMinutes(instant) {
|
function tzOffsetMinutes(instant) {
|
||||||
try {
|
try {
|
||||||
const d = new Date(instant);
|
const d = new Date(instant);
|
||||||
@@ -111,34 +110,20 @@
|
|||||||
} catch { return null; }
|
} catch { return null; }
|
||||||
}
|
}
|
||||||
|
|
||||||
function thumbSrc(p) {
|
|
||||||
if (!p) return '';
|
|
||||||
if (p.startsWith('/uploads/')) return `${API}/uploads/thumb/${p.slice('/uploads/'.length)}`;
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
function fmtDigestDate(iso) {
|
|
||||||
if (!iso) return '—';
|
|
||||||
try {
|
|
||||||
return new Intl.DateTimeFormat('ru-RU', {
|
|
||||||
timeZone: DateTime.tz, day: '2-digit', month: '2-digit', year: 'numeric',
|
|
||||||
hour: '2-digit', minute: '2-digit'
|
|
||||||
}).format(new Date(iso));
|
|
||||||
} catch { return String(iso).slice(0, 16); }
|
|
||||||
}
|
|
||||||
|
|
||||||
function digestCardHtml(d) {
|
function digestCardHtml(d) {
|
||||||
const admin = isAdmin();
|
const admin = isAdmin();
|
||||||
const mine = currentUser && d.author_id === currentUser.id;
|
const mine = currentUser && d.author_id === currentUser.id;
|
||||||
const canEdit = admin || mine;
|
const canEdit = admin || mine;
|
||||||
const pinned = !!d.is_pinned;
|
const pinned = !!d.is_pinned;
|
||||||
const nowTs = new Date();
|
const nowTs = Date.now();
|
||||||
|
const postFuture = d.post_at && new Date(d.post_at).getTime() > nowTs;
|
||||||
const hidden = d.hide_at && new Date(d.hide_at) <= nowTs;
|
const hidden = d.hide_at && new Date(d.hide_at) <= nowTs;
|
||||||
|
|
||||||
const badge = [];
|
const badge = [];
|
||||||
if (pinned) badge.push('<span class="digest-badge">Закреплено</span>');
|
if (pinned) badge.push('<span class="digest-badge">Закреплено</span>');
|
||||||
if (d.post_at) badge.push('<span class="digest-badge">Публикация ' + fmtDigestDate(d.post_at) + '</span>');
|
if (postFuture) badge.push('<span class="digest-badge scheduled">Запланировано на ' + esc(fmtDateTimeY(d.post_at)) + '</span>');
|
||||||
if (d.hide_at) badge.push('<span class="digest-badge">Скрыть ' + fmtDigestDate(d.hide_at) + '</span>');
|
if (hidden) badge.push('<span class="digest-badge dim">Скрыто</span>');
|
||||||
|
else if (d.hide_at) badge.push('<span class="digest-badge dim">Скроется ' + esc(fmtDateTimeY(d.hide_at)) + '</span>');
|
||||||
|
|
||||||
const preview = d.preview_path
|
const preview = d.preview_path
|
||||||
? '<div class="digest-head-img"><button type="button" class="digest-shot" data-img="' + esc(d.preview_path) + '" title="Открыть превью"><img class="digest-preview-img" src="' + esc(thumbSrc(d.preview_path)) + '" alt="превью"></button></div>'
|
? '<div class="digest-head-img"><button type="button" class="digest-shot" data-img="' + esc(d.preview_path) + '" title="Открыть превью"><img class="digest-preview-img" src="' + esc(thumbSrc(d.preview_path)) + '" alt="превью"></button></div>'
|
||||||
@@ -164,6 +149,11 @@
|
|||||||
actions.push('<button type="button" class="btn-link" data-action="pin" data-id="' + d.id + '" data-pin="' + (pinned ? '0' : '1') + '">' + (pinned ? 'Открепить' : 'Закрепить') + '</button>');
|
actions.push('<button type="button" class="btn-link" data-action="pin" data-id="' + d.id + '" data-pin="' + (pinned ? '0' : '1') + '">' + (pinned ? 'Открепить' : 'Закрепить') + '</button>');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bodyText = d.body || '';
|
||||||
|
const longBody = bodyText.length > 600;
|
||||||
|
const bodyHtml = '<div class="digest-body' + (longBody ? ' clamp' : '') + '">' + esc(bodyText) + '</div>' +
|
||||||
|
(longBody ? '<button type="button" class="digest-body-toggle" data-action="toggle-body" data-id="' + d.id + '">Показать полностью</button>' : '');
|
||||||
|
|
||||||
return '<div class="digest-card' + (pinned ? ' pinned' : '') + (hidden ? ' digest-hidden' : '') + '" data-id="' + d.id + '">' +
|
return '<div class="digest-card' + (pinned ? ' pinned' : '') + (hidden ? ' digest-hidden' : '') + '" data-id="' + d.id + '">' +
|
||||||
'<div class="digest-head">' +
|
'<div class="digest-head">' +
|
||||||
'<h3 class="digest-title">' + esc(d.title) + '</h3>' +
|
'<h3 class="digest-title">' + esc(d.title) + '</h3>' +
|
||||||
@@ -171,10 +161,10 @@
|
|||||||
'</div>' +
|
'</div>' +
|
||||||
preview +
|
preview +
|
||||||
'<div class="digest-meta">' +
|
'<div class="digest-meta">' +
|
||||||
'<span>' + esc(d.author_name || '—') + '</span>' +
|
'<span class="digest-meta-item"><i data-lucide="user"></i>' + esc(d.author_name || '—') + '</span>' +
|
||||||
'<span>' + fmtShortIso(d.created_at) + '</span>' +
|
'<span class="digest-meta-item"><i data-lucide="calendar"></i>' + esc(fmtDateTimeY(d.published_at || d.created_at)) + '</span>' +
|
||||||
'</div>' +
|
'</div>' +
|
||||||
'<div class="digest-body">' + esc(d.body) + '</div>' +
|
bodyHtml +
|
||||||
imagesHtml +
|
imagesHtml +
|
||||||
'<div class="digest-foot">' +
|
'<div class="digest-foot">' +
|
||||||
'<div class="digest-actions">' + actions.join('') + '</div>' +
|
'<div class="digest-actions">' + actions.join('') + '</div>' +
|
||||||
@@ -182,14 +172,55 @@
|
|||||||
'</div>';
|
'</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function filterDigests() {
|
||||||
|
const q = query.trim().toLowerCase();
|
||||||
|
if (!q) return digests;
|
||||||
|
return digests.filter(function(d) {
|
||||||
|
return (d.title || '').toLowerCase().includes(q) ||
|
||||||
|
(d.body || '').toLowerCase().includes(q) ||
|
||||||
|
(d.author_name || '').toLowerCase().includes(q);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateCountInfo(list) {
|
||||||
|
const el = document.getElementById('digestCount');
|
||||||
|
if (!el) return;
|
||||||
|
el.textContent = query.trim()
|
||||||
|
? 'Найдено: ' + list.length + ' из ' + digests.length
|
||||||
|
: (digests.length ? 'Сообщений: ' + digests.length : '');
|
||||||
|
}
|
||||||
|
|
||||||
function renderDigests() {
|
function renderDigests() {
|
||||||
const el = document.getElementById('digestList');
|
const el = document.getElementById('digestList');
|
||||||
if (!el) return;
|
if (!el) return;
|
||||||
|
if (!digestLoaded) return;
|
||||||
|
const list = filterDigests();
|
||||||
|
updateCountInfo(list);
|
||||||
if (!digests.length) {
|
if (!digests.length) {
|
||||||
el.innerHTML = '<div class="digest-empty">Сообщений пока нет</div>';
|
el.innerHTML = '<div class="digest-empty"><i data-lucide="megaphone"></i>' +
|
||||||
|
'<p>Сообщений пока нет</p>' +
|
||||||
|
'<p class="sub">Опубликуйте важное объявление — его увидят все тьюторы и админы.</p>' +
|
||||||
|
'</div>';
|
||||||
|
renderIcons();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
el.innerHTML = digests.map(digestCardHtml).join('');
|
if (!list.length) {
|
||||||
|
el.innerHTML = '<div class="digest-empty"><i data-lucide="search-x"></i>' +
|
||||||
|
'<p>Ничего не найдено</p>' +
|
||||||
|
'<p class="sub">По запросу «' + esc(query.trim()) + '» сообщений нет</p></div>';
|
||||||
|
renderIcons();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
el.innerHTML = list.map(digestCardHtml).join('');
|
||||||
|
renderIcons();
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderLoadError() {
|
||||||
|
const el = document.getElementById('digestList');
|
||||||
|
if (!el) return;
|
||||||
|
el.innerHTML = '<div class="digest-empty error"><i data-lucide="wifi-off"></i>' +
|
||||||
|
'<p>Не удалось загрузить сообщения</p>' +
|
||||||
|
'<button type="button" class="btn-primary ghost" data-action="reload">Повторить</button></div>';
|
||||||
renderIcons();
|
renderIcons();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,12 +229,18 @@
|
|||||||
try {
|
try {
|
||||||
res = await fetch(API + '/api/digests', { headers: hdr() });
|
res = await fetch(API + '/api/digests', { headers: hdr() });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if (!digestLoaded) renderLoadError();
|
||||||
showToast('Ошибка сети при загрузке дайджеста', true);
|
showToast('Ошибка сети при загрузке дайджеста', true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!res.ok) return;
|
if (!res.ok) {
|
||||||
|
if (!digestLoaded) renderLoadError();
|
||||||
|
showToast('Не удалось загрузить дайджест', true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const data = await res.json().catch(function() { return {}; });
|
const data = await res.json().catch(function() { return {}; });
|
||||||
digests = Array.isArray(data.items) ? data.items : (Array.isArray(data) ? data : []);
|
digests = Array.isArray(data.items) ? data.items : (Array.isArray(data) ? data : []);
|
||||||
|
digestLoaded = true;
|
||||||
renderDigests();
|
renderDigests();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,6 +290,15 @@
|
|||||||
btn.style.display = path || previewRemoved || previewFile ? '' : 'none';
|
btn.style.display = path || previewRemoved || previewFile ? '' : 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateCounts() {
|
||||||
|
const t = document.getElementById('digestTitle');
|
||||||
|
const b = document.getElementById('digestBody');
|
||||||
|
const tc = document.getElementById('digestTitleCount');
|
||||||
|
const bc = document.getElementById('digestBodyCount');
|
||||||
|
if (t && tc) tc.textContent = t.value.length + ' / 200';
|
||||||
|
if (b && bc) bc.textContent = b.value.length + ' / 5000';
|
||||||
|
}
|
||||||
|
|
||||||
function openDigestModal(d) {
|
function openDigestModal(d) {
|
||||||
editingId = d ? d.id : null;
|
editingId = d ? d.id : null;
|
||||||
previewPath = d ? d.preview_path : null;
|
previewPath = d ? d.preview_path : null;
|
||||||
@@ -260,8 +306,8 @@
|
|||||||
previewFile = null;
|
previewFile = null;
|
||||||
digestImages = [];
|
digestImages = [];
|
||||||
document.getElementById('digestModalTitle').textContent = d ? 'Редактирование сообщения' : 'Новое сообщение';
|
document.getElementById('digestModalTitle').textContent = d ? 'Редактирование сообщения' : 'Новое сообщение';
|
||||||
document.getElementById('digestTitle').value = d ? escAttr(d.title) : '';
|
document.getElementById('digestTitle').value = d ? d.title : '';
|
||||||
document.getElementById('digestBody').value = d ? escAttr(d.body) : '';
|
document.getElementById('digestBody').value = d ? d.body : '';
|
||||||
document.getElementById('digestPostAt').value = d ? toLocalInput(d.post_at) : '';
|
document.getElementById('digestPostAt').value = d ? toLocalInput(d.post_at) : '';
|
||||||
document.getElementById('digestHideAt').value = d ? toLocalInput(d.hide_at) : '';
|
document.getElementById('digestHideAt').value = d ? toLocalInput(d.hide_at) : '';
|
||||||
const pinRow = document.getElementById('digestPinned').closest('.settings-field');
|
const pinRow = document.getElementById('digestPinned').closest('.settings-field');
|
||||||
@@ -272,22 +318,26 @@
|
|||||||
document.getElementById('digestImageFile').value = '';
|
document.getElementById('digestImageFile').value = '';
|
||||||
const canManageImages = !!editingId;
|
const canManageImages = !!editingId;
|
||||||
document.getElementById('digestImageAdd').style.display = canManageImages ? '' : 'none';
|
document.getElementById('digestImageAdd').style.display = canManageImages ? '' : 'none';
|
||||||
document.getElementById('digestImagesWrap').style.display = canManageImages ? '' : 'none';
|
document.getElementById('digestImagesWrap').style.display = '';
|
||||||
if (canManageImages) {
|
if (canManageImages) {
|
||||||
loadImages(editingId);
|
loadImages(editingId);
|
||||||
} else {
|
} else {
|
||||||
document.getElementById('digestImagesWrap').innerHTML = '<span class="digest-none">Сохраните сообщение, чтобы добавить картинки</span>';
|
document.getElementById('digestImagesWrap').innerHTML = '<span class="digest-none">Добавятся после сохранения. Или вставьте картинку из буфера — Ctrl+V в поле текста, сообщение сохранится автоматически.</span>';
|
||||||
}
|
}
|
||||||
|
let draftRestored = false;
|
||||||
if (editingId) {
|
if (editingId) {
|
||||||
clearDraft();
|
clearDraft();
|
||||||
} else {
|
} else {
|
||||||
restoreDraft();
|
draftRestored = restoreDraft();
|
||||||
}
|
}
|
||||||
|
updateCounts();
|
||||||
document.getElementById('digestModal').classList.add('open');
|
document.getElementById('digestModal').classList.add('open');
|
||||||
document.getElementById('digestTitle').focus();
|
document.getElementById('digestTitle').focus();
|
||||||
|
if (draftRestored) showToast('Несохранённый черновик восстановлен');
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeDigestModal() {
|
function closeDigestModal() {
|
||||||
|
if (saving) return;
|
||||||
if (hasDraft() && !confirm('Есть несохранённые изменения. Закрыть без сохранения?')) return;
|
if (hasDraft() && !confirm('Есть несохранённые изменения. Закрыть без сохранения?')) return;
|
||||||
document.getElementById('digestModal').classList.remove('open');
|
document.getElementById('digestModal').classList.remove('open');
|
||||||
editingId = null;
|
editingId = null;
|
||||||
@@ -299,7 +349,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function uploadPreview(digestId) {
|
async function uploadPreview(digestId) {
|
||||||
if (!previewFile) return;
|
|
||||||
if (previewRemoved) {
|
if (previewRemoved) {
|
||||||
try {
|
try {
|
||||||
await fetch(API + '/api/digests/' + digestId + '/preview', { method: 'DELETE', headers: hdr() });
|
await fetch(API + '/api/digests/' + digestId + '/preview', { method: 'DELETE', headers: hdr() });
|
||||||
@@ -307,6 +356,7 @@
|
|||||||
previewRemoved = false;
|
previewRemoved = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!previewFile) return;
|
||||||
const fd = new FormData();
|
const fd = new FormData();
|
||||||
fd.append('image', previewFile);
|
fd.append('image', previewFile);
|
||||||
try {
|
try {
|
||||||
@@ -322,17 +372,37 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setInvalid(el, on) {
|
||||||
|
if (el) el.classList.toggle('invalid', !!on);
|
||||||
|
}
|
||||||
|
|
||||||
async function doSaveDigest() {
|
async function doSaveDigest() {
|
||||||
const title = document.getElementById('digestTitle').value.trim();
|
const titleEl = document.getElementById('digestTitle');
|
||||||
const body = document.getElementById('digestBody').value.trim();
|
const bodyEl = document.getElementById('digestBody');
|
||||||
|
const title = titleEl.value.trim();
|
||||||
|
const body = bodyEl.value.trim();
|
||||||
const isPinned = document.getElementById('digestPinned').checked;
|
const isPinned = document.getElementById('digestPinned').checked;
|
||||||
const postAt = inputToIso(document.getElementById('digestPostAt').value);
|
const postAt = inputToIso(document.getElementById('digestPostAt').value);
|
||||||
const hideAt = inputToIso(document.getElementById('digestHideAt').value);
|
const hideAt = inputToIso(document.getElementById('digestHideAt').value);
|
||||||
if (!title) { showToast('Введите заголовок', true); return null; }
|
if (!title || !body) {
|
||||||
if (!body) { showToast('Введите текст сообщения', true); return null; }
|
setInvalid(titleEl, !title);
|
||||||
|
setInvalid(bodyEl, !body);
|
||||||
|
if (!title) titleEl.focus(); else bodyEl.focus();
|
||||||
|
showToast(!title ? 'Введите заголовок' : 'Введите текст сообщения', true);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (hideAt && postAt && new Date(hideAt).getTime() <= new Date(postAt).getTime()) {
|
||||||
|
showToast('Дата скрытия должна быть позже даты публикации', true);
|
||||||
|
document.getElementById('digestHideAt').focus();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
if (saving) return null;
|
if (saving) return null;
|
||||||
const payload = { title: title, body: body, is_pinned: isPinned, preview_path: previewPath || null, post_at: postAt, hide_at: hideAt };
|
const payload = { title: title, body: body, is_pinned: isPinned, preview_path: previewPath || null, post_at: postAt, hide_at: hideAt };
|
||||||
|
const saveBtn = document.getElementById('digestSave');
|
||||||
saving = true;
|
saving = true;
|
||||||
|
saveBtn.disabled = true;
|
||||||
|
saveBtn.textContent = 'Сохранение…';
|
||||||
|
try {
|
||||||
let res;
|
let res;
|
||||||
try {
|
try {
|
||||||
if (editingId) {
|
if (editingId) {
|
||||||
@@ -343,12 +413,10 @@
|
|||||||
res = await fetch(API + '/api/digests', { method: 'POST', headers: hdrJson(), body: JSON.stringify(payload) });
|
res = await fetch(API + '/api/digests', { method: 'POST', headers: hdrJson(), body: JSON.stringify(payload) });
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
saving = false;
|
|
||||||
showToast('Ошибка сети', true);
|
showToast('Ошибка сети', true);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const data = await res.json().catch(function() { return {}; });
|
const data = await res.json().catch(function() { return {}; });
|
||||||
saving = false;
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
showToast(data.error || 'Ошибка при сохранении', true);
|
showToast(data.error || 'Ошибка при сохранении', true);
|
||||||
return null;
|
return null;
|
||||||
@@ -359,6 +427,11 @@
|
|||||||
previewFile = null;
|
previewFile = null;
|
||||||
}
|
}
|
||||||
return savedId;
|
return savedId;
|
||||||
|
} finally {
|
||||||
|
saving = false;
|
||||||
|
saveBtn.disabled = false;
|
||||||
|
saveBtn.textContent = 'Сохранить';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveDigest() {
|
async function saveDigest() {
|
||||||
@@ -404,6 +477,9 @@
|
|||||||
if (!saved) return;
|
if (!saved) return;
|
||||||
targetId = saved;
|
targetId = saved;
|
||||||
editingId = targetId;
|
editingId = targetId;
|
||||||
|
clearDraft();
|
||||||
|
document.getElementById('digestModalTitle').textContent = 'Редактирование сообщения';
|
||||||
|
showToast('Сообщение сохранено — картинка добавляется к нему');
|
||||||
document.getElementById('digestImageAdd').style.display = '';
|
document.getElementById('digestImageAdd').style.display = '';
|
||||||
document.getElementById('digestImagesWrap').style.display = '';
|
document.getElementById('digestImagesWrap').style.display = '';
|
||||||
}
|
}
|
||||||
@@ -548,7 +624,6 @@
|
|||||||
document.getElementById('digestSave').addEventListener('click', saveDigest);
|
document.getElementById('digestSave').addEventListener('click', saveDigest);
|
||||||
document.getElementById('digestPreviewFile').addEventListener('change', addPreviewFile);
|
document.getElementById('digestPreviewFile').addEventListener('change', addPreviewFile);
|
||||||
document.getElementById('digestPreviewRemove').addEventListener('click', removePreview);
|
document.getElementById('digestPreviewRemove').addEventListener('click', removePreview);
|
||||||
document.getElementById('digestImageAdd').addEventListener('click', addImages);
|
|
||||||
document.getElementById('digestImageFile').addEventListener('change', addImages);
|
document.getElementById('digestImageFile').addEventListener('change', addImages);
|
||||||
document.getElementById('digestModal').addEventListener('paste', digestPaste);
|
document.getElementById('digestModal').addEventListener('paste', digestPaste);
|
||||||
const draftTitle = document.getElementById('digestTitle');
|
const draftTitle = document.getElementById('digestTitle');
|
||||||
@@ -556,7 +631,11 @@
|
|||||||
const draftPinned = document.getElementById('digestPinned');
|
const draftPinned = document.getElementById('digestPinned');
|
||||||
const draftPostAt = document.getElementById('digestPostAt');
|
const draftPostAt = document.getElementById('digestPostAt');
|
||||||
const draftHideAt = document.getElementById('digestHideAt');
|
const draftHideAt = document.getElementById('digestHideAt');
|
||||||
[draftTitle, draftBody].forEach(el => el && el.addEventListener('input', persistDraft));
|
[draftTitle, draftBody].forEach(el => el && el.addEventListener('input', function() {
|
||||||
|
persistDraft();
|
||||||
|
updateCounts();
|
||||||
|
setInvalid(el, false);
|
||||||
|
}));
|
||||||
[draftPinned, draftPostAt, draftHideAt].forEach(el => el && el.addEventListener('change', persistDraft));
|
[draftPinned, draftPostAt, draftHideAt].forEach(el => el && el.addEventListener('change', persistDraft));
|
||||||
document.getElementById('digestImagesWrap').addEventListener('click', function(e) {
|
document.getElementById('digestImagesWrap').addEventListener('click', function(e) {
|
||||||
const btn = e.target.closest('[data-action="del-image"]');
|
const btn = e.target.closest('[data-action="del-image"]');
|
||||||
@@ -568,12 +647,20 @@
|
|||||||
document.addEventListener('keydown', function(e) {
|
document.addEventListener('keydown', function(e) {
|
||||||
const m = document.getElementById('digestModal');
|
const m = document.getElementById('digestModal');
|
||||||
const open = m && m.classList.contains('open');
|
const open = m && m.classList.contains('open');
|
||||||
if (e.key === 'Escape' && open) closeDigestModal();
|
if (!open) return;
|
||||||
|
if (e.key === 'Escape') { closeDigestModal(); return; }
|
||||||
|
if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) {
|
||||||
|
e.preventDefault();
|
||||||
|
const tag = document.activeElement && document.activeElement.tagName;
|
||||||
|
if (tag !== 'INPUT' || document.activeElement.type !== 'file') saveDigest();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function bindPage() {
|
function bindPage() {
|
||||||
document.getElementById('digestNewBtn').addEventListener('click', function() { openDigestModal(null); });
|
document.getElementById('digestNewBtn').addEventListener('click', function() { openDigestModal(null); });
|
||||||
|
const search = document.getElementById('digestSearch');
|
||||||
|
if (search) search.addEventListener('input', function() { query = search.value; renderDigests(); });
|
||||||
document.addEventListener('click', async function(e) {
|
document.addEventListener('click', async function(e) {
|
||||||
const actEl = e.target.closest('[data-action]');
|
const actEl = e.target.closest('[data-action]');
|
||||||
if (actEl) {
|
if (actEl) {
|
||||||
@@ -586,6 +673,18 @@
|
|||||||
}
|
}
|
||||||
if (action === 'delete') { await removeDigest(id); return; }
|
if (action === 'delete') { await removeDigest(id); return; }
|
||||||
if (action === 'pin') { await togglePin(id, actEl.dataset.pin === '1'); return; }
|
if (action === 'pin') { await togglePin(id, actEl.dataset.pin === '1'); return; }
|
||||||
|
if (action === 'toggle-body') {
|
||||||
|
const card = actEl.closest('.digest-card');
|
||||||
|
if (card) {
|
||||||
|
const body = card.querySelector('.digest-body');
|
||||||
|
if (body) {
|
||||||
|
const clamped = body.classList.toggle('clamp');
|
||||||
|
actEl.textContent = clamped ? 'Показать полностью' : 'Свернуть';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (action === 'reload') { await loadDigests(); return; }
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -611,7 +710,7 @@
|
|||||||
const mine = currentUser && d.author_id === currentUser.id;
|
const mine = currentUser && d.author_id === currentUser.id;
|
||||||
if (admin || mine) openDigestModal(d);
|
if (admin || mine) openDigestModal(d);
|
||||||
else {
|
else {
|
||||||
const card = document.querySelector('[data-id="' + id + '"]');
|
const card = document.querySelector('[data-page="digest"] .digest-card[data-id="' + id + '"]');
|
||||||
if (card) { card.scrollIntoView({ behavior: 'smooth', block: 'center' }); card.classList.add('digest-highlight'); setTimeout(function() { card.classList.remove('digest-highlight'); }, 1500); }
|
if (card) { card.scrollIntoView({ behavior: 'smooth', block: 'center' }); card.classList.add('digest-highlight'); setTimeout(function() { card.classList.remove('digest-highlight'); }, 1500); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -362,6 +362,7 @@ const NOTIFY_TYPES = {
|
|||||||
'lesson.report': { label: 'Отчёт о занятии', hint: 'Тьютор сохранил отчёт о том, что прошли на занятии', icon: 'notebook-pen', level: 'info', enabled: true, admin: false },
|
'lesson.report': { label: 'Отчёт о занятии', hint: 'Тьютор сохранил отчёт о том, что прошли на занятии', icon: 'notebook-pen', level: 'info', enabled: true, admin: false },
|
||||||
'lesson.ai.formatted': { label: 'Отчёт оформлен по шаблону', hint: 'ИИ привёл текст отчёта о занятии к деловому виду', icon: 'file-check', level: 'info', enabled: false, admin: false },
|
'lesson.ai.formatted': { label: 'Отчёт оформлен по шаблону', hint: 'ИИ привёл текст отчёта о занятии к деловому виду', icon: 'file-check', level: 'info', enabled: false, admin: false },
|
||||||
'feedback.ai.ready': { label: 'Отзыв сгенерирован', hint: 'ИИ сформировал отзыв по результатам занятия', icon: 'message-square-heart', level: 'info', enabled: true, admin: false },
|
'feedback.ai.ready': { label: 'Отзыв сгенерирован', hint: 'ИИ сформировал отзыв по результатам занятия', icon: 'message-square-heart', level: 'info', enabled: true, admin: false },
|
||||||
|
'feedback.ai.error': { label: 'Ошибка генерации отзыва', hint: 'ИИ не смог обработать отзыв после всех попыток', icon: 'message-square-x', level: 'warning', enabled: true, admin: false },
|
||||||
'face.scan.done': { label: 'Найдены лица на фото', hint: 'Фоновая проверка нашла лица на загруженном фото. Сколько именно — в тексте уведомления', icon: 'scan-face', level: 'info', enabled: false, admin: false },
|
'face.scan.done': { label: 'Найдены лица на фото', hint: 'Фоновая проверка нашла лица на загруженном фото. Сколько именно — в тексте уведомления', icon: 'scan-face', level: 'info', enabled: false, admin: false },
|
||||||
'face.recognized': { label: 'Ученики распознаны на фото', hint: 'Фоновая проверка сопоставила лица с эталонами и назвала учеников', icon: 'user-round-check', level: 'info', enabled: true, admin: false },
|
'face.recognized': { label: 'Ученики распознаны на фото', hint: 'Фоновая проверка сопоставила лица с эталонами и назвала учеников', icon: 'user-round-check', level: 'info', enabled: true, admin: false },
|
||||||
'face.scan.error': { label: 'Ошибка проверки лиц', hint: 'Сервис face-id недоступен или очередь проверки исчерпала попытки', icon: 'scan-search', level: 'warning', enabled: true, admin: false },
|
'face.scan.error': { label: 'Ошибка проверки лиц', hint: 'Сервис face-id недоступен или очередь проверки исчерпала попытки', icon: 'scan-search', level: 'warning', enabled: true, admin: false },
|
||||||
@@ -6966,8 +6967,26 @@ async function onFeedbackDone({ row, status, text, aiText, error }) {
|
|||||||
}).catch(() => {});
|
}).catch(() => {});
|
||||||
if (status === 'done') {
|
if (status === 'done') {
|
||||||
try {
|
try {
|
||||||
const branchId = row.branch_id ?? null;
|
await pushNotification({
|
||||||
pushNotification('feedback.ai.ready', { id: row.id, resident: row.resident }, branchId).catch(() => {});
|
type: 'feedback.ai.ready',
|
||||||
|
title: `Отзыв сгенерирован: ${row.resident || row.group_name || 'занятие'}`,
|
||||||
|
body: String(text || aiText || '').slice(0, 300),
|
||||||
|
link: 'feedback.html',
|
||||||
|
target: { feedback_id: row.id, resident: row.resident || null },
|
||||||
|
branchId: row.branch_id,
|
||||||
|
});
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
if (status === 'error') {
|
||||||
|
try {
|
||||||
|
await pushNotification({
|
||||||
|
type: 'feedback.ai.error',
|
||||||
|
title: `Не удалось сгенерировать отзыв: ${row.resident || row.group_name || 'занятие'}`,
|
||||||
|
body: String(error || 'Ошибка обработки').slice(0, 300),
|
||||||
|
link: 'feedback.html',
|
||||||
|
target: { feedback_id: row.id, resident: row.resident || null },
|
||||||
|
branchId: row.branch_id,
|
||||||
|
});
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user