feat(exam9): link tasks to textbook + difficulty-ordered random + topic exclusion

Practice (random) now picks tasks by ascending difficulty so the first
slot is always level 1 and the session ramps up. Adds ?exclude= to drop
specific subtopics from the random pool, with a per-section checkbox
modal in the UI.

Each task carries a topic_ref (textbook chapter + paragraph) shown as
a 'Учить тему · §N' button next to the solution, deep-linking to the
right section of /textbook/<slug>. Mapping seeded for all 15 math9
subtopics in migration 028.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Maxim Dolgolyov
2026-05-29 14:55:47 +03:00
parent 441321c598
commit 3cc52e21b0
5 changed files with 386 additions and 9 deletions
+103 -1
View File
@@ -15,6 +15,8 @@
let batch = null; // { strategy, session_id, tasks: [...] }
let strategy = readStrategyFromUrl() || readPersistedStrategy() || 'random';
let count = readPersistedCount();
let excludeSlugs = readPersistedExclude(); // Set<slug>
let topicSections = null; // { sections: [...] } — lazy-loaded
let finalized = false;
const results = new Map(); // taskId -> { isCorrect: 0|1|null, attempts: number }
@@ -39,6 +41,17 @@
function persistCount(n) {
try { localStorage.setItem(`exam_prep_${examKey}_practice_count`, String(n)); } catch {}
}
function readPersistedExclude() {
try {
const raw = localStorage.getItem(`exam_prep_${examKey}_practice_exclude`) || '';
return new Set(raw.split(',').filter(Boolean));
} catch { return new Set(); }
}
function persistExclude(set) {
try {
localStorage.setItem(`exam_prep_${examKey}_practice_exclude`, Array.from(set).join(','));
} catch {}
}
/* ── Boot: show controls and load first batch ───────────────── */
await loadBatch();
@@ -47,6 +60,11 @@
function controlsHTML() {
const opts = [5, 10, 15, 20].map(n => `
<option value="${n}" ${n === count ? 'selected' : ''}>${n} задач</option>`).join('');
const excludeBadge = excludeSlugs.size
? `<span class="pr-exclude-count">${excludeSlugs.size}</span>` : '';
// Exclude only applies to the difficulty-ordered random pool. Hide
// for other strategies so users don't think it filters them too.
const showExclude = strategy === 'random';
return `
<div class="pr-controls">
<div class="pr-controls-row">
@@ -66,10 +84,19 @@
<label>Размер сессии:</label>
<select class="pr-count-select">${opts}</select>
</div>
${showExclude ? `
<button class="ep-btn pr-exclude-btn" title="Исключить темы из пула случайных задач">
<i data-lucide="filter-x"></i> Исключить темы ${excludeBadge}
</button>` : ''}
<button class="ep-btn ep-btn-primary pr-restart">
<i data-lucide="rotate-cw"></i> Новая сессия
</button>
</div>
${strategy === 'random' ? `
<div class="pr-difficulty-note">
<i data-lucide="bar-chart-2"></i>
Задачи идут по возрастанию сложности: 1-я всегда лёгкая, к концу — сложнее.
</div>` : ''}
<div class="pr-progress" id="pr-progress"></div>
</div>`;
}
@@ -102,7 +129,11 @@
wireControls();
try {
batch = await EP.api.getPracticeNext(examKey, { count, strategy });
const query = { count, strategy };
if (strategy === 'random' && excludeSlugs.size) {
query.exclude = Array.from(excludeSlugs).join(',');
}
batch = await EP.api.getPracticeNext(examKey, query);
} catch (e) {
main.querySelector('.ep-empty').outerHTML = `
<div class="ep-empty">
@@ -234,6 +265,77 @@
}
const restart = main.querySelector('.pr-restart');
if (restart) restart.onclick = () => loadBatch();
const excludeBtn = main.querySelector('.pr-exclude-btn');
if (excludeBtn) excludeBtn.onclick = () => openExcludeModal();
}
/* ── Exclude-topics modal ───────────────────────────────────── */
async function openExcludeModal() {
if (!topicSections) {
try {
topicSections = await EP.api.listTopics(examKey);
} catch (e) {
LS.toast?.('Не удалось загрузить темы', 'error');
return;
}
}
const sections = topicSections.sections || [];
const sectionsHtml = sections.map(sec => {
const items = (sec.subtopics || []).map(st => {
const checked = excludeSlugs.has(st.slug) ? 'checked' : '';
return `
<label class="pr-ex-item">
<input type="checkbox" value="${st.slug}" ${checked} />
<span class="pr-ex-title">${escapeHtml(st.title)}</span>
<span class="pr-ex-meta">${st.total || 0} задач</span>
</label>`;
}).join('');
return `
<div class="pr-ex-section">
<div class="pr-ex-section-head">
<span>${escapeHtml(sec.title)}</span>
<button type="button" class="pr-ex-toggle-all" data-section="${sec.slug}">Все</button>
</div>
<div class="pr-ex-items" data-section-items="${sec.slug}">${items}</div>
</div>`;
}).join('');
const body = `
<div class="pr-ex-form">
<p class="pr-ex-hint">Отмеченные темы не попадут в случайный пул. Сложность распределения сохраняется.</p>
${sectionsHtml || '<div class="pr-ex-empty">Темы не настроены</div>'}
</div>`;
const m = LS.modal({
title: 'Исключить темы из пула',
content: body,
size: 'md',
actions: [
{ label: 'Сбросить', onClick: () => {
m.body.querySelectorAll('input[type="checkbox"]').forEach(c => c.checked = false);
} },
{ label: 'Отмена', onClick: () => m.close() },
{ label: 'Применить', primary: true, onClick: () => {
const checked = Array.from(m.body.querySelectorAll('input[type="checkbox"]:checked')).map(c => c.value);
excludeSlugs = new Set(checked);
persistExclude(excludeSlugs);
m.close();
loadBatch();
} },
],
});
// "Все" toggle per section
m.body.querySelectorAll('.pr-ex-toggle-all').forEach(btn => {
btn.onclick = () => {
const items = m.body.querySelector(`[data-section-items="${btn.dataset.section}"]`);
if (!items) return;
const boxes = items.querySelectorAll('input[type="checkbox"]');
const allChecked = Array.from(boxes).every(b => b.checked);
boxes.forEach(b => b.checked = !allChecked);
};
});
}
function escapeHtml(s) {