diff --git a/public/info.html b/public/info.html index f1f4084..2c3cc3d 100644 --- a/public/info.html +++ b/public/info.html @@ -105,6 +105,7 @@ +
diff --git a/public/info.js b/public/info.js index 4010ac7..bd8ed82 100644 --- a/public/info.js +++ b/public/info.js @@ -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 = '/';