feat(lessons): «Мои материалы» — ученик сохраняет материалы урока к себе

Ученик на странице «Мои уроки» может сохранить к себе страницу доски (PNG) и свою заметку
из прошлой онлайн-сессии. Копия хранится у ученика и переживает удаление сессии учителем.

- Миграция 060: student_materials (kind board/note/link/image, denormalized source_title,
  source_session_id ON DELETE SET NULL).
- API /api/materials (GET/POST/DELETE, авторизация + проверка владельца) + helpers в js/api.js.
- my-lessons.html: кнопки «К себе» на доске и заметке (Whiteboard.exportBlob → /api/files → saveMaterial).
- Новая страница /my-materials (просмотр/открыть/скачать/удалить) + пункт сайдбара (ученик).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Maxim Dolgolyov
2026-06-04 11:33:01 +03:00
parent 6be8a505eb
commit 44ab5e045e
9 changed files with 305 additions and 1 deletions
+53 -1
View File
@@ -585,6 +585,10 @@
<span>Загрузка доски...</span>
</div>
<div class="lh-board-export">
<button class="lh-export-btn" onclick="saveBoardToMaterials(this)" title="Сохранить страницу в «Мои материалы»">
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"/><polyline points="17 21 17 13 7 13 7 21"/><polyline points="7 3 7 8 15 8"/></svg>
К себе
</button>
<button class="lh-export-btn" onclick="exportBoardPage()">
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
PNG
@@ -1023,6 +1027,51 @@ function lhZoom(delta) {
function lhZoomFit() { if (_wb) _wb.zoomFitStrokes(); }
function exportBoardPage() { if (_wb) _wb.exportPNG(); }
/* ─── Сохранить материалы урока к себе («Мои материалы») ─── */
let _myNoteText = '';
function _matSource() {
const s = _activeSession && _activeSession.session;
return { sourceSessionId: s ? s.id : null, sourceTitle: s ? (s.title || 'Урок') : null };
}
async function saveBoardToMaterials(btn) {
if (!_wb) { LS.toast('Откройте страницу доски', 'warn'); return; }
if (btn) btn.disabled = true;
try {
const blob = await new Promise(res => _wb.exportBlob(res));
if (!blob) throw new Error('Не удалось сделать снимок страницы');
const fd = new FormData();
fd.append('file', blob, 'board-p' + (_wbCurrentPage || 1) + '.png');
const up = await LS.uploadFile(fd);
const src = _matSource();
await LS.saveMaterial({
kind: 'board',
title: (src.sourceTitle || 'Доска') + ' · стр. ' + (_wbCurrentPage || 1),
url: LS.downloadFileUrl(up.id),
sourceSessionId: src.sourceSessionId, sourceTitle: src.sourceTitle,
});
LS.toast('Страница сохранена в «Мои материалы»', 'success');
} catch (e) {
LS.toast(e.message || 'Ошибка сохранения', 'error');
} finally { if (btn) btn.disabled = false; }
}
async function saveNoteToMaterials(btn) {
const text = (_myNoteText || '').trim();
if (!text) { LS.toast('Заметка пустая', 'warn'); return; }
if (btn) btn.disabled = true;
try {
const src = _matSource();
await LS.saveMaterial({
kind: 'note',
title: 'Заметка · ' + (src.sourceTitle || 'Урок'),
body: text,
sourceSessionId: src.sourceSessionId, sourceTitle: src.sourceTitle,
});
LS.toast('Заметка сохранена в «Мои материалы»', 'success');
} catch (e) {
LS.toast(e.message || 'Ошибка сохранения', 'error');
} finally { if (btn) btn.disabled = false; }
}
/* ─── Chat ─── */
async function loadChat() {
_chatLoaded = true;
@@ -1073,12 +1122,15 @@ async function loadNotes() {
try {
const data = await LS.get(`/api/classroom/${sessionId}/notes`);
const content = data.content || '';
_myNoteText = content;
if (!content.trim()) {
container.innerHTML = `<div class="ml-empty"><p>Вы не оставили заметок к этому уроку</p></div>`;
return;
}
container.innerHTML = `<div class="lh-own-note-box">
<div class="lh-own-note-lbl">Мои заметки</div>
<div class="lh-own-note-lbl">Мои заметки
<button class="lh-export-btn" style="float:right" onclick="saveNoteToMaterials(this)" title="Сохранить в «Мои материалы»">К себе</button>
</div>
<div class="lh-note-text">${LS.escapeHtml(content)}</div>
</div>`;
} catch {