diff --git a/public/info.html b/public/info.html index 0e766f1..f1f4084 100644 --- a/public/info.html +++ b/public/info.html @@ -105,6 +105,7 @@ +

Все записи

@@ -131,6 +132,7 @@
+ \ No newline at end of file diff --git a/public/info.js b/public/info.js index 33eff32..4010ac7 100644 --- a/public/info.js +++ b/public/info.js @@ -66,7 +66,7 @@ async function loadRegistrations() { document.getElementById('recordsCount').innerText = `Найдено: ${currentRegistrations.length}`; } catch (err) { console.error(err); - document.getElementById('tableBody').innerHTML = 'Ошибка загрузки'; + document.getElementById('tableBody').innerHTML = 'Ошибка загрузки'; } } @@ -152,6 +152,45 @@ function exportToCSV() { URL.revokeObjectURL(url); } +// Функция выгрузки уникальных родителей для охраны с автоматической шириной столбца +async function exportForGuard() { + try { + const res = await fetch('/api/info/registrations'); + const registrations = await res.json(); + if (!registrations.length) { + alert('Нет данных для экспорта'); + return; + } + const uniqueMap = new Map(); + registrations.forEach(reg => { + if (!uniqueMap.has(reg.parent_name)) { + uniqueMap.set(reg.parent_name, { 'ФИО родителя': reg.parent_name }); + } + }); + const uniqueArray = Array.from(uniqueMap.values()); + + // Вычисляем максимальную длину ФИО + let maxLen = 0; + uniqueArray.forEach(item => { + const len = item['ФИО родителя'].length; + if (len > maxLen) maxLen = len; + }); + // Ширина столбца в Excel (в символах) – делаем запас +2, минимум 30 + const colWidth = Math.max(maxLen + 2, 50); + + const ws = XLSX.utils.json_to_sheet(uniqueArray); + // Устанавливаем ширину для столбца A (индекс 0) + ws['!cols'] = [{ wch: colWidth }]; + + const wb = XLSX.utils.book_new(); + XLSX.utils.book_append_sheet(wb, ws, 'Список для охраны'); + XLSX.writeFile(wb, 'spisok_dlya_ohrany.xlsx'); + } catch (err) { + console.error(err); + alert('Ошибка при выгрузке'); + } +} + function setupEventListeners() { document.getElementById('applyFiltersBtn')?.addEventListener('click', () => loadRegistrations()); document.getElementById('resetFiltersBtn')?.addEventListener('click', () => { @@ -162,6 +201,7 @@ function setupEventListeners() { loadRegistrations(); }); document.getElementById('exportBtn')?.addEventListener('click', exportToCSV); + document.getElementById('exportGuardBtn')?.addEventListener('click', exportForGuard); document.getElementById('logoutBtn')?.addEventListener('click', async () => { await fetch('/api/logout', { method: 'POST' }); window.location.href = '/';