This commit is contained in:
2026-04-16 14:28:30 +05:00
parent 766d38c198
commit 9a91998904
2 changed files with 44 additions and 0 deletions

View File

@@ -105,6 +105,7 @@
<button id="applyFiltersBtn" class="primary">Применить</button>
<button id="resetFiltersBtn" class="reset-btn">Сбросить</button>
<button id="exportBtn" class="export-btn">📎 Выгрузить в Excel (CSV)</button>
<button id="exportTeachersBtn" class="export-btn">👨‍🏫 Выгрузить учителей (Excel)</button>
<button id="exportGuardBtn" class="export-btn">🛡️ Выгрузить для охраны (Excel)</button>
</div>
<div class="header-actions">

View File

@@ -191,6 +191,48 @@ async function exportForGuard() {
}
}
// Функция выгрузки уникальных учителей (без дублирования)
async function exportTeachersForGuard() {
try {
const res = await fetch('/api/info/registrations');
const registrations = await res.json();
if (!registrations.length) {
alert('Нет данных для экспорта');
return;
}
const uniqueTeachers = new Map();
registrations.forEach(reg => {
if (reg.teacher && !uniqueTeachers.has(reg.teacher)) {
uniqueTeachers.set(reg.teacher, { 'Учитель': reg.teacher });
}
});
const uniqueArray = Array.from(uniqueTeachers.values());
if (uniqueArray.length === 0) {
alert('Нет данных об учителях');
return;
}
// Вычисляем максимальную длину имени учителя
let maxLen = 0;
uniqueArray.forEach(item => {
const len = item['Учитель'].length;
if (len > maxLen) maxLen = len;
});
const colWidth = Math.max(maxLen + 2, 30);
const ws = XLSX.utils.json_to_sheet(uniqueArray);
ws['!cols'] = [{ wch: colWidth }];
const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, 'Учителя');
XLSX.writeFile(wb, 'teachers_unique.xlsx');
} catch (err) {
console.error(err);
alert('Ошибка при выгрузке учителей');
}
}
function setupEventListeners() {
document.getElementById('applyFiltersBtn')?.addEventListener('click', () => loadRegistrations());
document.getElementById('resetFiltersBtn')?.addEventListener('click', () => {
@@ -202,6 +244,7 @@ function setupEventListeners() {
});
document.getElementById('exportBtn')?.addEventListener('click', exportToCSV);
document.getElementById('exportGuardBtn')?.addEventListener('click', exportForGuard);
document.getElementById('exportTeachersBtn')?.addEventListener('click', exportTeachersForGuard);
document.getElementById('logoutBtn')?.addEventListener('click', async () => {
await fetch('/api/logout', { method: 'POST' });
window.location.href = '/';