927 lines
50 KiB
React
927 lines
50 KiB
React
import { useEffect, useRef, useState } from 'react';
|
||
import { getSession } from '../../../admin/js/api.js';
|
||
import { CustomSelect } from '../../shared/ui/CustomSelect.jsx';
|
||
import { AsyncCombobox } from '../../shared/ui/AsyncCombobox.jsx';
|
||
import { ConfirmDialog } from '../../shared/ui/ConfirmDialog.jsx';
|
||
import {
|
||
confirmAbandonDirtyChanges,
|
||
createDirtyScope,
|
||
} from '../../../admin/js/dirty-state.js';
|
||
import {
|
||
LOAD_CATEGORIES,
|
||
emptyPlanForm,
|
||
loadDraft,
|
||
workloadHours,
|
||
compatibleGroups,
|
||
fetchPlans,
|
||
fetchPlanMetadata,
|
||
fetchPlan,
|
||
savePlan,
|
||
savePlanSubject,
|
||
removePlanSubject,
|
||
assignPlan,
|
||
unassignPlan,
|
||
removePlan,
|
||
fetchPlanTeachers,
|
||
} from '../study-plans-service.js';
|
||
|
||
export function StudyPlansTab() {
|
||
const [session] = useState(() => getSession());
|
||
const editable = ['ADMIN', 'EDUCATION_OFFICE'].includes(session?.role);
|
||
const [plans, setPlans] = useState([]);
|
||
const [metadata, setMetadata] = useState(null);
|
||
const [details, setDetails] = useState(null);
|
||
const [form, setForm] = useState(emptyPlanForm);
|
||
const [phase, setPhase] = useState('loading');
|
||
const [busy, setBusy] = useState(false);
|
||
const [alert, setAlert] = useState(null);
|
||
const [query, setQuery] = useState('');
|
||
const [subjectId, setSubjectId] = useState('');
|
||
const [loads, setLoads] = useState(() => loadDraft());
|
||
const [editingSubjectId, setEditingSubjectId] = useState(null);
|
||
const [semesterId, setSemesterId] = useState('');
|
||
const [groupId, setGroupId] = useState('');
|
||
const [confirm, setConfirm] = useState(null);
|
||
const draftChanges = useRef({ header: false, subject: false });
|
||
const request = useRef(0);
|
||
const dirty = useRef(null);
|
||
const mounted = useRef(false);
|
||
useEffect(() => {
|
||
mounted.current = true;
|
||
dirty.current = createDirtyScope('study-plans');
|
||
let active = true;
|
||
Promise.all([fetchPlans(), fetchPlanMetadata()])
|
||
.then(([list, refs]) => {
|
||
if (!active) return;
|
||
setPlans(list);
|
||
setMetadata(refs);
|
||
setPhase('ready');
|
||
})
|
||
.catch((error) => {
|
||
if (!active) return;
|
||
setPhase('error');
|
||
setAlert({ error: true, text: error.message });
|
||
});
|
||
return () => {
|
||
active = false;
|
||
mounted.current = false;
|
||
request.current++;
|
||
dirty.current?.dispose();
|
||
};
|
||
}, []);
|
||
function applyDetails(next) {
|
||
setDetails(next);
|
||
setForm(next ? { ...next.plan } : emptyPlanForm());
|
||
setSubjectId('');
|
||
setLoads(loadDraft());
|
||
setEditingSubjectId(null);
|
||
draftChanges.current = { header: false, subject: false };
|
||
dirty.current?.clear();
|
||
}
|
||
async function selectPlan(id) {
|
||
if (busy || !(await confirmAbandonDirtyChanges())) return;
|
||
const token = ++request.current;
|
||
setAlert(null);
|
||
if (!id) {
|
||
applyDetails(null);
|
||
return;
|
||
}
|
||
setBusy(true);
|
||
try {
|
||
const next = await fetchPlan(id);
|
||
if (token === request.current) applyDetails(next);
|
||
} catch (error) {
|
||
if (token === request.current)
|
||
setAlert({ error: true, text: error.message });
|
||
} finally {
|
||
if (token === request.current) setBusy(false);
|
||
}
|
||
}
|
||
async function run(action, success, resetSubject = false, part = null) {
|
||
if (busy) return;
|
||
if (!part && dirty.current?.isDirty()) {
|
||
if (!(await confirmAbandonDirtyChanges())) return;
|
||
applyDetails(details);
|
||
}
|
||
setBusy(true);
|
||
setAlert(null);
|
||
try {
|
||
const next = await action();
|
||
if (!mounted.current) return;
|
||
if (next?.plan) {
|
||
setDetails(next);
|
||
if (part === 'header' || !draftChanges.current.header)
|
||
setForm({ ...next.plan });
|
||
if (part === 'header') draftChanges.current.header = false;
|
||
if (resetSubject) draftChanges.current.subject = false;
|
||
if (resetSubject) {
|
||
setSubjectId('');
|
||
setEditingSubjectId(null);
|
||
setLoads(loadDraft());
|
||
}
|
||
}
|
||
const list = await fetchPlans();
|
||
if (!mounted.current) return;
|
||
setPlans(list);
|
||
setAlert({ text: success });
|
||
if (!draftChanges.current.header && !draftChanges.current.subject)
|
||
dirty.current?.clear();
|
||
} catch (error) {
|
||
if (mounted.current) setAlert({ error: true, text: error.message });
|
||
} finally {
|
||
if (mounted.current) setBusy(false);
|
||
}
|
||
}
|
||
function changeForm(key, value) {
|
||
draftChanges.current.header = true;
|
||
dirty.current?.mark();
|
||
setForm((current) => ({ ...current, [key]: value }));
|
||
}
|
||
function changeLoad(category, patch) {
|
||
draftChanges.current.subject = true;
|
||
dirty.current?.mark();
|
||
setLoads((current) =>
|
||
current.map((load) =>
|
||
load.category === category ? { ...load, ...patch } : load,
|
||
),
|
||
);
|
||
}
|
||
async function editSubject(row) {
|
||
if (!(await confirmAbandonDirtyChanges())) return;
|
||
setForm({ ...details.plan });
|
||
draftChanges.current = { header: false, subject: false };
|
||
setSubjectId(String(row.subjectId));
|
||
setEditingSubjectId(row.subjectId);
|
||
setLoads(loadDraft(row));
|
||
}
|
||
const plan = details?.plan;
|
||
const visiblePlans = plans.filter(
|
||
(p) =>
|
||
p.id === plan?.id ||
|
||
`${p.title} ${p.specialtyCode} ${p.profileName}`
|
||
.toLocaleLowerCase('ru')
|
||
.includes(query.toLocaleLowerCase('ru')),
|
||
);
|
||
const groups = compatibleGroups(metadata, plan, semesterId);
|
||
const totals = details?.subjects.reduce(
|
||
(sum, row) => ({
|
||
academic: sum.academic + row.academicHours,
|
||
workload: sum.workload + row.workloadHours,
|
||
}),
|
||
{ academic: 0, workload: 0 },
|
||
);
|
||
const contextLocked = Boolean(details?.assignments.length);
|
||
if (phase !== 'ready')
|
||
return (
|
||
<div className="card">
|
||
<h2>Учебные планы</h2>
|
||
<p role="status">
|
||
{phase === 'loading'
|
||
? 'Загрузка учебных планов…'
|
||
: alert?.text}
|
||
</p>
|
||
{phase === 'error' && (
|
||
<button
|
||
className="btn btn-md btn-secondary"
|
||
onClick={() => window.location.reload()}
|
||
>
|
||
Повторить загрузку
|
||
</button>
|
||
)}
|
||
</div>
|
||
);
|
||
return (
|
||
<section className="study-plans-workspace" aria-label="Учебные планы">
|
||
<div className="card study-plans-catalog">
|
||
<div className="study-plan-heading">
|
||
<div>
|
||
<p className="study-plan-kicker">Учебный процесс</p>
|
||
<h2>Учебные планы</h2>
|
||
<p className="muted">
|
||
Профиль → семестр → дисциплины и часы → группы
|
||
</p>
|
||
</div>
|
||
<div className="study-plan-row-actions">
|
||
{plan && (
|
||
<button
|
||
type="button"
|
||
className="btn btn-md btn-secondary"
|
||
disabled={busy}
|
||
onClick={() => void selectPlan(plan.id)}
|
||
>
|
||
Обновить
|
||
</button>
|
||
)}
|
||
{editable && (
|
||
<button
|
||
type="button"
|
||
className="btn btn-md btn-primary"
|
||
disabled={busy}
|
||
onClick={() => void selectPlan(null)}
|
||
>
|
||
Новый план
|
||
</button>
|
||
)}
|
||
</div>
|
||
</div>
|
||
<div className="study-plan-controls">
|
||
<label className="form-group">
|
||
Поиск по названию, шифру и профилю
|
||
<input
|
||
value={query}
|
||
onChange={(e) => setQuery(e.target.value)}
|
||
type="search"
|
||
placeholder="Название или шифр специальности"
|
||
/>
|
||
</label>
|
||
<label className="form-group">
|
||
Учебный план
|
||
<CustomSelect
|
||
disabled={busy}
|
||
value={plan?.id || ''}
|
||
onChange={(e) => void selectPlan(e.target.value)}
|
||
>
|
||
<option value="">Выберите план</option>
|
||
{visiblePlans.map((p) => (
|
||
<option value={p.id} key={p.id}>
|
||
{p.title} · {p.specialtyCode} ·{' '}
|
||
{p.profileName} · {p.semesterNumber} семестр
|
||
</option>
|
||
))}
|
||
</CustomSelect>
|
||
</label>
|
||
</div>
|
||
{alert && (
|
||
<p
|
||
role={alert.error ? 'alert' : 'status'}
|
||
className={`form-alert study-plan-alert ${alert.error ? 'error' : 'success'}`}
|
||
>
|
||
{alert.text}
|
||
</p>
|
||
)}
|
||
</div>
|
||
{(plan || editable) && (
|
||
<div className="card">
|
||
<div className="study-plan-heading">
|
||
<h3>{plan ? plan.title : 'Новый учебный план'}</h3>
|
||
{plan && (
|
||
<span className="badge">
|
||
{plan.specialtyCode} · {plan.profileName}
|
||
</span>
|
||
)}
|
||
</div>
|
||
<form
|
||
onSubmit={(e) => {
|
||
e.preventDefault();
|
||
void run(
|
||
() => savePlan(plan?.id, form, plan?.revision),
|
||
'Учебный план сохранён',
|
||
false,
|
||
'header',
|
||
);
|
||
}}
|
||
>
|
||
<fieldset
|
||
disabled={!editable || busy}
|
||
className="study-plan-fieldset"
|
||
>
|
||
<div className="study-plan-controls">
|
||
<label className="form-group">
|
||
Название
|
||
<input
|
||
required
|
||
maxLength={255}
|
||
value={form.title}
|
||
onChange={(e) =>
|
||
changeForm('title', e.target.value)
|
||
}
|
||
/>
|
||
</label>
|
||
<label className="form-group">
|
||
Шифр и профиль
|
||
<CustomSelect
|
||
required
|
||
disabled={contextLocked}
|
||
value={form.specialtyProfileId}
|
||
onChange={(e) =>
|
||
changeForm(
|
||
'specialtyProfileId',
|
||
e.target.value,
|
||
)
|
||
}
|
||
>
|
||
<option value="">
|
||
Выберите профиль
|
||
</option>
|
||
{metadata.profiles.map((p) => (
|
||
<option value={p.id} key={p.id}>
|
||
{p.specialtyCode} · {p.name}
|
||
</option>
|
||
))}
|
||
</CustomSelect>
|
||
</label>
|
||
<label className="form-group">
|
||
Форма обучения
|
||
<CustomSelect
|
||
required
|
||
disabled={contextLocked}
|
||
value={form.educationFormId}
|
||
onChange={(e) =>
|
||
changeForm(
|
||
'educationFormId',
|
||
e.target.value,
|
||
)
|
||
}
|
||
>
|
||
<option value="">Выберите форму</option>
|
||
{metadata.educationForms.map((f) => (
|
||
<option key={f.id} value={f.id}>
|
||
{f.name}
|
||
</option>
|
||
))}
|
||
</CustomSelect>
|
||
</label>
|
||
<label className="form-group">
|
||
Номер семестра обучения
|
||
<input
|
||
type="number"
|
||
min="1"
|
||
max="20"
|
||
required
|
||
disabled={contextLocked}
|
||
value={form.semesterNumber}
|
||
onChange={(e) =>
|
||
changeForm(
|
||
'semesterNumber',
|
||
e.target.value,
|
||
)
|
||
}
|
||
/>
|
||
</label>
|
||
</div>
|
||
{editable && (
|
||
<button
|
||
className="btn btn-md btn-primary"
|
||
type="submit"
|
||
>
|
||
{plan ? 'Сохранить план' : 'Создать план'}
|
||
</button>
|
||
)}
|
||
</fieldset>
|
||
</form>
|
||
{contextLocked && (
|
||
<p className="muted">
|
||
Профиль, форма и номер семестра закреплённого плана
|
||
защищены от изменения.
|
||
</p>
|
||
)}
|
||
{plan && editable && !contextLocked && (
|
||
<button
|
||
disabled={busy}
|
||
type="button"
|
||
className="btn btn-md btn-danger study-plan-delete"
|
||
onClick={() =>
|
||
setConfirm({
|
||
text: `Удалить план «${plan.title}» вместе с дисциплинами?`,
|
||
action: async () => {
|
||
await removePlan(
|
||
plan.id,
|
||
plan.revision,
|
||
);
|
||
applyDetails(null);
|
||
},
|
||
})
|
||
}
|
||
>
|
||
Удалить план
|
||
</button>
|
||
)}
|
||
</div>
|
||
)}
|
||
{plan && (
|
||
<>
|
||
<div className="card">
|
||
<div className="study-plan-heading">
|
||
<div>
|
||
<h3>Дисциплины и часы</h3>
|
||
<p className="muted">
|
||
Академические часы. Одна пара — 2 часа. Для
|
||
лабораторных в двух подгруппах нагрузка ×2.
|
||
</p>
|
||
</div>
|
||
<div className="study-plan-totals">
|
||
<span>
|
||
<strong>{totals.academic}</strong> учебных
|
||
часов
|
||
</span>
|
||
<span>
|
||
<strong>{totals.workload}</strong> часов
|
||
нагрузки
|
||
</span>
|
||
</div>
|
||
</div>
|
||
<div className="table-wrap">
|
||
<table className="study-plan-table">
|
||
<thead>
|
||
<tr>
|
||
<th>Дисциплина</th>
|
||
{LOAD_CATEGORIES.map((c) => (
|
||
<th key={c.key}>{c.label}</th>
|
||
))}
|
||
<th>Учебные часы</th>
|
||
<th>Нагрузка</th>
|
||
{editable && <th>Действия</th>}
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{!details.subjects.length && (
|
||
<tr>
|
||
<td
|
||
colSpan={editable ? 7 : 6}
|
||
className="loading-row"
|
||
>
|
||
Добавьте первую дисциплину в
|
||
план
|
||
</td>
|
||
</tr>
|
||
)}
|
||
{details.subjects.map((row) => (
|
||
<tr key={row.subjectId}>
|
||
<td>
|
||
<strong>{row.name}</strong>
|
||
<div className="muted">
|
||
{row.code}
|
||
</div>
|
||
</td>
|
||
{LOAD_CATEGORIES.map((c) => {
|
||
const load = row.loads.find(
|
||
(l) => l.category === c.key,
|
||
);
|
||
return (
|
||
<td key={c.key}>
|
||
{load?.academicHours ||
|
||
'—'}
|
||
{load?.splitSubgroups && (
|
||
<span className="badge">
|
||
2 подгруппы ·{' '}
|
||
{
|
||
load.workloadHours
|
||
}{' '}
|
||
ч нагрузки
|
||
</span>
|
||
)}
|
||
<div className="muted">
|
||
{load?.academicHours >
|
||
0
|
||
? load.teacherName ||
|
||
'Преподаватель не назначен'
|
||
: ''}
|
||
</div>
|
||
</td>
|
||
);
|
||
})}
|
||
<td>{row.academicHours}</td>
|
||
<td>
|
||
<strong>
|
||
{row.workloadHours}
|
||
</strong>
|
||
</td>
|
||
{editable && (
|
||
<td>
|
||
<div className="study-plan-row-actions">
|
||
<button
|
||
type="button"
|
||
disabled={busy}
|
||
className="btn btn-sm btn-secondary"
|
||
onClick={() =>
|
||
void editSubject(
|
||
row,
|
||
)
|
||
}
|
||
>
|
||
Изменить
|
||
</button>
|
||
<button
|
||
type="button"
|
||
disabled={busy}
|
||
className="btn btn-sm btn-danger"
|
||
onClick={() =>
|
||
setConfirm({
|
||
text: `Удалить дисциплину «${row.name}» из плана?`,
|
||
action: () =>
|
||
removePlanSubject(
|
||
plan.id,
|
||
row.subjectId,
|
||
plan.revision,
|
||
),
|
||
})
|
||
}
|
||
>
|
||
Удалить
|
||
</button>
|
||
</div>
|
||
</td>
|
||
)}
|
||
</tr>
|
||
))}
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
{editable && (
|
||
<form
|
||
className="study-plan-subject-editor"
|
||
onSubmit={(e) => {
|
||
e.preventDefault();
|
||
void run(
|
||
() =>
|
||
savePlanSubject(
|
||
plan.id,
|
||
subjectId,
|
||
loads,
|
||
plan.revision,
|
||
),
|
||
'Дисциплина и нагрузка сохранены',
|
||
true,
|
||
'subject',
|
||
);
|
||
}}
|
||
>
|
||
<fieldset
|
||
className="study-plan-fieldset"
|
||
disabled={busy}
|
||
>
|
||
<h4>
|
||
{editingSubjectId
|
||
? 'Изменение дисциплины'
|
||
: 'Добавление дисциплины'}
|
||
</h4>
|
||
<label className="form-group">
|
||
Дисциплина
|
||
<CustomSelect
|
||
required
|
||
disabled={Boolean(editingSubjectId)}
|
||
value={subjectId}
|
||
onChange={(e) => {
|
||
draftChanges.current.subject = true;
|
||
dirty.current?.mark();
|
||
setSubjectId(e.target.value);
|
||
setLoads(loadDraft());
|
||
}}
|
||
>
|
||
<option value="">
|
||
Выберите дисциплину
|
||
</option>
|
||
{metadata.subjects
|
||
.filter(
|
||
(s) =>
|
||
s.id ===
|
||
editingSubjectId ||
|
||
!details.subjects.some(
|
||
(row) =>
|
||
row.subjectId ===
|
||
s.id,
|
||
),
|
||
)
|
||
.map((s) => (
|
||
<option
|
||
value={s.id}
|
||
key={s.id}
|
||
>
|
||
{s.code
|
||
? `${s.code} · `
|
||
: ''}
|
||
{s.name}
|
||
</option>
|
||
))}
|
||
</CustomSelect>
|
||
</label>
|
||
<div className="study-plan-load-grid">
|
||
{LOAD_CATEGORIES.map((c) => {
|
||
const load = loads.find(
|
||
(l) => l.category === c.key,
|
||
);
|
||
return (
|
||
<div
|
||
className="study-plan-load-card"
|
||
key={c.key}
|
||
>
|
||
<h4>{c.label}</h4>
|
||
<label className="form-group">
|
||
Учебные часы
|
||
<input
|
||
type="number"
|
||
min="0"
|
||
max="100000"
|
||
step="2"
|
||
required
|
||
value={
|
||
load.academicHours
|
||
}
|
||
onChange={(e) =>
|
||
changeLoad(
|
||
c.key,
|
||
{
|
||
academicHours:
|
||
e
|
||
.target
|
||
.value,
|
||
...(Number(
|
||
e
|
||
.target
|
||
.value,
|
||
) === 0
|
||
? {
|
||
teacherId:
|
||
null,
|
||
teacherName:
|
||
'',
|
||
splitSubgroups: false,
|
||
}
|
||
: {}),
|
||
},
|
||
)
|
||
}
|
||
/>
|
||
</label>
|
||
{c.key === 'LABORATORY' && (
|
||
<label className="study-plan-check checkbox-item">
|
||
<input
|
||
type="checkbox"
|
||
disabled={
|
||
!Number(
|
||
load.academicHours,
|
||
)
|
||
}
|
||
checked={
|
||
load.splitSubgroups
|
||
}
|
||
onChange={(e) =>
|
||
changeLoad(
|
||
c.key,
|
||
{
|
||
splitSubgroups:
|
||
e
|
||
.target
|
||
.checked,
|
||
},
|
||
)
|
||
}
|
||
/>
|
||
<span
|
||
className="checkmark"
|
||
aria-hidden="true"
|
||
/>
|
||
<span>
|
||
Делить на две
|
||
подгруппы
|
||
</span>
|
||
</label>
|
||
)}
|
||
<p className="study-plan-load-total">
|
||
Нагрузка:{' '}
|
||
<strong>
|
||
{workloadHours(
|
||
load,
|
||
)}{' '}
|
||
ч
|
||
</strong>
|
||
</p>
|
||
<fieldset
|
||
disabled={
|
||
!subjectId ||
|
||
!Number(
|
||
load.academicHours,
|
||
) ||
|
||
busy
|
||
}
|
||
className="study-plan-fieldset"
|
||
>
|
||
<label className="form-group">
|
||
Преподаватель
|
||
<AsyncCombobox
|
||
key={`${plan.id}-${subjectId}-${c.key}`}
|
||
ariaLabel={`Преподаватель: ${c.label}`}
|
||
placeholder="Можно назначить позднее"
|
||
optionLabel={(
|
||
t,
|
||
) =>
|
||
t.fullName ||
|
||
t.username
|
||
}
|
||
load={(q) =>
|
||
subjectId
|
||
? fetchPlanTeachers(
|
||
subjectId,
|
||
q,
|
||
)
|
||
: Promise.resolve(
|
||
[],
|
||
)
|
||
}
|
||
selectedValue={
|
||
load.teacherId ||
|
||
''
|
||
}
|
||
selectedLabel={
|
||
load.teacherName
|
||
}
|
||
onSelect={(t) =>
|
||
changeLoad(
|
||
c.key,
|
||
{
|
||
teacherId:
|
||
t?.id ||
|
||
null,
|
||
teacherName:
|
||
t
|
||
? t.fullName ||
|
||
t.username
|
||
: '',
|
||
},
|
||
)
|
||
}
|
||
/>
|
||
</label>
|
||
</fieldset>
|
||
</div>
|
||
);
|
||
})}
|
||
</div>
|
||
<div className="study-plan-row-actions">
|
||
<button
|
||
type="submit"
|
||
className="btn btn-md btn-primary"
|
||
disabled={!subjectId}
|
||
>
|
||
Сохранить дисциплину
|
||
</button>
|
||
<button
|
||
type="button"
|
||
className="btn btn-md btn-secondary"
|
||
onClick={async () => {
|
||
if (
|
||
await confirmAbandonDirtyChanges()
|
||
) {
|
||
applyDetails(details);
|
||
}
|
||
}}
|
||
>
|
||
Очистить форму
|
||
</button>
|
||
</div>
|
||
</fieldset>
|
||
</form>
|
||
)}
|
||
</div>
|
||
<div className="card">
|
||
<h3>Закрепление за группами</h3>
|
||
<p className="muted">
|
||
На один календарный семестр группе назначается один
|
||
план её профиля и формы обучения.
|
||
</p>
|
||
<div className="table-wrap">
|
||
<table>
|
||
<thead>
|
||
<tr>
|
||
<th>Группа</th>
|
||
<th>Календарный семестр</th>
|
||
{editable && <th>Действия</th>}
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{!details.assignments.length && (
|
||
<tr>
|
||
<td
|
||
colSpan={editable ? 3 : 2}
|
||
className="loading-row"
|
||
>
|
||
План пока не закреплён
|
||
</td>
|
||
</tr>
|
||
)}
|
||
{details.assignments.map((a) => (
|
||
<tr
|
||
key={`${a.groupId}-${a.semesterId}`}
|
||
>
|
||
<td>{a.groupName}</td>
|
||
<td>{a.semesterTitle}</td>
|
||
{editable && (
|
||
<td>
|
||
<button
|
||
disabled={busy}
|
||
className="btn btn-sm btn-danger"
|
||
type="button"
|
||
onClick={() =>
|
||
setConfirm({
|
||
text: `Снять закрепление плана за группой ${a.groupName} (${a.semesterTitle})?`,
|
||
action: () =>
|
||
unassignPlan(
|
||
plan.id,
|
||
a.groupId,
|
||
a.semesterId,
|
||
),
|
||
})
|
||
}
|
||
>
|
||
Снять закрепление
|
||
</button>
|
||
</td>
|
||
)}
|
||
</tr>
|
||
))}
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
{editable && (
|
||
<form
|
||
onSubmit={(e) => {
|
||
e.preventDefault();
|
||
void run(
|
||
() =>
|
||
assignPlan(
|
||
plan.id,
|
||
groupId,
|
||
semesterId,
|
||
),
|
||
'План закреплён за группой',
|
||
);
|
||
}}
|
||
>
|
||
<fieldset
|
||
className="study-plan-fieldset study-plan-controls"
|
||
disabled={busy}
|
||
>
|
||
<label className="form-group">
|
||
Календарный семестр
|
||
<CustomSelect
|
||
required
|
||
value={semesterId}
|
||
onChange={(e) => {
|
||
setSemesterId(e.target.value);
|
||
setGroupId('');
|
||
}}
|
||
>
|
||
<option value="">
|
||
Выберите семестр
|
||
</option>
|
||
{metadata.semesters.map((s) => (
|
||
<option key={s.id} value={s.id}>
|
||
{s.name}
|
||
</option>
|
||
))}
|
||
</CustomSelect>
|
||
</label>
|
||
<label className="form-group">
|
||
Совместимая группа
|
||
<CustomSelect
|
||
required
|
||
value={groupId}
|
||
onChange={(e) =>
|
||
setGroupId(e.target.value)
|
||
}
|
||
>
|
||
<option value="">
|
||
{semesterId && !groups.length
|
||
? 'Нет групп этого профиля и семестра'
|
||
: 'Выберите группу'}
|
||
</option>
|
||
{groups.map((g) => (
|
||
<option key={g.id} value={g.id}>
|
||
{g.name}
|
||
</option>
|
||
))}
|
||
</CustomSelect>
|
||
</label>
|
||
<button
|
||
type="submit"
|
||
className="btn btn-md btn-primary"
|
||
disabled={
|
||
!groupId || !details.subjects.length
|
||
}
|
||
>
|
||
Закрепить план
|
||
</button>
|
||
</fieldset>
|
||
</form>
|
||
)}
|
||
</div>
|
||
</>
|
||
)}
|
||
{confirm && (
|
||
<ConfirmDialog
|
||
title="Подтвердите действие"
|
||
message={confirm.text}
|
||
danger
|
||
confirmLabel="Подтвердить"
|
||
onClose={() => setConfirm(null)}
|
||
onConfirm={() => {
|
||
const action = confirm.action;
|
||
setConfirm(null);
|
||
void run(action, 'Изменения сохранены', true);
|
||
}}
|
||
/>
|
||
)}
|
||
</section>
|
||
);
|
||
}
|