65 lines
3.0 KiB
JavaScript
65 lines
3.0 KiB
JavaScript
// Сводка считает опубликованные занятия за выбранный период, а не штатную норму.
|
|
export function departmentWorkloadRows(teachers = [], workload = []) {
|
|
const rows = new Map();
|
|
teachers.forEach(teacher => {
|
|
rows.set(`id:${teacher.id}`, {
|
|
id: teacher.id,
|
|
name: teacher.fullName || teacher.username || 'Имя не указано',
|
|
meta: teacher.jobTitle || 'Должность не указана',
|
|
assigned: true,
|
|
academicHours: 0,
|
|
lessonCount: 0
|
|
});
|
|
});
|
|
workload.forEach(item => {
|
|
const key = item.id != null ? `id:${item.id}` : `name:${item.name || ''}`;
|
|
const row = rows.get(key) || {
|
|
id: item.id,
|
|
name: item.name || item.fullName || 'Имя не указано',
|
|
meta: 'Есть занятия в расписании кафедры',
|
|
assigned: false,
|
|
academicHours: 0,
|
|
lessonCount: 0
|
|
};
|
|
row.academicHours += Number(item.academicHours) || 0;
|
|
row.lessonCount += Number(item.lessonCount) || 0;
|
|
rows.set(key, row);
|
|
});
|
|
return [...rows.values()].sort((left, right) => right.academicHours - left.academicHours
|
|
|| left.name.localeCompare(right.name, 'ru'));
|
|
}
|
|
|
|
export function departmentWorkloadSummary(rows, limit) {
|
|
const threshold = Number(limit);
|
|
const hasLimit = String(limit ?? '').trim() !== '' && Number.isFinite(threshold) && threshold > 0;
|
|
return {
|
|
academicHours: rows.reduce((sum, row) => sum + row.academicHours, 0),
|
|
lessonCount: rows.reduce((sum, row) => sum + row.lessonCount, 0),
|
|
withLessons: rows.filter(row => row.lessonCount > 0).length,
|
|
withoutLessons: rows.filter(row => row.assigned && row.lessonCount === 0).length,
|
|
unassigned: rows.filter(row => !row.assigned && row.lessonCount > 0).length,
|
|
aboveLimit: hasLimit ? rows.filter(row => row.academicHours > threshold).length : null,
|
|
hasLimit
|
|
};
|
|
}
|
|
|
|
export function filterDepartmentWorkload(rows, filter, query, limit) {
|
|
const threshold = Number(limit);
|
|
const search = String(query || '').trim().toLocaleLowerCase('ru');
|
|
return rows.filter(row => {
|
|
if (search && !`${row.name} ${row.meta}`.toLocaleLowerCase('ru').includes(search)) return false;
|
|
if (filter === 'without-lessons') return row.assigned && row.lessonCount === 0;
|
|
if (filter === 'with-lessons') return row.lessonCount > 0;
|
|
if (filter === 'unassigned') return !row.assigned && row.lessonCount > 0;
|
|
if (filter === 'above-limit') return threshold > 0 && row.academicHours > threshold;
|
|
return true;
|
|
});
|
|
}
|
|
|
|
export function departmentListPage(items, page, size = 25) {
|
|
const totalPages = Math.ceil(items.length / size);
|
|
const current = Math.min(Math.max(0, page), Math.max(0, totalPages - 1));
|
|
return { items: items.slice(current * size, (current + 1) * size), page: current, size,
|
|
totalItems: items.length, totalPages };
|
|
}
|