notes: AI titles for new notes, personal-only access, modal polish
- new note created without a title gets one generated by a background worker (createNoteTitleWorker, ai_status column, wake channel, notes_changed SSE event, settings toggle notes_ai_enabled) - notes are strictly personal: list/update/delete/reorder always scoped to req.user.id, admin no longer sees other users' notes (403) - notes modal: focus goes to the text body, random color for new notes, ctrl+enter hint, tags hint styling, empty-title 400 fix (optText) - backup/restore: user_notes.ai_status normalized and restored
This commit is contained in:
@@ -97,6 +97,11 @@ const ACTION_LABELS = {
|
||||
'feedback.update': 'Изменён отзыв',
|
||||
'feedback.ai.run': 'ИИ сформировал отзыв',
|
||||
'feedback.ai.error': 'Ошибка ИИ при формировании отзыва',
|
||||
'note.reorder': 'Изменён порядок заметок',
|
||||
'note.delete': 'Удалена заметка',
|
||||
'note.ai.title': 'ИИ придумал заголовок заметки',
|
||||
'note.ai.error': 'Ошибка ИИ при генерации заголовка заметки',
|
||||
'note.ai.retry': 'ИИ повторил генерацию заголовка заметки',
|
||||
};
|
||||
|
||||
const AUDIT_PAGE_SIZE = 50;
|
||||
|
||||
+40
-3
@@ -5,6 +5,11 @@
|
||||
let editingId = null;
|
||||
let dragId = null;
|
||||
let saving = false;
|
||||
const NOTE_COLORS = ['#2563eb', '#4f46e5', '#7c3aed', '#db2777', '#dc2626', '#ea580c', '#ca8a04', '#16a34a', '#0d9488', '#0891b2'];
|
||||
|
||||
function randomColor() {
|
||||
return NOTE_COLORS[Math.floor(Math.random() * NOTE_COLORS.length)];
|
||||
}
|
||||
|
||||
function hdr() {
|
||||
const t = sessionStorage.getItem('authToken');
|
||||
@@ -29,6 +34,12 @@
|
||||
const body = n.note
|
||||
? esc(n.note)
|
||||
: '<span class="note-empty-note">Без текста</span>';
|
||||
const generating = !n.title && (n.ai_status === 'pending' || n.ai_status === 'processing');
|
||||
const titleHtml = n.title
|
||||
? esc(n.title)
|
||||
: generating
|
||||
? '<span class="note-empty-note">Заголовок генерируется…</span>'
|
||||
: esc('Без заголовка');
|
||||
return '<div class="note-card" data-id="' + n.id + '" style="--ncolor:' + color + '">' +
|
||||
'<div class="note-card-head">' +
|
||||
'<span class="note-drag" draggable="true" title="Перетащите, чтобы изменить порядок">⠿</span>' +
|
||||
@@ -36,7 +47,7 @@
|
||||
'<input type="color" id="noteColorPicker-' + n.id + '" value="' + color + '" style="display:none">' +
|
||||
'<span class="note-color-swatch" style="background:' + color + '" title="Изменить цвет"></span>' +
|
||||
'</div>' +
|
||||
'<div class="note-card-title">' + esc(n.title || 'Без заголовка') + '</div>' +
|
||||
'<div class="note-card-title">' + titleHtml + '</div>' +
|
||||
tagsHtml +
|
||||
'</div>' +
|
||||
'<div class="note-card-note">' + body + '</div>' +
|
||||
@@ -127,14 +138,14 @@
|
||||
document.getElementById('notesTitle').value = note ? note.title : '';
|
||||
document.getElementById('notesNote').value = note ? note.note : '';
|
||||
document.getElementById('notesTags').value = note ? note.tags : '';
|
||||
const color = note && /^#[0-9a-fA-F]{6}$/.test(note.color || '') ? note.color : '#2563eb';
|
||||
const color = note && /^#[0-9a-fA-F]{6}$/.test(note.color || '') ? note.color : randomColor();
|
||||
document.getElementById('notesColor').value = color;
|
||||
document.getElementById('notesColorPreview').style.background = color;
|
||||
const row = document.getElementById('notesColorRow');
|
||||
if (row) row.style.setProperty('--ncolor', color);
|
||||
document.getElementById('notesModal').classList.add('open');
|
||||
renderIcons();
|
||||
setTimeout(() => document.getElementById('notesTitle').focus(), 50);
|
||||
setTimeout(() => document.getElementById('notesNote').focus(), 50);
|
||||
}
|
||||
|
||||
function closeModal() {
|
||||
@@ -291,6 +302,31 @@
|
||||
}
|
||||
}
|
||||
|
||||
let liveSource = null;
|
||||
let liveReconnectTimer = null;
|
||||
let liveReloadTimer = null;
|
||||
|
||||
function connectNotesLive() {
|
||||
if (liveSource) { liveSource.close(); liveSource = null; }
|
||||
const connect = () => {
|
||||
const t = sessionStorage.getItem('authToken');
|
||||
if (!t) return;
|
||||
liveSource = new EventSource(`${API}/api/events?token=${encodeURIComponent(t)}`);
|
||||
const scheduleReload = () => {
|
||||
if (liveReloadTimer) clearTimeout(liveReloadTimer);
|
||||
liveReloadTimer = setTimeout(() => { liveReloadTimer = null; loadNotes(); }, 300);
|
||||
};
|
||||
liveSource.addEventListener('notes_changed', scheduleReload);
|
||||
liveSource.onerror = () => {
|
||||
if (liveSource) { liveSource.close(); liveSource = null; }
|
||||
if (liveReconnectTimer) clearTimeout(liveReconnectTimer);
|
||||
liveReconnectTimer = setTimeout(connect, 5000);
|
||||
};
|
||||
};
|
||||
connect();
|
||||
window.addEventListener('beforeunload', () => { if (liveSource) liveSource.close(); });
|
||||
}
|
||||
|
||||
async function init() {
|
||||
if (!(await checkAuth())) return;
|
||||
buildSidebar(document.body.dataset.page);
|
||||
@@ -298,6 +334,7 @@
|
||||
bindPage();
|
||||
renderIcons();
|
||||
await loadNotes();
|
||||
connectNotesLive();
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const DIRTY_FIELDS = ['systemName', 'timezone', 'timeFormat', 'spamInterval', 'footerLeft', 'footerRight', 'aiPrompt', 'aiAutoCheck', 'lessonAiPrompt', 'lessonAiEnabled', 'shareShowMessage', 'shareShowDate', 'shareShowNames', 'shareShowPhotos', 'cookieNoticeText', 'photoResolution', 'photoQuality', 'photoEngine', 'camEnabled', 'photoAiFaceMode', 'photoAiFaceModel', 'photoAiDevicePref', 'trashPurgeDays', 'notifyEnabled', 'notifyRetentionDays'];
|
||||
const DIRTY_FIELDS = ['systemName', 'timezone', 'timeFormat', 'spamInterval', 'footerLeft', 'footerRight', 'aiPrompt', 'aiAutoCheck', 'lessonAiPrompt', 'lessonAiEnabled', 'notesAiEnabled', 'shareShowMessage', 'shareShowDate', 'shareShowNames', 'shareShowPhotos', 'cookieNoticeText', 'photoResolution', 'photoQuality', 'photoEngine', 'camEnabled', 'photoAiFaceMode', 'photoAiFaceModel', 'photoAiDevicePref', 'trashPurgeDays', 'notifyEnabled', 'notifyRetentionDays'];
|
||||
const NOTIFY_IDS = [];
|
||||
const SECTION_IDS = ['sec-system', 'sec-stack', 'sec-brand', 'sec-datetime', 'sec-antispam', 'sec-share', 'sec-ai', 'sec-lesson-ai', 'sec-backup', 'sec-trash', 'sec-form', 'sec-notify', 'sec-photo', 'sec-photo-ai', 'sec-bans'];
|
||||
const SECTION_IDS = ['sec-system', 'sec-stack', 'sec-brand', 'sec-datetime', 'sec-antispam', 'sec-share', 'sec-ai', 'sec-lesson-ai', 'sec-notes-ai', 'sec-backup', 'sec-trash', 'sec-form', 'sec-notify', 'sec-photo', 'sec-photo-ai', 'sec-bans'];
|
||||
const SPAM_MAX = 10080;
|
||||
const BAN_REASONS = {
|
||||
'honeypot': 'Антиспам-поле',
|
||||
@@ -285,6 +285,7 @@ async function loadSettings() {
|
||||
document.getElementById('aiAutoCheck').checked = s.ai_autocheck_enabled !== 'false';
|
||||
document.getElementById('lessonAiEnabled').checked = s.lesson_ai_enabled !== 'false';
|
||||
document.getElementById('lessonAiPrompt').value = s.lesson_ai_prompt || '';
|
||||
document.getElementById('notesAiEnabled').checked = s.notes_ai_enabled !== 'false';
|
||||
document.getElementById('shareShowMessage').checked = s.share_show_student_message === 'true';
|
||||
document.getElementById('shareShowDate').checked = s.share_show_entry_date === 'true';
|
||||
document.getElementById('shareShowNames').checked = s.share_show_student_names !== 'false';
|
||||
@@ -890,6 +891,7 @@ async function saveSettings() {
|
||||
ai_autocheck_enabled: document.getElementById('aiAutoCheck').checked ? 'true' : 'false',
|
||||
lesson_ai_enabled: document.getElementById('lessonAiEnabled').checked ? 'true' : 'false',
|
||||
lesson_ai_prompt: document.getElementById('lessonAiPrompt').value.trim(),
|
||||
notes_ai_enabled: document.getElementById('notesAiEnabled').checked ? 'true' : 'false',
|
||||
share_show_student_message: document.getElementById('shareShowMessage').checked ? 'true' : 'false',
|
||||
share_show_entry_date: document.getElementById('shareShowDate').checked ? 'true' : 'false',
|
||||
share_show_student_names: document.getElementById('shareShowNames').checked ? 'true' : 'false',
|
||||
|
||||
Reference in New Issue
Block a user