feat: преподаватели дисциплин — привязки на странице кафедры и сужение в конструкторе правил
Кабинет кафедры: новая секция «Преподаватели дисциплин» — таблица дисциплин кафедры с колонкой привязанных преподавателей, панель управления с поиском по преподавателям кафедры (уже привязанные скрываются), отвязка с диалогом подтверждения. Привязки грузятся пачками по 100 дисциплин. Конструктор правил: список «Преподаватель» слота сужается до привязок выбранной дисциплины через GET /api/users/teachers/options?subjectId=… (новый параметр, запрос searchTeachersBySubjectBinding). До выбора дисциплины — подсказка «Сначала выберите дисциплину», без привязок — «К дисциплине не привязаны преподаватели». Смена дисциплины или группы сбрасывает преподавателей слотов; текущий преподаватель редактируемого правила остаётся в списке через selectedId. Тот же контракт в модалке конфликта слота.
This commit is contained in:
1 parent
deeee47cae
commit
ddf1850155
13 files changed
+599
-26
No files matched your search
@@ -114,17 +114,23 @@ import {
|
||||
assignTeacherError,
|
||||
attachmentGroupLabel,
|
||||
availableTeachers,
|
||||
bindingCountLabel,
|
||||
bindSubjectTeacher,
|
||||
departmentSubjectCalendarEndpoint,
|
||||
departmentSubjectsEndpoint,
|
||||
departmentTeacherOptionsEndpoint,
|
||||
departmentTeacherRequestsEndpoint,
|
||||
departmentTeachersEndpoint,
|
||||
fetchDepartmentSubjectCalendar,
|
||||
fetchDepartmentSubjects,
|
||||
fetchDepartmentTeacherOptions,
|
||||
fetchDepartmentTeacherRequests,
|
||||
fetchDepartmentTeachers,
|
||||
fetchSubjectTeacherBindings,
|
||||
fetchTeacherWorkload,
|
||||
filterDepartmentSubjects,
|
||||
formatDateTime,
|
||||
groupBindingsBySubject,
|
||||
importSubjects,
|
||||
importSubjectsPayload,
|
||||
listValuesLabel,
|
||||
@@ -138,6 +144,7 @@ import {
|
||||
teacherOptionLabel,
|
||||
teacherRequestPayload,
|
||||
teacherWorkloadEndpoint,
|
||||
unbindSubjectTeacher,
|
||||
uniqueAttachmentValues,
|
||||
workloadLabel
|
||||
} from '../react/admin/department-workspace-service.js';
|
||||
@@ -1444,10 +1451,89 @@ test('вкладка кабинета кафедры рендерит формы
|
||||
assert.match(markup, /Профиль/);
|
||||
assert.match(markup, /Вид нагрузки/);
|
||||
assert.match(markup, /Календарный график/);
|
||||
assert.match(markup, /Преподаватели дисциплин/);
|
||||
assert.match(markup, /id="department-binding-card"/);
|
||||
assert.match(markup, /id="department-binding-table"/);
|
||||
assert.match(markup, /id="department-binding-tbody"/);
|
||||
assert.match(markup, /id="department-binding-count"/);
|
||||
assert.match(markup, /Загрузка\.\.\./);
|
||||
assert.doesNotMatch(markup, /style="/);
|
||||
// карточка комментариев скрыта до выбора дисциплины
|
||||
assert.doesNotMatch(markup, /department-comments-card/);
|
||||
// панель привязки преподавателей скрыта до выбора дисциплины
|
||||
assert.doesNotMatch(markup, /id="department-binding-panel"/);
|
||||
});
|
||||
|
||||
test('контракты привязки преподавателей к дисциплинам кафедры', async () => {
|
||||
// опции преподавателей кафедры для привязки
|
||||
assert.equal(
|
||||
departmentTeacherOptionsEndpoint('ivan', 7, 3),
|
||||
'/api/users/teachers/options?query=ivan&limit=30&selectedId=7&departmentId=3'
|
||||
);
|
||||
assert.equal(
|
||||
departmentTeacherOptionsEndpoint(' ', null, null),
|
||||
'/api/users/teachers/options?query=&limit=30'
|
||||
);
|
||||
|
||||
const teachersClient = recordingClient(async () => [{ id: 7, fullName: 'Иванов И. И.' }]);
|
||||
const teachers = await fetchDepartmentTeacherOptions('ivan', 7, 3, teachersClient);
|
||||
assert.equal(teachers[0].fullName, 'Иванов И. И.');
|
||||
assert.equal(teachersClient.calls[0].endpoint, '/api/users/teachers/options?query=ivan&limit=30&selectedId=7&departmentId=3');
|
||||
|
||||
// опции преподавателей слота сужаются до привязок дисциплины
|
||||
assert.equal(
|
||||
teachersOptionsEndpoint('ivan', 7, 5),
|
||||
'/api/users/teachers/options?query=ivan&limit=30&selectedId=7&subjectId=5'
|
||||
);
|
||||
assert.equal(
|
||||
teachersOptionsEndpoint('ivan', 7, null),
|
||||
'/api/users/teachers/options?query=ivan&limit=30&selectedId=7'
|
||||
);
|
||||
const subjectTeachersClient = recordingClient(async () => [{ id: 7, fullName: 'Иванов И. И.' }]);
|
||||
await fetchTeacherOptions('ivan', 7, 5, subjectTeachersClient);
|
||||
assert.equal(subjectTeachersClient.calls[0].endpoint, '/api/users/teachers/options?query=ivan&limit=30&selectedId=7&subjectId=5');
|
||||
|
||||
// привязки: больше 100 дисциплин делятся на отдельные запросы
|
||||
const subjectIds = Array.from({ length: 150 }, (_, index) => index + 1);
|
||||
const bindingsClient = recordingClient(async () => []);
|
||||
await fetchSubjectTeacherBindings(subjectIds, bindingsClient);
|
||||
assert.equal(bindingsClient.calls.length, 2);
|
||||
assert.equal(bindingsClient.calls[0].endpoint.split('subjectId=').length - 1, 100);
|
||||
assert.equal(bindingsClient.calls[1].endpoint.split('subjectId=').length - 1, 50);
|
||||
assert.ok(bindingsClient.calls[0].endpoint.startsWith('/api/teacher-subjects?'));
|
||||
|
||||
// пустой список дисциплин не делает запросов
|
||||
const emptyClient = recordingClient(async () => []);
|
||||
assert.deepEqual(await fetchSubjectTeacherBindings([], emptyClient), []);
|
||||
assert.equal(emptyClient.calls.length, 0);
|
||||
|
||||
// привязка и отвязка преподавателя
|
||||
const bindClient = recordingClient(async () => ({ message: 'Привязка создана' }));
|
||||
await bindSubjectTeacher(5, 9, bindClient);
|
||||
assert.equal(bindClient.calls[0].method, 'POST');
|
||||
assert.equal(bindClient.calls[0].endpoint, '/api/teacher-subjects');
|
||||
assert.deepEqual(bindClient.calls[0].json, { subjectId: 5, userId: 9 });
|
||||
|
||||
const unbindClient = recordingClient(async () => ({ message: 'Привязка удалена' }));
|
||||
await unbindSubjectTeacher(5, 9, unbindClient);
|
||||
assert.equal(unbindClient.calls[0].method, 'DELETE');
|
||||
assert.equal(unbindClient.calls[0].endpoint, '/api/teacher-subjects');
|
||||
|
||||
// группировка привязок по дисциплинам
|
||||
const grouped = groupBindingsBySubject([
|
||||
{ subjectId: 5, userId: 1, fullName: 'А' },
|
||||
{ subjectId: 5, userId: 2, fullName: 'Б' },
|
||||
{ subjectId: 6, userId: 3, fullName: 'В' }
|
||||
]);
|
||||
assert.equal(grouped.get('5').length, 2);
|
||||
assert.equal(grouped.get('6').length, 1);
|
||||
assert.equal(grouped.get('7'), undefined);
|
||||
|
||||
// склонение счётчика привязок
|
||||
assert.equal(bindingCountLabel(1), '1 привязка');
|
||||
assert.equal(bindingCountLabel(3), '3 привязки');
|
||||
assert.equal(bindingCountLabel(11), '11 привязок');
|
||||
assert.equal(bindingCountLabel(25), '25 привязок');
|
||||
});
|
||||
|
||||
test('дисциплины кафедры фильтруются по прикреплению к графикам', () => {
|
||||
@@ -2179,7 +2265,7 @@ test('контракты API просмотра расписаний сохра
|
||||
'/api/groups/options?query=%D0%BF%D0%BE%D0%B8%D1%81%D0%BA&limit=30&selectedId=15&departmentId=4'
|
||||
);
|
||||
|
||||
await fetchTeacherOptions('иванов', '', client);
|
||||
await fetchTeacherOptions('иванов', '', null, client);
|
||||
assert.equal(
|
||||
client.calls[9].endpoint,
|
||||
'/api/users/teachers/options?query=%D0%B8%D0%B2%D0%B0%D0%BD%D0%BE%D0%B2&limit=30'
|
||||
|
||||
Reference in new issue
Block a user