Дорабоки интерфейса системы тестирования. Раздел 1 Шапка+Верхний brick

This commit is contained in:
Константин Лебединский
2026-04-29 14:55:43 +05:00
parent 1c4dacbc85
commit eff3fda5b0
34 changed files with 3339 additions and 576 deletions
+656 -5
View File
@@ -1,17 +1,668 @@
/* Точечные стили поверх Tailwind CDN.
В E1.0 файл почти пустой — задаёт только сглаживание иконок и базовый focus-ring,
чтобы кнопки/ссылки были консистентны со стилем кабинета HR. */
/* Базовые токены и точечные стили в духе webapp-nginx/cabinet-theme. */
:root {
--surface: #ffffff;
--surface-container-low: #f3f8f9;
--surface-container: #eaf3f5;
--on-surface: #0d1b1d;
--on-surface-variant: #3d5357;
--primary: #007168;
--primary-hover: #00645b;
--outline-variant: #b9bc94;
--shadow-card: 0 8px 40px rgba(0, 0, 0, 0.08);
--radius-card: 2rem;
--max-content: 42rem;
}
*,
*::before,
*::after {
box-sizing: border-box;
}
body {
margin: 0;
min-height: 100dvh;
font-family: 'Inter', system-ui, -apple-system, sans-serif;
background: var(--surface-container-low);
color: var(--on-surface);
-webkit-tap-highlight-color: transparent;
line-height: 1.45;
}
h1,
h2,
h3 {
letter-spacing: -0.02em;
}
.material-symbols-outlined {
font-family: 'Material Symbols Outlined', sans-serif;
font-weight: normal;
font-style: normal;
line-height: 1;
letter-spacing: normal;
text-transform: none;
display: inline-block;
white-space: nowrap;
word-wrap: normal;
font-variation-settings:
'FILL' 0,
'wght' 400,
'GRAD' 0,
'opsz' 20;
'opsz' 24;
direction: ltr;
-webkit-font-feature-settings: 'liga';
font-feature-settings: 'liga';
-webkit-font-smoothing: antialiased;
}
:focus-visible {
outline: 2px solid #6366f1; /* brand-500 */
outline: 2px solid var(--primary);
outline-offset: 2px;
border-radius: 6px;
}
/* Небольшой "cabinet" акцент карточек/кнопок без переписывания шаблонов. */
.rounded-2xl.bg-white,
.rounded-xl.bg-white {
border-color: color-mix(in srgb, var(--outline-variant) 38%, transparent);
}
.bg-brand-600 {
background-color: var(--primary) !important;
}
.hover\:bg-brand-700:hover {
background-color: var(--primary-hover) !important;
}
/* ------------------------------------------------------------------ */
/* UI variants (оба режима на Flask, отличие только в компоновке UI). */
/* ------------------------------------------------------------------ */
/* Modern: плотная колонка и акцент на карточный контент. */
body.ui-modern .max-w-2xl {
max-width: 42rem !important;
}
body.ui-modern main {
padding-top: 1.25rem;
}
/* Legacy: идентичный cabinet layout. */
body.ui-legacy .max-w-2xl {
max-width: 42rem !important;
}
body.ui-legacy .cabinet-app {
min-height: 100dvh;
display: flex;
flex-direction: column;
background: var(--surface);
}
body.ui-legacy .cabinet-header {
position: sticky;
top: 0;
z-index: 20;
background: color-mix(in srgb, var(--surface) 88%, transparent);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
border-bottom: 1px solid color-mix(in srgb, var(--outline-variant) 35%, transparent);
}
body.ui-legacy .cabinet-header__inner {
max-width: var(--max-content);
margin: 0 auto;
padding-top: max(0.75rem, env(safe-area-inset-top, 0px));
padding-bottom: 0.75rem;
padding-left: max(1.25rem, env(safe-area-inset-left, 0px) + 0.5rem);
padding-right: max(1.25rem, env(safe-area-inset-right, 0px) + 0.5rem);
display: flex;
align-items: center;
justify-content: space-between;
gap: 1rem;
}
body.ui-legacy .cabinet-brand {
display: flex;
align-items: center;
gap: 0.65rem;
color: var(--on-surface);
text-decoration: none;
min-width: 0;
}
body.ui-legacy .cabinet-brand:hover {
text-decoration: none;
color: var(--on-surface);
}
body.ui-legacy .cabinet-brand__logo {
width: 2rem;
height: 2rem;
object-fit: contain;
display: block;
}
body.ui-legacy .login-logo__img {
width: 96px;
height: 96px;
object-fit: contain;
display: block;
margin: 0 auto 0.5rem;
}
body.ui-legacy .cabinet-brand__icon {
font-size: 1.75rem;
color: var(--primary);
background: var(--surface-container-low);
border-radius: 0.75rem;
padding: 0.35rem;
border: 1px solid color-mix(in srgb, var(--outline-variant) 30%, transparent);
flex-shrink: 0;
}
body.ui-legacy .cabinet-brand__title {
font-family: 'Manrope', 'Inter', sans-serif;
font-weight: 800;
font-size: 1rem;
line-height: 1.2;
letter-spacing: -0.02em;
}
body.ui-legacy .cabinet-header__actions {
display: flex;
align-items: center;
gap: 0.75rem;
flex-shrink: 0;
}
body.ui-legacy .cabinet-user {
font-size: 0.8rem;
color: var(--on-surface-variant);
text-align: right;
max-width: 12rem;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
display: none;
}
@media (min-width: 480px) {
body.ui-legacy .cabinet-user {
display: inline;
}
}
body.ui-legacy .cabinet-user__role {
color: var(--secondary, #506965);
font-weight: 500;
}
body.ui-legacy .cabinet-main {
flex: 1;
max-width: var(--max-content);
width: 100%;
margin: 0 auto;
padding: 1.25rem 1.25rem calc(2.5rem + env(safe-area-inset-bottom, 0px));
}
body.ui-legacy main {
padding-top: 0;
}
body.ui-legacy .rounded-2xl.bg-white,
body.ui-legacy .rounded-xl.bg-white {
border-radius: 0.85rem;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
/* Legacy catalog (портировано из старого webapp) */
body.ui-legacy .legacy-list-shell {
max-width: 42rem;
margin: 0 auto;
}
body.ui-legacy .legacy-list-title {
font-size: 1.5rem;
margin: 0 0 0.75rem;
}
body.ui-legacy .legacy-list-toolbar {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
margin: 0 0 1rem;
}
body.ui-legacy .legacy-list-subtitle {
font-size: 1.1rem;
margin: 1.5rem 0 0.5rem;
}
body.ui-legacy .btn {
font-family: inherit;
font-size: 0.9375rem;
font-weight: 600;
padding: 0.55rem 1.1rem;
border-radius: 0.75rem;
border: 1.5px solid transparent;
cursor: pointer;
transition: background 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
text-decoration: none;
}
body.ui-legacy .btn-ghost {
background: transparent;
color: var(--primary);
border-color: color-mix(in srgb, var(--outline-variant) 70%, transparent);
}
body.ui-legacy .btn-ghost:hover {
background: var(--surface-container);
border-color: var(--primary);
text-decoration: none;
}
body.ui-legacy .text-muted {
color: var(--on-surface-variant);
font-size: 0.875rem;
}
body.ui-legacy .list-stack {
list-style: none;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
gap: 0.5rem;
}
body.ui-legacy .list-row {
display: block;
border: 1px solid color-mix(in srgb, var(--outline-variant) 30%, transparent);
border-radius: 1rem;
padding: 0.9rem 1rem;
background: var(--surface);
transition: border-color 0.15s, box-shadow 0.15s;
}
body.ui-legacy .list-row--split {
display: flex;
flex-direction: row;
align-items: stretch;
padding: 0;
overflow: hidden;
gap: 0;
}
body.ui-legacy .list-row__main {
display: flex;
flex-direction: column;
flex: 1;
min-width: 0;
}
body.ui-legacy .list-row__link {
display: flex;
flex-direction: column;
flex: 1 1 auto;
padding: 0.9rem 1rem;
text-decoration: none;
color: inherit;
}
body.ui-legacy .list-row__title {
display: block;
color: var(--on-surface);
font-weight: 600;
}
body.ui-legacy .list-row__meta {
color: var(--on-surface-variant);
font-size: 0.8rem;
display: block;
margin-top: 0.25rem;
}
body.ui-legacy .list-row__meta-tail {
white-space: nowrap;
}
body.ui-legacy .list-row__side {
display: flex;
align-items: center;
padding: 0.5rem 0.9rem 0.5rem 0;
flex-shrink: 0;
border-left: 1px solid color-mix(in srgb, var(--outline-variant) 35%, transparent);
}
body.ui-legacy .list-row--hidden {
border-style: dashed;
opacity: 0.95;
}
body.ui-legacy .link-back {
display: inline-flex;
align-items: center;
gap: 0.25rem;
font-size: 0.9rem;
font-weight: 500;
margin: 0 0 1rem;
}
body.ui-legacy .callout {
border-radius: 1rem;
padding: 0.75rem 1rem;
font-size: 0.9rem;
font-weight: 500;
margin: 0 0 1rem;
}
body.ui-legacy .callout--warning {
background: #fffbeb;
border: 1px solid #fde68a;
color: #92400e;
}
body.ui-legacy .muted,
body.ui-legacy .text-muted,
body.ui-legacy .text-secondary {
color: #506965;
font-size: 0.875rem;
}
body.ui-legacy .mono {
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
body.ui-legacy .form-label {
display: block;
font-size: 0.9rem;
font-weight: 500;
color: var(--on-surface);
margin-bottom: 0.35rem;
}
body.ui-legacy .form-input {
width: 100%;
padding: 11px 13px;
border: 1.5px solid var(--outline-variant);
border-radius: 0.75rem;
font-size: 15px;
font-family: inherit;
outline: none;
background: var(--surface-container-low);
color: var(--on-surface);
transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
body.ui-legacy .form-input:focus {
border-color: var(--primary);
box-shadow: 0 0 0 3px rgba(0, 113, 104, 0.12);
background: #fff;
}
body.ui-legacy .surface-card {
background: var(--surface);
border: 1px solid color-mix(in srgb, var(--outline-variant) 30%, transparent);
border-radius: 1rem;
padding: 1rem 1.1rem;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
body.ui-legacy .cabinet-brick {
margin-bottom: 1.1rem;
}
body.ui-legacy .cabinet-brick--hero {
padding: 0.1rem 0 0.6rem;
border-bottom: 1px solid color-mix(in srgb, var(--outline-variant) 45%, transparent);
margin-bottom: 1.25rem;
}
.hero-brick__nav {
display: flex;
justify-content: space-between;
align-items: baseline;
flex-wrap: wrap;
gap: 0.5rem;
font-size: 0.85rem;
color: var(--ink-500, #6b7280);
}
.hero-brick__meta {
display: inline-flex;
flex-wrap: wrap;
gap: 0.4rem;
align-items: baseline;
color: var(--ink-500, #6b7280);
}
.hero-brick__sep { opacity: 0.55; }
.hero-brick__title {
display: block;
width: 100%;
margin-top: 0.5rem;
border: 1px solid transparent;
background: transparent;
font-size: 1.65rem;
line-height: 1.2;
font-weight: 700;
padding: 0.3rem 0.4rem;
border-radius: 0.5rem;
outline: none;
resize: none;
overflow: hidden;
white-space: pre-wrap;
word-break: break-word;
font-family: inherit;
min-height: 2.4rem;
}
.hero-brick__title:hover { border-color: color-mix(in srgb, var(--outline-variant) 50%, transparent); }
.hero-brick__title:focus { border-color: var(--primary, #0d9488); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary, #0d9488) 18%, transparent); background: #fff; }
.hero-brick__desc {
display: block;
width: 100%;
margin-top: 0.35rem;
border: 1px solid transparent;
background: transparent;
font-size: 0.95rem;
color: var(--ink-700, #374151);
padding: 0.3rem 0.4rem;
border-radius: 0.5rem;
resize: none;
overflow: hidden;
outline: none;
font-family: inherit;
}
.hero-brick__desc:hover { border-color: color-mix(in srgb, var(--outline-variant) 50%, transparent); }
.hero-brick__desc:focus { border-color: var(--primary, #0d9488); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary, #0d9488) 18%, transparent); background: #fff; }
.hero-brick__chips {
margin-top: 0.65rem;
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
align-items: center;
}
.hero-brick__chip {
display: inline-flex;
align-items: center;
gap: 0.35rem;
padding: 0.25rem 0.55rem;
background: color-mix(in srgb, var(--surface, #fff) 80%, var(--outline-variant, #e5e7eb));
border: 1px solid color-mix(in srgb, var(--outline-variant, #e5e7eb) 70%, transparent);
border-radius: 999px;
font-size: 0.85rem;
color: var(--ink-700, #374151);
cursor: pointer;
}
.hero-brick__chip--readonly { cursor: default; }
.hero-brick__chip input[type="number"] {
width: 3.2rem;
border: none;
background: transparent;
text-align: right;
font: inherit;
outline: none;
padding: 0;
}
.hero-brick__chip input[type="checkbox"] { accent-color: var(--primary, #0d9488); }
body.ui-legacy .cabinet-disclosure {
border: 1px solid color-mix(in srgb, var(--outline-variant) 30%, transparent);
border-radius: 1rem;
background: var(--surface);
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
body.ui-legacy .cabinet-disclosure__summary {
cursor: pointer;
list-style: none;
user-select: none;
padding: 0.85rem 1rem 0.75rem;
font-size: 1.05rem;
border-radius: 1rem 1rem 0 0;
min-height: 2.75rem;
display: flex;
align-items: center;
gap: 0.5rem;
}
body.ui-legacy .cabinet-disclosure__summary::-webkit-details-marker { display: none; }
body.ui-legacy .cabinet-disclosure__summary::after {
content: 'expand_more';
font-family: 'Material Symbols Outlined', sans-serif;
margin-left: auto;
font-size: 1.25rem;
opacity: 0.55;
transition: transform 0.2s ease;
}
body.ui-legacy .cabinet-disclosure[open] .cabinet-disclosure__summary::after {
transform: rotate(180deg);
}
body.ui-legacy .cabinet-disclosure__summary-text {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 0.15rem;
min-width: 0;
}
body.ui-legacy .cabinet-disclosure__summary-title {
font-size: 1.05rem;
line-height: 1.25;
}
body.ui-legacy .cabinet-disclosure__summary-sub {
display: block;
font-size: 0.8rem;
font-weight: 400;
line-height: 1.3;
color: #506965;
}
body.ui-legacy .cabinet-disclosure__body {
padding: 0.7rem 1rem 1.05rem;
border-top: 1px solid color-mix(in srgb, var(--outline-variant) 35%, transparent);
}
body.ui-legacy .test-detail-subsection {
margin-top: 1.25rem;
padding-top: 1.15rem;
border-top: 1px solid color-mix(in srgb, var(--outline-variant) 32%, transparent);
}
body.ui-legacy .test-detail-subsection--tight {
margin-top: 0;
padding-top: 0;
border-top: none;
}
body.ui-legacy .test-detail-subsection__title {
margin: 0 0 0.35rem;
font-size: 0.95rem;
font-weight: 600;
}
body.ui-legacy .test-detail-hint {
margin: 0 0 0.6rem;
font-size: 0.8rem;
line-height: 1.4;
color: #506965;
}
body.ui-legacy .test-detail-ai-panel {
padding: 0.9rem 1rem;
margin-bottom: 1.15rem;
background: var(--surface-container-low);
border: 1px solid color-mix(in srgb, var(--outline-variant) 32%, transparent);
border-radius: 0.85rem;
box-shadow: none;
}
body.ui-legacy .assign-toolbar {
display: flex;
flex-direction: column;
gap: 0.5rem;
margin-bottom: 0.65rem;
}
@media (min-width: 520px) {
body.ui-legacy .assign-toolbar {
flex-direction: row;
flex-wrap: wrap;
align-items: center;
}
}
body.ui-legacy .assign-toolbar__search {
flex: 1 1 200px;
}
body.ui-legacy .assign-list {
max-height: min(40vh, 18rem);
overflow: auto;
border: 1px solid color-mix(in srgb, var(--outline-variant) 30%, transparent);
border-radius: 0.75rem;
background: var(--surface-container-low);
}
body.ui-legacy .assign-row {
display: flex;
gap: 0.5rem;
padding: 0.65rem 0.75rem;
border-bottom: 1px solid color-mix(in srgb, var(--outline-variant) 40%, transparent);
cursor: pointer;
align-items: center;
}
body.ui-legacy .assign-row:last-child { border-bottom: none; }
body.ui-legacy .assign-row--selected,
body.ui-legacy .assign-row:hover { background: color-mix(in srgb, var(--primary) 8%, transparent); }
body.ui-legacy .assign-row__text {
display: flex;
flex-direction: column;
gap: 0.2rem;
min-width: 0;
flex: 1;
}
body.ui-legacy .assign-row__fio { font-weight: 600; font-size: 0.95rem; }
body.ui-legacy .assign-row__login { font-size: 0.8rem; color: #506965; font-family: ui-monospace, Menlo, monospace; }
body.ui-legacy .assign-row__meta { font-size: 0.8rem; color: #506965; line-height: 1.35; }
body.ui-legacy .version-card-list,
body.ui-legacy .attempts-card-list {
list-style: none;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
gap: 0.5rem;
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

+324 -15
View File
@@ -25,14 +25,74 @@
const saveStatusEl = $('#save-status');
const aiStatusEl = $('#ai-status');
const chainActiveEl = $('#chain-active');
const aiTopicEl = $('#ai-topic');
const aiQCountEl = $('#ai-q-count');
const aiOCountEl = $('#ai-o-count');
const introUpdatedEl = $('#intro-updated');
const introForkBannerEl = $('#intro-fork-banner');
const versionsListEl = $('#versions-list');
const attemptsListEl = $('#attempts-list');
const visibilityBtn = $('#btn-toggle-visibility');
const assignSearchEl = $('#assign-search');
const assignDeptEl = $('#assign-dept');
const assignClinicEl = $('#assign-clinic');
const assignListEl = $('#assign-list');
const assignSelectAllBtn = $('#assign-select-all');
const assignSubmitBtn = $('#assign-submit');
const assignStatusEl = $('#assign-status');
const tplQ = $('#tpl-question');
const tplO = $('#tpl-option');
let chainActive = true;
let assignPeople = [];
let assignSelected = new Set();
let hasAnyAttempts = false;
let hasForkRisk = Boolean(initial?.test?.hasForkRisk)
|| (introForkBannerEl && introForkBannerEl.dataset.forkRisk === '1');
let baselineDraftKey = '';
let dirtyCheckQueued = false;
function currentDraftKey() {
return JSON.stringify(collectPayload());
}
function isDirty() {
return baselineDraftKey !== '' && baselineDraftKey !== currentDraftKey();
}
function updateForkBanner() {
if (!introForkBannerEl) return;
introForkBannerEl.style.display = (hasForkRisk && isDirty()) ? '' : 'none';
}
function scheduleDirtyCheck() {
if (dirtyCheckQueued) return;
dirtyCheckQueued = true;
requestAnimationFrame(() => {
dirtyCheckQueued = false;
updateForkBanner();
});
}
function resetBaselineDraft() {
baselineDraftKey = currentDraftKey();
updateForkBanner();
}
// ─── render ─────────────────────────────────────────────────────────
function syncOptionInputTypes(qNode) {
const isMulti = $('.q-multi', qNode).checked;
const qName = `q-correct-${Math.random().toString(36).slice(2)}`;
$$('.opt-correct', qNode).forEach((input) => {
input.type = isMulti ? 'checkbox' : 'radio';
if (isMulti) input.removeAttribute('name');
else input.setAttribute('name', qName);
input.classList.add('question-option-row__mark');
});
}
function renderQuestion(q) {
const node = tplQ.content.firstElementChild.cloneNode(true);
node._q = { id: q.id || null };
@@ -43,6 +103,7 @@
(q.options || []).forEach((o) => optsEl.appendChild(renderOption(o)));
bindQuestionEvents(node);
syncOptionInputTypes(node);
return node;
}
@@ -61,41 +122,86 @@
if (!confirm('Удалить вопрос?')) return;
node.remove();
renumber();
scheduleDirtyCheck();
});
$('.q-up', node).addEventListener('click', () => {
if (node.previousElementSibling) {
node.parentNode.insertBefore(node, node.previousElementSibling);
renumber();
scheduleDirtyCheck();
}
});
$('.q-down', node).addEventListener('click', () => {
if (node.nextElementSibling) {
node.parentNode.insertBefore(node.nextElementSibling, node);
renumber();
scheduleDirtyCheck();
}
});
$('.q-add-option', node).addEventListener('click', () => {
$('.q-options', node).appendChild(renderOption({ text: '', isCorrect: false }));
syncOptionInputTypes(node);
scheduleDirtyCheck();
});
$('.q-ai', node).addEventListener('click', () => aiGenerateQuestion(node));
$('.q-multi', node).addEventListener('change', () => {
syncOptionInputTypes(node);
scheduleDirtyCheck();
});
}
function renumber() {
$$('#questions .q-item').forEach((li, i) => {
$('.q-num', li).textContent = `Вопрос #${i + 1}`;
});
qCountEl.textContent = $$('#questions .q-item').length;
const n = $$('#questions .q-item').length;
if (qCountEl) qCountEl.textContent = n;
const mirror = document.getElementById('q-count-mirror');
if (mirror) mirror.textContent = n;
}
function autoResize(el) {
if (!el) return;
el.style.height = 'auto';
el.style.height = el.scrollHeight + 'px';
}
function loadInitial() {
titleEl.value = initial.test.title || '';
descEl.value = initial.test.description || '';
autoResize(titleEl);
autoResize(descEl);
if (titleEl && titleEl.tagName === 'TEXTAREA') {
titleEl.addEventListener('input', () => autoResize(titleEl));
titleEl.addEventListener('keydown', (e) => {
if (e.key === 'Enter') e.preventDefault();
});
}
if (descEl) descEl.addEventListener('input', () => autoResize(descEl));
thresholdEl.value =
initial.test.passingThreshold == null ? '' : Number(initial.test.passingThreshold);
questionsEl.innerHTML = '';
(initial.questions || []).forEach((q) => questionsEl.appendChild(renderQuestion(q)));
renumber();
if (aiTopicEl && !aiTopicEl.value.trim()) {
aiTopicEl.value = initial.test.title || '';
}
}
function fmtDt(iso) {
if (!iso) return '—';
try {
return new Date(iso).toLocaleString('ru-RU', { dateStyle: 'short', timeStyle: 'short' });
} catch {
return '—';
}
}
function escHtml(s) {
return String(s == null ? '' : s)
.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
.replace(/"/g, '&quot;').replace(/'/g, '&#39;');
}
// ─── collect ───────────────────────────────────────────────────────
@@ -144,6 +250,7 @@
}),
);
renumber();
scheduleDirtyCheck();
});
$('#save-draft').addEventListener('click', async () => {
@@ -167,6 +274,7 @@
saveStatusEl.textContent = data.forked
? 'Сохранено (создана новая версия — есть попытки прохождения).'
: 'Сохранено.';
resetBaselineDraft();
setTimeout(() => (saveStatusEl.textContent = ''), 4000);
} catch (e) {
saveStatusEl.textContent = '';
@@ -175,18 +283,24 @@
});
$('#ai-generate-test').addEventListener('click', async () => {
const shape = collectShape();
if (!shape.length) {
alert('Сначала добавьте хотя бы один вопрос (его настройки определяют сетку).');
const topic = (aiTopicEl?.value || titleEl.value || '').trim();
if (!topic) {
alert('Укажите тему.');
return;
}
const nQ = Math.min(30, Math.max(1, Number(aiQCountEl?.value || 7) || 7));
const nO = Math.min(8, Math.max(2, Number(aiOCountEl?.value || 3) || 3));
const shape = Array.from({ length: nQ }, () => ({
optionsCount: nO,
hasMultipleAnswers: false,
}));
aiStatusEl.textContent = 'Генерируем…';
try {
const r = await fetch(`/api/tests/${TEST_ID}/ai/generate-test`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
testTitle: titleEl.value,
testTitle: topic,
testDescription: descEl.value,
shape,
}),
@@ -194,11 +308,15 @@
const data = await r.json();
if (!r.ok) throw new Error(data.error || 'AI: ошибка.');
const draft = data.draft;
if (draft.title) titleEl.value = draft.title;
if (draft.title) {
titleEl.value = draft.title;
if (aiTopicEl) aiTopicEl.value = draft.title;
}
if (draft.description) descEl.value = draft.description;
questionsEl.innerHTML = '';
(draft.questions || []).forEach((q) => questionsEl.appendChild(renderQuestion(q)));
renumber();
scheduleDirtyCheck();
aiStatusEl.textContent = `Готово: ${draft.questions?.length || 0} вопросов.`;
setTimeout(() => (aiStatusEl.textContent = ''), 4000);
} catch (e) {
@@ -242,6 +360,7 @@
questionsEl.innerHTML = '';
(draft.questions || []).forEach((q) => questionsEl.appendChild(renderQuestion(q)));
renumber();
scheduleDirtyCheck();
aiStatusEl.textContent = `Применено: ${draft.questions?.length || 0} вопросов.`;
setTimeout(() => (aiStatusEl.textContent = ''), 4000);
} catch (e) {
@@ -263,12 +382,6 @@
alert(msg);
}
function escHtml(s) {
return String(s == null ? '' : s)
.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
.replace(/"/g, '&quot;').replace(/'/g, '&#39;');
}
const modal = $('#ai-modal');
const modalTitle = $('#ai-modal-title');
const modalBody = $('#ai-modal-body');
@@ -290,7 +403,8 @@
modal.showModal();
}
$('#ai-generate-by-title').addEventListener('click', async () => {
const aiGenerateByTitleBtn = $('#ai-generate-by-title');
if (aiGenerateByTitleBtn) aiGenerateByTitleBtn.addEventListener('click', async () => {
const title = titleEl.value.trim();
if (!title) {
alert('Сначала заполните название теста.');
@@ -334,6 +448,7 @@
questionsEl.innerHTML = '';
(draft.questions || []).forEach((q) => questionsEl.appendChild(renderQuestion(q)));
renumber();
scheduleDirtyCheck();
aiStatusEl.textContent = `Применено: ${draft.questions.length} вопросов.`;
setTimeout(() => (aiStatusEl.textContent = ''), 4000);
} catch (e) {
@@ -342,7 +457,8 @@
}
});
$('#ai-check').addEventListener('click', async () => {
const aiCheckBtn = $('#ai-check');
if (aiCheckBtn) aiCheckBtn.addEventListener('click', async () => {
const payload = collectPayload();
if (!payload.questions.length) {
alert('В тесте нет вопросов — нечего проверять.');
@@ -394,7 +510,8 @@
}
});
$('#ai-improve').addEventListener('click', async () => {
const aiImproveBtn = $('#ai-improve');
if (aiImproveBtn) aiImproveBtn.addEventListener('click', async () => {
const payload = collectPayload();
if (!payload.questions.length) {
alert('В тесте нет вопросов — нечего улучшать.');
@@ -480,6 +597,7 @@
it.suggested.options.forEach((o) => optsEl.appendChild(renderOption(o)));
});
modal.close();
scheduleDirtyCheck();
aiStatusEl.textContent = 'Изменения применены. Не забудьте сохранить.';
setTimeout(() => (aiStatusEl.textContent = ''), 5000);
},
@@ -517,6 +635,7 @@
data.options.forEach((o) => optsEl.appendChild(renderOption(o)));
$('.q-multi', node).checked = !!data.hasMultipleAnswers;
}
scheduleDirtyCheck();
aiStatusEl.textContent = data.mode === 'full' ? 'AI: вопрос сгенерирован.' : 'AI: формулировка обновлена.';
setTimeout(() => (aiStatusEl.textContent = ''), 4000);
} catch (e) {
@@ -542,5 +661,195 @@
chainActiveEl.checked = true;
});
function renderVersions(rows) {
if (!versionsListEl) return;
versionsListEl.innerHTML = '';
(rows || []).forEach((r) => {
const li = document.createElement('li');
li.className = 'surface-card version-card-list__item';
li.innerHTML = `
<div class="version-card-list__row">
<div class="version-card-list__main">
<div class="version-card-list__title-line">
<span class="font-headline" style="font-size:1rem;">v${r.version}</span>
${r.is_active ? '<span class="code-inline" style="font-size:0.7rem;">текущая</span>' : ''}
</div>
<p class="muted mono" style="margin:.4rem 0 0; font-size:.8rem;">${fmtDt(r.created_at)}</p>
<p class="muted" style="margin:.2rem 0 0; font-size:.8rem;">Активна: ${r.is_active ? 'да' : 'нет'}</p>
</div>
</div>`;
versionsListEl.appendChild(li);
});
}
function renderAttempts(rows) {
if (!attemptsListEl) return;
attemptsListEl.innerHTML = '';
(rows || []).forEach((a) => {
const when = a.completedAt ? fmtDt(a.completedAt) : (a.startedAt ? fmtDt(a.startedAt) : '—');
const result = a.status === 'completed' && a.totalQuestions != null
? `${a.correctCount}/${a.totalQuestions}${a.passed ? ' · зачёт' : ' · незачёт'}`
: a.status;
const li = document.createElement('li');
li.className = 'surface-card attempts-card-list__item';
li.innerHTML = `
<div class="attempts-card-list__row">
<div class="attempts-card-list__main">
<p class="muted mono" style="margin:0; font-size:.8rem;">${when}</p>
<p style="margin:.35rem 0 0; font-weight:600;">${escHtml(a.attempterName || '—')}
${a.attempterLogin ? `<span class="code-inline" style="font-size:11px; margin-left:6px;">${escHtml(a.attempterLogin)}</span>` : ''}
</p>
<p class="muted" style="margin:.25rem 0 0; font-size:.85rem;">v${a.testVersion} · ${escHtml(result)}</p>
</div>
${a.status === 'completed'
? `<a class="btn btn-ghost btn--sm attempts-card-list__action" href="/tests/${TEST_ID}/attempts/${a.id}/review">Разбор</a>`
: ''}
</div>`;
attemptsListEl.appendChild(li);
});
}
function renderAssignList() {
if (!assignListEl) return;
assignListEl.innerHTML = '';
assignPeople.forEach((p) => {
const row = document.createElement('label');
row.className = `assign-row${assignSelected.has(String(p.staffId)) ? ' assign-row--selected' : ''}`;
row.innerHTML = `
<input type="checkbox" ${assignSelected.has(String(p.staffId)) ? 'checked' : ''} />
<span class="assign-row__text">
<span class="assign-row__fio">${escHtml(p.fio || '—')}</span>
${p.webLogin ? `<span class="assign-row__login">${escHtml(p.webLogin)}</span>` : ''}
<span class="assign-row__meta">${escHtml(p.department || '—')}${p.clinicUserId ? ' · есть учётка' : ' · нет учётки (создадим при назначении)'}</span>
</span>`;
const cb = row.querySelector('input');
cb.addEventListener('change', () => {
const k = String(p.staffId);
if (cb.checked) assignSelected.add(k); else assignSelected.delete(k);
row.classList.toggle('assign-row--selected', cb.checked);
});
assignListEl.appendChild(row);
});
if (!assignPeople.length) assignListEl.innerHTML = '<p class="muted" style="padding:.75rem;">Никого не найдено.</p>';
}
async function loadDirectory() {
if (!assignListEl) return;
assignStatusEl.textContent = 'Загружаем…';
try {
const params = new URLSearchParams();
if (assignSearchEl.value.trim()) params.set('q', assignSearchEl.value.trim());
if (assignDeptEl.value && assignDeptEl.value !== '__all__') params.set('department', assignDeptEl.value);
params.set('clinic', assignClinicEl.value || 'all');
const r = await fetch(`/api/auth/dev/assignment-directory?${params.toString()}`);
const data = await r.json();
if (!r.ok) throw new Error(data.error || 'Не удалось загрузить сотрудников');
assignPeople = data.people || [];
const depts = data.departments || [];
if (assignDeptEl.options.length <= 1) {
depts.forEach((d) => {
const o = document.createElement('option');
o.value = d;
o.textContent = d;
assignDeptEl.appendChild(o);
});
}
assignSelected = new Set();
renderAssignList();
assignStatusEl.textContent = '';
} catch (e) {
assignStatusEl.textContent = e.message || 'Ошибка загрузки';
}
}
if (assignSearchEl) {
let t = null;
assignSearchEl.addEventListener('input', () => {
clearTimeout(t);
t = setTimeout(loadDirectory, 350);
});
assignDeptEl.addEventListener('change', loadDirectory);
assignClinicEl.addEventListener('change', loadDirectory);
assignSelectAllBtn.addEventListener('click', () => {
assignPeople.forEach((p) => assignSelected.add(String(p.staffId)));
renderAssignList();
});
assignSubmitBtn.addEventListener('click', async () => {
const selectedRows = assignPeople.filter((p) => assignSelected.has(String(p.staffId)));
const userIds = selectedRows.filter((p) => p.clinicUserId).map((p) => p.clinicUserId);
const staffIds = selectedRows.filter((p) => !p.clinicUserId && p.staffId != null).map((p) => p.staffId);
if (!userIds.length && !staffIds.length) return;
assignStatusEl.textContent = 'Назначаем…';
try {
const r = await fetch(`/api/tests/${TEST_ID}/assign`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ userIds, staffIds }),
});
const data = await r.json();
if (!r.ok) throw new Error(data.error || 'Ошибка назначения');
assignStatusEl.textContent = `Назначено: ${data.count ?? selectedRows.length}`;
} catch (e) {
assignStatusEl.textContent = e.message || 'Ошибка назначения';
}
});
loadDirectory();
}
if (visibilityBtn) {
visibilityBtn.addEventListener('click', async () => {
const next = !chainActiveEl.checked;
try {
const r = await fetch(`/api/tests/${TEST_ID}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ chainActive: next }),
});
const data = await r.json();
if (!r.ok) throw new Error(data.error || 'Ошибка изменения видимости');
chainActiveEl.checked = !!next;
chainActive = !!next;
visibilityBtn.textContent = chainActive ? 'Скрыть из списка' : 'Снова показать в списке';
} catch (e) {
alert(e.message || 'Ошибка изменения видимости');
}
});
}
Promise.all([
fetch(`/api/tests/${TEST_ID}/versions`).then((r) => r.json()).catch(() => null),
fetch(`/api/tests/${TEST_ID}/attempts`).then((r) => r.json()).catch(() => null),
fetch(`/api/tests/${TEST_ID}/summary`).then((r) => r.json()).catch(() => null),
]).then(([v, a, s]) => {
if (v && Array.isArray(v.versions)) {
renderVersions(v.versions);
hasForkRisk = hasForkRisk || (v.versions.length > 1);
if (typeof v.hasAttempts === 'boolean') {
hasAnyAttempts = hasAnyAttempts || v.hasAttempts;
hasForkRisk = hasForkRisk || v.hasAttempts;
}
}
if (a && Array.isArray(a.attempts)) {
renderAttempts(a.attempts);
hasAnyAttempts = a.attempts.length > 0;
}
if (s && s.test) {
if (introUpdatedEl) introUpdatedEl.textContent = fmtDt(s.test.updated_at || s.test.updatedAt);
const versionEl = document.getElementById('intro-version');
if (versionEl && s.test.version != null) versionEl.textContent = s.test.version;
if (typeof s.test.hasAttempts === 'boolean') {
hasAnyAttempts = hasAnyAttempts || s.test.hasAttempts;
hasForkRisk = hasForkRisk || s.test.hasAttempts;
}
if (typeof s.test.versionCount === 'number') {
hasForkRisk = hasForkRisk || s.test.versionCount > 1;
}
}
updateForkBanner();
});
loadInitial();
resetBaselineDraft();
root.addEventListener('input', scheduleDirtyCheck);
root.addEventListener('change', scheduleDirtyCheck);
})();