70 lines
2.9 KiB
JavaScript
70 lines
2.9 KiB
JavaScript
import { apiClient } from '../shared/api-client.js';
|
|
import { subjectPayload } from './study-plans-service.js';
|
|
export const fetchCalendarLoads = (semesterId, groupId = '') => {
|
|
const params = new URLSearchParams({ semesterId });
|
|
if (groupId) params.set('groupId', groupId);
|
|
return apiClient.get(`/api/calendar-loads?${params}`, {
|
|
errorMessage: 'Не удалось загрузить нагрузку календарных графиков',
|
|
});
|
|
};
|
|
export const calendarSubjectPath = (context, subjectId) =>
|
|
`/api/calendar-loads/groups/${context.groupId}/semesters/${context.semesterId}/subjects/${subjectId}`;
|
|
export const saveCalendarLoad = (context, subjectId, loads) =>
|
|
apiClient.put(
|
|
calendarSubjectPath(context, subjectId),
|
|
subjectPayload(loads, context.revision, true),
|
|
);
|
|
export const assignCalendarTeacher = (context, row, teacherId) =>
|
|
apiClient.put(
|
|
`${calendarSubjectPath(context, row.subjectId)}/loads/${row.category}/teacher`,
|
|
{
|
|
teacherId: teacherId == null ? null : Number(teacherId),
|
|
expectedRevision: context.revision,
|
|
},
|
|
);
|
|
export function calendarMaterialRows(details, filters = {}, departments = []) {
|
|
const names = new Map(
|
|
departments.map((d) => [
|
|
String(d.id),
|
|
d.departmentName || d.name || '',
|
|
]),
|
|
);
|
|
const query = (filters.query || '').trim().toLocaleLowerCase('ru');
|
|
return details
|
|
.flatMap((detail) =>
|
|
detail.subjects.flatMap((subject) =>
|
|
subject.loads.map((load) => ({
|
|
...load,
|
|
context: detail.context,
|
|
subjectId: subject.subjectId,
|
|
subjectName: subject.name,
|
|
departmentId: subject.departmentId,
|
|
})),
|
|
),
|
|
)
|
|
.filter(
|
|
(row) =>
|
|
(!filters.groupId ||
|
|
String(row.context.groupId) === String(filters.groupId)) &&
|
|
(!filters.departmentId ||
|
|
String(row.departmentId) ===
|
|
String(filters.departmentId)) &&
|
|
(!filters.unassigned || row.teacherId == null) &&
|
|
(filters.includeZero || row.academicHours > 0) &&
|
|
`${row.subjectName} ${row.context.groupName} ${row.teacherName || ''}`
|
|
.toLocaleLowerCase('ru')
|
|
.includes(query),
|
|
)
|
|
.sort(
|
|
(a, b) =>
|
|
(names.get(String(a.departmentId)) || '').localeCompare(
|
|
names.get(String(b.departmentId)) || '',
|
|
'ru',
|
|
) ||
|
|
a.context.groupName.localeCompare(b.context.groupName, 'ru', {
|
|
numeric: true,
|
|
}) ||
|
|
a.subjectName.localeCompare(b.subjectName, 'ru'),
|
|
);
|
|
}
|