|
|
|
@ -519,6 +519,22 @@ |
|
|
|
return data; |
|
|
|
return data; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function refreshHintsInForm() { |
|
|
|
|
|
|
|
const r = await fetch(`/api/tests/${TEST_ID}/editor`); |
|
|
|
|
|
|
|
const data = await r.json().catch(() => ({})); |
|
|
|
|
|
|
|
if (!r.ok || !Array.isArray(data.questions)) { |
|
|
|
|
|
|
|
throw new Error(data.error || 'Не удалось обновить подсказки в форме.'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const byOrder = (data.questions || []).slice().sort( |
|
|
|
|
|
|
|
(a, b) => Number(a.questionOrder || 0) - Number(b.questionOrder || 0) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
// Надёжно подтягиваем подсказки: перерисовываем список вопросов с актуальными данными сервера.
|
|
|
|
|
|
|
|
questionsEl.innerHTML = ''; |
|
|
|
|
|
|
|
byOrder.forEach((q) => questionsEl.appendChild(renderQuestion(q))); |
|
|
|
|
|
|
|
renumber(); |
|
|
|
|
|
|
|
scheduleDirtyCheck(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ─── actions ───────────────────────────────────────────────────────
|
|
|
|
// ─── actions ───────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
|
|
$('#add-question').addEventListener('click', () => { |
|
|
|
$('#add-question').addEventListener('click', () => { |
|
|
|
@ -665,6 +681,11 @@ |
|
|
|
const hr = await fetch(`/api/tests/${TEST_ID}/ai/hints/generate`, { method: 'POST' }); |
|
|
|
const hr = await fetch(`/api/tests/${TEST_ID}/ai/hints/generate`, { method: 'POST' }); |
|
|
|
const hd = await hr.json().catch(() => ({})); |
|
|
|
const hd = await hr.json().catch(() => ({})); |
|
|
|
if (hr.ok) { |
|
|
|
if (hr.ok) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
await refreshHintsInForm(); |
|
|
|
|
|
|
|
} catch (_) { |
|
|
|
|
|
|
|
// Не блокируем успех генерации вопросов.
|
|
|
|
|
|
|
|
} |
|
|
|
const skipped = Number(hd.skipped || 0); |
|
|
|
const skipped = Number(hd.skipped || 0); |
|
|
|
aiStatusEl.textContent = skipped |
|
|
|
aiStatusEl.textContent = skipped |
|
|
|
? `Готово: вопросы + подсказки (${hd.generated}, пропущено ${skipped}).` |
|
|
|
? `Готово: вопросы + подсказки (${hd.generated}, пропущено ${skipped}).` |
|
|
|
@ -1527,6 +1548,11 @@ |
|
|
|
const r = await fetch(`/api/tests/${TEST_ID}/ai/hints/generate`, { method: 'POST' }); |
|
|
|
const r = await fetch(`/api/tests/${TEST_ID}/ai/hints/generate`, { method: 'POST' }); |
|
|
|
const data = await r.json().catch(() => ({})); |
|
|
|
const data = await r.json().catch(() => ({})); |
|
|
|
if (!r.ok) throw new Error(data.error || 'Не удалось сгенерировать подсказки.'); |
|
|
|
if (!r.ok) throw new Error(data.error || 'Не удалось сгенерировать подсказки.'); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
await refreshHintsInForm(); |
|
|
|
|
|
|
|
} catch (_) { |
|
|
|
|
|
|
|
// Статус покажем как успешный; пользователь может перезагрузить страницу.
|
|
|
|
|
|
|
|
} |
|
|
|
const skipped = Number(data.skipped || 0); |
|
|
|
const skipped = Number(data.skipped || 0); |
|
|
|
if (hintsStatusEl) { |
|
|
|
if (hintsStatusEl) { |
|
|
|
hintsStatusEl.textContent = data.failed |
|
|
|
hintsStatusEl.textContent = data.failed |
|
|
|
|