Тесты и опросы: генерация ИИ, критерии оценки, версия 2.0
- ИИ-генерация черновиков тестов (lib/quiz-ai.js, quiz-ai-jobs, quiz-ai.selftest.js) - Критерии оценки (quiz_grade_scales/quiz_grade_ranges, lib/quiz-grades.js, public/js/grade-scales.js) - Версия 2.0 формата бэкапа, добавление таблиц тестов в BACKUP_TABLES - Обновление AGENTS.md под новый функционал тестов/опросов
This commit is contained in:
+61
-9
@@ -1,6 +1,6 @@
|
||||
(function () {
|
||||
const quizId = parseInt(new URLSearchParams(location.search).get('id'), 10);
|
||||
const state = { quiz: null, assets: [], questions: [] };
|
||||
const state = { quiz: null, assets: [], questions: [], gradeScales: [] };
|
||||
let dirty = false;
|
||||
let saving = false;
|
||||
let dragState = null;
|
||||
@@ -68,6 +68,8 @@
|
||||
shuffle_questions: quiz.shuffle_questions === true,
|
||||
shuffle_options: quiz.shuffle_options === true,
|
||||
show_results: quiz.show_results !== false,
|
||||
show_answers: quiz.show_answers !== false,
|
||||
grade_scale_id: quiz.grade_scale_id == null ? '' : quiz.grade_scale_id,
|
||||
allow_anonymous: quiz.allow_anonymous === true,
|
||||
max_attempts: quiz.max_attempts == null ? '' : quiz.max_attempts,
|
||||
time_limit_min: quiz.time_limit_min || 0,
|
||||
@@ -109,6 +111,8 @@
|
||||
shuffle_questions: q.shuffle_questions,
|
||||
shuffle_options: q.shuffle_options,
|
||||
show_results: q.show_results,
|
||||
show_answers: q.show_answers,
|
||||
grade_scale_id: q.grade_scale_id === '' ? null : q.grade_scale_id,
|
||||
allow_anonymous: q.allow_anonymous,
|
||||
max_attempts: q.max_attempts === '' ? null : q.max_attempts,
|
||||
time_limit_min: q.time_limit_min === '' ? 0 : q.time_limit_min,
|
||||
@@ -301,18 +305,23 @@
|
||||
function renderAnon() {
|
||||
const wrap = document.getElementById('qeAnonWrap');
|
||||
if (!wrap) return;
|
||||
const isSurvey = state.quiz.kind === 'survey';
|
||||
wrap.hidden = !isSurvey;
|
||||
if (!isSurvey) return;
|
||||
wrap.hidden = false;
|
||||
const isTest = state.quiz.kind === 'test';
|
||||
document.getElementById('qeAnonymous').checked = state.quiz.allow_anonymous;
|
||||
const link = document.getElementById('qeAnonLink');
|
||||
const hint = document.getElementById('qeAnonPublishHint');
|
||||
const desc = document.getElementById('qeAnonDesc');
|
||||
if (desc) {
|
||||
desc.textContent = isTest
|
||||
? 'По ссылке можно пройти тест без входа в систему. Перед началом ученик может указать имя; если оставить пустым, результат будет анонимным.'
|
||||
: 'По ссылке можно пройти опрос без входа в систему. Ответы сохраняются без имени.';
|
||||
}
|
||||
const ready = state.quiz.allow_anonymous && state.quiz.is_published;
|
||||
const visible = ready && !dirty;
|
||||
link.hidden = !visible;
|
||||
let text = '';
|
||||
if (state.quiz.allow_anonymous && !state.quiz.is_published) text = 'Опубликуйте опрос, чтобы ссылка заработала.';
|
||||
else if (ready && dirty) text = 'Сохраните опрос, чтобы ссылка заработала.';
|
||||
if (state.quiz.allow_anonymous && !state.quiz.is_published) text = 'Опубликуйте, чтобы ссылка заработала.';
|
||||
else if (ready && dirty) text = 'Сохраните изменения, чтобы ссылка заработала.';
|
||||
hint.hidden = !text;
|
||||
hint.textContent = text;
|
||||
if (visible) {
|
||||
@@ -322,6 +331,33 @@
|
||||
}
|
||||
}
|
||||
|
||||
function renderGradeSelect() {
|
||||
const sel = document.getElementById('qeGradeScale');
|
||||
if (!sel) return;
|
||||
const current = state.quiz.grade_scale_id === '' || state.quiz.grade_scale_id == null
|
||||
? ''
|
||||
: String(state.quiz.grade_scale_id);
|
||||
let known = current === '';
|
||||
const opts = ['<option value="">Без градации</option>'];
|
||||
for (const s of state.gradeScales) {
|
||||
if (String(s.id) === current) known = true;
|
||||
opts.push(`<option value="${s.id}">${at(s.name)}</option>`);
|
||||
}
|
||||
if (!known) opts.push(`<option value="${at(current)}">Критерий не найден</option>`);
|
||||
sel.innerHTML = opts.join('');
|
||||
sel.value = current;
|
||||
}
|
||||
|
||||
async function loadGradeScales() {
|
||||
try {
|
||||
const res = await fetch(API + '/api/grade-scales', { headers: hdr() });
|
||||
const data = await res.json().catch(() => ({}));
|
||||
state.gradeScales = res.ok && Array.isArray(data.items) ? data.items : [];
|
||||
} catch (e) {
|
||||
state.gradeScales = [];
|
||||
}
|
||||
}
|
||||
|
||||
function renderSide() {
|
||||
const q = state.quiz;
|
||||
document.getElementById('qeName').value = q.title;
|
||||
@@ -333,15 +369,26 @@
|
||||
document.getElementById('qeShuffleQ').checked = q.shuffle_questions;
|
||||
document.getElementById('qeShuffleO').checked = q.shuffle_options;
|
||||
document.getElementById('qeShowResults').checked = q.show_results;
|
||||
document.getElementById('qeShowAnswers').checked = q.show_answers;
|
||||
document.getElementById('qeShowAnswersWrap').hidden = q.kind !== 'test';
|
||||
document.getElementById('qeGradeWrap').hidden = q.kind !== 'test';
|
||||
renderGradeSelect();
|
||||
document.querySelectorAll('#qeKindSeg .qe-seg-btn').forEach(b => {
|
||||
b.classList.toggle('on', b.dataset.kind === q.kind);
|
||||
});
|
||||
document.getElementById('qePassWrap').hidden = q.kind !== 'test';
|
||||
document.getElementById('qeBarTitle').textContent = q.title || 'Без названия';
|
||||
document.getElementById('qePreviewBtn').href = 'quiz.html?id=' + q.id;
|
||||
const previewBtn = document.getElementById('qePreviewBtn');
|
||||
if (previewBtn) previewBtn.href = 'quiz.html?id=' + q.id;
|
||||
renderCover();
|
||||
renderQuizAssets();
|
||||
renderAnon();
|
||||
if (location.hash === '#public') {
|
||||
const wrap = document.getElementById('qeAnonWrap');
|
||||
if (wrap) wrap.scrollIntoView({ block: 'center', behavior: 'smooth' });
|
||||
const url = document.getElementById('qeAnonUrl');
|
||||
if (url && !document.getElementById('qeAnonLink').hidden) url.focus();
|
||||
}
|
||||
}
|
||||
|
||||
function renderAll() {
|
||||
@@ -740,13 +787,14 @@
|
||||
state.quiz.time_limit_min = e.target.value === '' ? 0 : Number(e.target.value);
|
||||
markDirty();
|
||||
});
|
||||
['qePublished', 'qeShuffleQ', 'qeShuffleO', 'qeShowResults', 'qeAnonymous'].forEach(id => {
|
||||
['qePublished', 'qeShuffleQ', 'qeShuffleO', 'qeShowResults', 'qeShowAnswers', 'qeAnonymous'].forEach(id => {
|
||||
document.getElementById(id).addEventListener('change', e => {
|
||||
const map = {
|
||||
qePublished: 'is_published',
|
||||
qeShuffleQ: 'shuffle_questions',
|
||||
qeShuffleO: 'shuffle_options',
|
||||
qeShowResults: 'show_results',
|
||||
qeShowAnswers: 'show_answers',
|
||||
qeAnonymous: 'allow_anonymous',
|
||||
};
|
||||
state.quiz[map[id]] = e.target.checked;
|
||||
@@ -754,12 +802,15 @@
|
||||
if (id === 'qePublished' || id === 'qeAnonymous') renderAnon();
|
||||
});
|
||||
});
|
||||
document.getElementById('qeGradeScale').addEventListener('change', e => {
|
||||
state.quiz.grade_scale_id = e.target.value === '' ? '' : Number(e.target.value);
|
||||
markDirty();
|
||||
});
|
||||
document.getElementById('qeKindSeg').addEventListener('click', e => {
|
||||
const btn = e.target.closest('[data-kind]');
|
||||
if (!btn) return;
|
||||
if (state.quiz.kind === btn.dataset.kind) return;
|
||||
state.quiz.kind = btn.dataset.kind;
|
||||
if (state.quiz.kind !== 'survey') state.quiz.allow_anonymous = false;
|
||||
markDirty();
|
||||
renderSide();
|
||||
renderQuestions();
|
||||
@@ -832,6 +883,7 @@
|
||||
if (!(await checkAuth())) return;
|
||||
buildSidebar(document.body.dataset.page);
|
||||
bind();
|
||||
await loadGradeScales();
|
||||
await load();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user