download data import csv report
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
let processingData = [];
|
||||
let currentSessionId = null; // Store session ID for report download
|
||||
let resultsMap = null;
|
||||
let markers = [];
|
||||
let eventListenersInitialized = false;
|
||||
@@ -310,6 +311,7 @@ function handleProcessingUpdate(data) {
|
||||
|
||||
case 'complete':
|
||||
console.log('Received complete event:', data);
|
||||
currentSessionId = data.sessionId; // Store session ID for report download
|
||||
onProcessingComplete(data);
|
||||
break;
|
||||
|
||||
@@ -410,6 +412,11 @@ function onProcessingComplete(data) {
|
||||
}
|
||||
}
|
||||
|
||||
// Show download report button if we have a session ID
|
||||
if (currentSessionId && data.total > 0) {
|
||||
showDownloadReportButton(data.total, data.errors || data.failed || 0);
|
||||
}
|
||||
|
||||
const errorCount = data.errors || data.failed || 0;
|
||||
showDataConvertStatus(`Processing complete: ${processedCount} successful, ${errorCount} errors`,
|
||||
errorCount > 0 ? 'warning' : 'success');
|
||||
@@ -551,6 +558,13 @@ function resetToUpload() {
|
||||
|
||||
// Clear any existing data
|
||||
processingData = [];
|
||||
currentSessionId = null; // Reset session ID
|
||||
|
||||
// Remove download report button if it exists
|
||||
const downloadBtn = document.getElementById('download-report-btn');
|
||||
if (downloadBtn) {
|
||||
downloadBtn.remove();
|
||||
}
|
||||
if (markers && markers.length > 0) {
|
||||
markers.forEach(marker => {
|
||||
if (resultsMap && marker) {
|
||||
@@ -594,3 +608,84 @@ function resetToUpload() {
|
||||
// Reset form
|
||||
clearUpload();
|
||||
}
|
||||
|
||||
// Show download report button
|
||||
function showDownloadReportButton(totalRecords, errorCount) {
|
||||
const actionsDiv = document.getElementById('processing-actions');
|
||||
if (!actionsDiv) return;
|
||||
|
||||
// Check if button already exists
|
||||
let downloadBtn = document.getElementById('download-report-btn');
|
||||
if (!downloadBtn) {
|
||||
downloadBtn = document.createElement('button');
|
||||
downloadBtn.id = 'download-report-btn';
|
||||
downloadBtn.type = 'button';
|
||||
downloadBtn.className = 'btn btn-info';
|
||||
downloadBtn.addEventListener('click', downloadProcessingReport);
|
||||
|
||||
// Insert before the save results button
|
||||
const saveBtn = document.getElementById('save-results-btn');
|
||||
if (saveBtn) {
|
||||
actionsDiv.insertBefore(downloadBtn, saveBtn);
|
||||
} else {
|
||||
actionsDiv.appendChild(downloadBtn);
|
||||
}
|
||||
}
|
||||
|
||||
// Update button text with error info
|
||||
if (errorCount > 0) {
|
||||
downloadBtn.textContent = `📄 Download Full Report (${totalRecords} records, ${errorCount} errors)`;
|
||||
downloadBtn.title = `Download complete processing report including ${errorCount} error records for review`;
|
||||
} else {
|
||||
downloadBtn.textContent = `📄 Download Processing Report (${totalRecords} records)`;
|
||||
downloadBtn.title = 'Download complete processing report';
|
||||
}
|
||||
|
||||
downloadBtn.style.marginRight = '10px'; // Add some spacing
|
||||
}
|
||||
|
||||
// Download processing report
|
||||
async function downloadProcessingReport() {
|
||||
if (!currentSessionId) {
|
||||
showDataConvertStatus('No processing session available for report generation', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
const downloadBtn = document.getElementById('download-report-btn');
|
||||
const originalText = downloadBtn.textContent;
|
||||
|
||||
try {
|
||||
downloadBtn.disabled = true;
|
||||
downloadBtn.textContent = '📄 Generating Report...';
|
||||
|
||||
showDataConvertStatus('Generating processing report...', 'info');
|
||||
|
||||
// Create download link
|
||||
const downloadUrl = `/api/admin/data-convert/download-report/${currentSessionId}`;
|
||||
|
||||
// Create a temporary anchor element and trigger download
|
||||
const link = document.createElement('a');
|
||||
link.href = downloadUrl;
|
||||
link.download = `geocoding-report-${currentSessionId}.csv`;
|
||||
link.style.display = 'none';
|
||||
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
|
||||
showDataConvertStatus('Processing report downloaded successfully', 'success');
|
||||
|
||||
// Update button text
|
||||
downloadBtn.textContent = '📄 Report Downloaded';
|
||||
setTimeout(() => {
|
||||
downloadBtn.textContent = originalText;
|
||||
downloadBtn.disabled = false;
|
||||
}, 3000);
|
||||
|
||||
} catch (error) {
|
||||
console.error('Download report error:', error);
|
||||
showDataConvertStatus('Failed to download processing report: ' + error.message, 'error');
|
||||
downloadBtn.textContent = originalText;
|
||||
downloadBtn.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user