Implement export function

This commit is contained in:
Nguyen Ngo
2025-08-14 11:11:38 -04:00
parent 03c75d5d30
commit 8392db4798
6 changed files with 1302 additions and 23 deletions
+126
View File
@@ -945,3 +945,129 @@ function exportAttendanceWithAccuracy() {
link.click();
document.body.removeChild(link);
}
function exportAttendance() {
// Log export action
console.log('Export button clicked - redirecting to configuration page');
// Get current filters
const currentFilters = getCurrentFilters();
// Build URL with current filters
const params = new URLSearchParams();
if (currentFilters.date_from) params.append('date_from', currentFilters.date_from);
if (currentFilters.date_to) params.append('date_to', currentFilters.date_to);
if (currentFilters.location) params.append('location', currentFilters.location);
if (currentFilters.employee) params.append('employee', currentFilters.employee);
// Navigate to export configuration page
const configUrl = '/export-configuration' + (params.toString() ? '?' + params.toString() : '');
window.location.href = configUrl;
}
function getCurrentFilters() {
// Extract current filter values from the page
return {
date_from: document.getElementById('date_from')?.value || '',
date_to: document.getElementById('date_to')?.value || '',
location: document.getElementById('location')?.value || '',
employee: document.getElementById('employee')?.value || ''
};
}
// Add a quick CSV export function as backup (keep existing functionality)
function exportAttendanceCSV() {
// Build export URL with current filters for CSV
const params = new URLSearchParams();
const filters = getCurrentFilters();
if (filters.date_from) params.append('date_from', filters.date_from);
if (filters.date_to) params.append('date_to', filters.date_to);
if (filters.location) params.append('location', filters.location);
if (filters.employee) params.append('employee', filters.employee);
params.append('export', 'csv');
// Create a temporary link and click it to download
const downloadUrl = window.location.pathname + '?' + params.toString();
window.open(downloadUrl, '_blank');
}
// Enhanced export menu (if you want to add dropdown with multiple export options)
function showExportMenu() {
// Create export options menu
const existingMenu = document.getElementById('exportMenu');
if (existingMenu) {
existingMenu.remove();
return;
}
const exportBtn = document.querySelector('button[onclick="exportAttendance()"]');
if (!exportBtn) return;
const menu = document.createElement('div');
menu.id = 'exportMenu';
menu.style.cssText = `
position: absolute;
top: 100%;
right: 0;
background: white;
border: 1px solid #e2e8f0;
border-radius: 8px;
box-shadow: 0 4px 16px rgba(0,0,0,0.1);
z-index: 1000;
min-width: 200px;
margin-top: 5px;
`;
menu.innerHTML = `
<div style="padding: 0.5rem;">
<button onclick="exportAttendance(); closeExportMenu();"
style="width: 100%; padding: 0.75rem; border: none; background: none; text-align: left; cursor: pointer; border-radius: 4px;"
onmouseover="this.style.background='#f7fafc'"
onmouseout="this.style.background='none'">
<i class="fas fa-file-excel" style="color: #48bb78; margin-right: 0.5rem;"></i>
Excel Export (Customizable)
</button>
<button onclick="exportAttendanceCSV(); closeExportMenu();"
style="width: 100%; padding: 0.75rem; border: none; background: none; text-align: left; cursor: pointer; border-radius: 4px;"
onmouseover="this.style.background='#f7fafc'"
onmouseout="this.style.background='none'">
<i class="fas fa-file-csv" style="color: #4299e1; margin-right: 0.5rem;"></i>
Quick CSV Export
</button>
</div>
`;
exportBtn.parentElement.style.position = 'relative';
exportBtn.parentElement.appendChild(menu);
// Close menu when clicking outside
setTimeout(() => {
document.addEventListener('click', function closeOnClickOutside(e) {
if (!menu.contains(e.target) && e.target !== exportBtn) {
closeExportMenu();
document.removeEventListener('click', closeOnClickOutside);
}
});
}, 100);
}
function closeExportMenu() {
const menu = document.getElementById('exportMenu');
if (menu) {
menu.remove();
}
}
// Initialize export functionality when page loads
document.addEventListener('DOMContentLoaded', function() {
// Update export button to use enhanced functionality
const exportBtn = document.querySelector('button[onclick="exportAttendance()"]');
if (exportBtn) {
// You can modify the button to show a dropdown instead
// exportBtn.onclick = showExportMenu;
// exportBtn.innerHTML = '<i class="fas fa-download"></i> Export Data <i class="fas fa-chevron-down" style="margin-left: 0.5rem;"></i>';
}
console.log('Enhanced export functionality initialized');
});