feat: дисциплины кафедры из календарных графиков
Дисциплины, прикреплённые к календарным графикам, автоматически отображаются на странице кафедры — ручное ведение списка больше не требуется (форма импорта сохранена). - Backend: GET /api/department/subjects/calendar — дисциплины кафедры с прикреплениями к графикам (дисциплина попадает на страницу своей кафедры по subjects.department_id) - Frontend: кабинет кафедры — колонка «Календарный график» с семестрами, фильтр «Все / В календарных графиках / Без графика» - Тесты: backend (группировка, сортировка, пустая кафедра), frontend (контракт, фильтр, группировка семестров) — 239/239 - Документация: API.md, BUSINESS_LOGIC.md
This commit is contained in:
1 parent
97bf3cc50a
commit
91f44c85b4
11 files changed
+414
-31
No files matched your search
@@ -42,6 +42,73 @@ export function fetchDepartmentSubjects(departmentId, client = apiClient) {
|
||||
});
|
||||
}
|
||||
|
||||
// --- Дисциплины кафедры с прикреплениями к календарным графикам ---
|
||||
|
||||
export function departmentSubjectCalendarEndpoint(departmentId) {
|
||||
return `/api/department/subjects/calendar?departmentId=${encodeURIComponent(departmentId || '')}`;
|
||||
}
|
||||
|
||||
export function fetchDepartmentSubjectCalendar(departmentId, client = apiClient) {
|
||||
return client.get(departmentSubjectCalendarEndpoint(departmentId), {
|
||||
errorMessage: 'Ошибка загрузки дисциплин'
|
||||
});
|
||||
}
|
||||
|
||||
export const SUBJECT_CALENDAR_FILTER_ALL = 'all';
|
||||
export const SUBJECT_CALENDAR_FILTER_IN_CALENDAR = 'calendar';
|
||||
export const SUBJECT_CALENDAR_FILTER_WITHOUT_CALENDAR = 'manual';
|
||||
|
||||
export const SUBJECT_CALENDAR_FILTER_OPTIONS = [
|
||||
{ value: SUBJECT_CALENDAR_FILTER_ALL, label: 'Все дисциплины' },
|
||||
{ value: SUBJECT_CALENDAR_FILTER_IN_CALENDAR, label: 'В календарных графиках' },
|
||||
{ value: SUBJECT_CALENDAR_FILTER_WITHOUT_CALENDAR, label: 'Без графика' }
|
||||
];
|
||||
|
||||
export function filterDepartmentSubjects(items, filter) {
|
||||
const list = items || [];
|
||||
if (filter === SUBJECT_CALENDAR_FILTER_IN_CALENDAR) {
|
||||
return list.filter(item => (item.attachments || []).length > 0);
|
||||
}
|
||||
if (filter === SUBJECT_CALENDAR_FILTER_WITHOUT_CALENDAR) {
|
||||
return list.filter(item => !(item.attachments || []).length);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
// Прикрепления дисциплины группируются по графику: один график — одна строка
|
||||
// с перечнем семестров («2026/2027 · 10.03.01 ИБ — 1, 3 семестр»).
|
||||
export function subjectAttachmentGroups(attachments) {
|
||||
const groups = new Map();
|
||||
(attachments || []).forEach(attachment => {
|
||||
if (!attachment) return;
|
||||
const key = String(attachment.calendarId);
|
||||
if (!groups.has(key)) {
|
||||
groups.set(key, {
|
||||
calendarId: attachment.calendarId,
|
||||
calendarTitle: attachment.calendarTitle || '',
|
||||
academicYearTitle: attachment.academicYearTitle || '',
|
||||
semesterNumbers: []
|
||||
});
|
||||
}
|
||||
groups.get(key).semesterNumbers.push(attachment.semesterNumber);
|
||||
});
|
||||
return Array.from(groups.values()).map(group => ({
|
||||
...group,
|
||||
semesterNumbers: [...new Set(group.semesterNumbers)].sort((a, b) => a - b)
|
||||
}));
|
||||
}
|
||||
|
||||
export function semesterNumbersLabel(numbers) {
|
||||
const sorted = [...(numbers || [])].sort((a, b) => a - b);
|
||||
return sorted.map(number => `${number} семестр`).join(', ');
|
||||
}
|
||||
|
||||
export function attachmentGroupLabel(group) {
|
||||
if (!group) return '';
|
||||
const title = group.calendarTitle || group.academicYearTitle || 'График';
|
||||
return `${title} — ${semesterNumbersLabel(group.semesterNumbers)}`;
|
||||
}
|
||||
|
||||
export function importSubjectsPayload(rows, departmentId) {
|
||||
if (!departmentId) return { error: 'Выберите кафедру' };
|
||||
const payload = (rows || [])
|
||||
|
||||
@@ -5,26 +5,31 @@ import { addDays, toIsoDate } from '../../shared/dates.js';
|
||||
import { requestCountLabel } from '../admin-service.js';
|
||||
import {
|
||||
DEPARTMENT_REQUEST_TABLE_COLUMNS,
|
||||
SUBJECT_CALENDAR_FILTER_ALL,
|
||||
SUBJECT_CALENDAR_FILTER_OPTIONS,
|
||||
SUBJECT_TABLE_COLUMNS,
|
||||
assignTeacher,
|
||||
assignTeacherError,
|
||||
attachmentGroupLabel,
|
||||
availableTeachers,
|
||||
defaultWorkloadPeriod,
|
||||
departmentOptionLabel,
|
||||
fetchAllTeachers,
|
||||
fetchDepartmentSubjects,
|
||||
fetchDepartmentSubjectCalendar,
|
||||
fetchDepartmentTeacherRequests,
|
||||
fetchDepartmentTeachers,
|
||||
fetchDepartments,
|
||||
fetchSemesters,
|
||||
fetchSubjectComments,
|
||||
fetchTeacherWorkload,
|
||||
filterDepartmentSubjects,
|
||||
formatDateTime,
|
||||
importSubjects,
|
||||
importSubjectsPayload,
|
||||
requestStatusClass,
|
||||
requestStatusLabel,
|
||||
saveSubjectComment,
|
||||
subjectAttachmentGroups,
|
||||
subjectCountLabel,
|
||||
submitTeacherRequest,
|
||||
teacherMetrics,
|
||||
@@ -52,6 +57,7 @@ export function DepartmentWorkspaceTab() {
|
||||
const [workspaceAlert, setWorkspaceAlert] = useState({ text: '', isError: false });
|
||||
|
||||
const [subjects, setSubjects] = useState({ loading: true, items: [], error: '' });
|
||||
const [subjectFilter, setSubjectFilter] = useState(SUBJECT_CALENDAR_FILTER_ALL);
|
||||
const [teachers, setTeachers] = useState({ items: null, error: '' });
|
||||
const [workload, setWorkload] = useState({ items: null, error: '' });
|
||||
const [requests, setRequests] = useState({ items: null, error: '' });
|
||||
@@ -133,7 +139,7 @@ export function DepartmentWorkspaceTab() {
|
||||
async function loadSubjects() {
|
||||
setSubjects({ loading: true, items: [], error: '' });
|
||||
try {
|
||||
const items = await fetchDepartmentSubjects(currentDepartmentId());
|
||||
const items = await fetchDepartmentSubjectCalendar(currentDepartmentId());
|
||||
setSubjects({ loading: false, items: Array.isArray(items) ? items : [], error: '' });
|
||||
} catch (error) {
|
||||
setSubjects({ loading: false, items: [], error: error.message || 'Ошибка загрузки дисциплин' });
|
||||
@@ -333,9 +339,10 @@ export function DepartmentWorkspaceTab() {
|
||||
const requestsCountLabel = requests.error
|
||||
? '0 заявок'
|
||||
: (requests.items === null ? 'Загрузка...' : requestCountLabel(requests.items.length));
|
||||
const visibleSubjects = subjects.error || subjects.loading ? [] : filterDepartmentSubjects(subjects.items, subjectFilter);
|
||||
const subjectsCountLabel = subjects.error
|
||||
? '0 дисциплин'
|
||||
: (subjects.loading ? 'Загрузка...' : subjectCountLabel(subjects.items.length));
|
||||
: (subjects.loading ? 'Загрузка...' : subjectCountLabel(visibleSubjects.length));
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -665,6 +672,20 @@ export function DepartmentWorkspaceTab() {
|
||||
<div className="card-header-row">
|
||||
<h2>Дисциплины кафедры</h2>
|
||||
<span className="muted" id="department-subject-count">{subjectsCountLabel}</span>
|
||||
<div className="form-group form-group--flush" id="department-subject-filter-field">
|
||||
<label className="schedule-section-label schedule-section-label--flush" htmlFor="department-subject-filter">
|
||||
Показывать
|
||||
</label>
|
||||
<select
|
||||
id="department-subject-filter"
|
||||
value={subjectFilter}
|
||||
onChange={event => setSubjectFilter(event.target.value)}
|
||||
>
|
||||
{SUBJECT_CALENDAR_FILTER_OPTIONS.map(option => (
|
||||
<option key={option.value} value={option.value}>{option.label}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div className="table-wrap">
|
||||
<table>
|
||||
@@ -672,7 +693,7 @@ export function DepartmentWorkspaceTab() {
|
||||
<tr>
|
||||
<th>Код</th>
|
||||
<th>Название</th>
|
||||
<th>Описание</th>
|
||||
<th>Календарный график</th>
|
||||
<th>Комментарии</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -689,28 +710,43 @@ export function DepartmentWorkspaceTab() {
|
||||
{subjects.error}
|
||||
</td>
|
||||
</tr>
|
||||
) : subjects.items.length === 0 ? (
|
||||
) : visibleSubjects.length === 0 ? (
|
||||
<tr>
|
||||
<td colSpan={SUBJECT_TABLE_COLUMNS} className="loading-row">
|
||||
Дисциплины не найдены
|
||||
</td>
|
||||
</tr>
|
||||
) : subjects.items.map(subject => (
|
||||
<tr key={subject.id}>
|
||||
<td>{subject.code || '-'}</td>
|
||||
<td>{subject.name || '-'}</td>
|
||||
<td>{subject.description || '-'}</td>
|
||||
<td>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-sm btn-secondary department-comments-open"
|
||||
onClick={() => void openComments(subject.id, subject.name || '')}
|
||||
>
|
||||
Открыть
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
) : visibleSubjects.map(subject => {
|
||||
const attachmentGroups = subjectAttachmentGroups(subject.attachments);
|
||||
return (
|
||||
<tr key={subject.id}>
|
||||
<td>{subject.code || '-'}</td>
|
||||
<td>{subject.name || '-'}</td>
|
||||
<td>
|
||||
{attachmentGroups.length ? (
|
||||
<div className="assignment-subjects">
|
||||
{attachmentGroups.map(group => (
|
||||
<div className="assignment-subject-semester" key={group.calendarId}>
|
||||
<span>{attachmentGroupLabel(group)}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<span className="text-muted">Не прикреплена к графику</span>
|
||||
)}
|
||||
</td>
|
||||
<td>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-sm btn-secondary department-comments-open"
|
||||
onClick={() => void openComments(subject.id, subject.name || '')}
|
||||
>
|
||||
Открыть
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user