@@ -1302,9 +1165,6 @@ function onTabShown(tabName) {
if (tabName === 'issues') {
loadIssues();
loadIssueStats();
- } else if (tabName === 'import') {
- loadAvailableImportFiles();
- loadImportStatus();
} else if (tabName === 'backup') {
loadBackups();
} else if (tabName === 'users') {
@@ -2533,380 +2393,6 @@ async function addResponse() {
}
}
-// Import Management Functions
-let availableImportFiles = {};
-let importInProgress = false;
-
-async function loadAvailableImportFiles() {
- try {
- const response = await window.http.wrappedFetch('/api/import/available-files');
-
- if (!response.ok) throw new Error('Failed to load available files');
-
- const data = await response.json();
- availableImportFiles = data;
-
- // Populate file type dropdowns
- const fileTypeSelect = document.getElementById('adminFileType');
- const clearTableSelect = document.getElementById('adminClearTableType');
-
- fileTypeSelect.innerHTML = '
';
- clearTableSelect.innerHTML = '
';
-
- data.available_files.forEach(fileType => {
- const description = data.descriptions[fileType] || fileType;
-
- const option1 = document.createElement('option');
- option1.value = fileType;
- option1.textContent = `${fileType} - ${description}`;
- fileTypeSelect.appendChild(option1);
-
- const option2 = document.createElement('option');
- option2.value = fileType;
- option2.textContent = `${fileType} - ${description}`;
- clearTableSelect.appendChild(option2);
- });
-
- // Setup form listener
- document.getElementById('adminImportForm').addEventListener('submit', handleAdminImport);
-
- // File type change listener
- document.getElementById('adminFileType').addEventListener('change', updateAdminFileTypeDescription);
-
- } catch (error) {
- console.error('Error loading available files:', error);
- showAlert('Error loading available file types: ' + error.message, 'error');
- }
-}
-
-async function loadImportStatus() {
- try {
- const response = await window.http.wrappedFetch('/api/import/status');
-
- if (!response.ok) throw new Error('Failed to load import status');
-
- const status = await response.json();
- displayImportStatus(status);
-
- } catch (error) {
- console.error('Error loading import status:', error);
- document.getElementById('importStatus').innerHTML =
- `
Error loading import status: ${error.message}
`;
- }
-}
-
-function displayImportStatus(status) {
- const container = document.getElementById('importStatus');
-
- let html = '
';
- let totalRecords = 0;
-
- Object.entries(status).forEach(([fileType, info], index) => {
- totalRecords += info.record_count || 0;
-
- const statusClass = info.error ? 'danger' : (info.record_count > 0 ? 'success' : 'secondary');
- const statusIcon = info.error ? 'triangle-exclamation' : (info.record_count > 0 ? 'circle-check' : 'circle');
-
- // grid handles wrapping; no manual row breaks needed
-
- html += `
-
-
-
-
-
- ${fileType}
- ${info.table_name}
-
-
-
- ${info.record_count || 0}
-
-
- ${info.error ? `
${info.error}
` : ''}
-
-
-
- `;
- });
-
- html += '
';
- html += `
- Total Records: ${totalRecords.toLocaleString()}
-
`;
-
- container.innerHTML = html;
-}
-
-function updateAdminFileTypeDescription() {
- const fileType = document.getElementById('adminFileType').value;
- const description = availableImportFiles.descriptions && availableImportFiles.descriptions[fileType];
- document.getElementById('adminFileTypeDescription').textContent = description || '';
-}
-
-async function validateAdminFile() {
- const fileType = document.getElementById('adminFileType').value;
- const fileInput = document.getElementById('adminCsvFile');
-
- if (!fileType || !fileInput.files[0]) {
- showAlert('Please select both file type and CSV file', 'error');
- return;
- }
-
- const formData = new FormData();
- formData.append('file', fileInput.files[0]);
-
- try {
- showAdminProgress(true, 'Validating file...');
-
- const response = await window.http.wrappedFetch(`/api/import/validate/${fileType}`, {
- method: 'POST',
- body: formData
- });
-
- if (!response.ok) {
- throw await window.http.toError(response, 'Validation failed');
- }
-
- const result = await response.json();
- displayAdminValidationResults(result);
-
- } catch (error) {
- console.error('Validation error:', error);
- const message = window.http && typeof window.http.formatAlert === 'function'
- ? window.http.formatAlert(error, 'Validation failed')
- : 'Validation failed: ' + (error && error.message ? error.message : String(error));
- showAlert(message, 'error');
- } finally {
- showAdminProgress(false);
- }
-}
-
-function displayAdminValidationResults(result) {
- const panel = document.getElementById('adminValidationPanel');
- const container = document.getElementById('adminValidationResults');
-
- let html = '';
-
- // Overall status
- const statusClass = result.valid ? 'success' : 'danger';
- const statusIcon = result.valid ? 'circle-check' : 'triangle-exclamation';
-
- html += `
-
-
- File validation ${result.valid ? 'passed' : 'failed'}
-
- `;
-
- // Headers validation
- html += '
Column Headers
';
- if (result.headers.missing.length > 0) {
- html += `
- Missing columns: ${result.headers.missing.join(', ')}
-
`;
- }
- if (result.headers.extra.length > 0) {
- html += `
- Extra columns: ${result.headers.extra.join(', ')}
-
`;
- }
- if (result.headers.missing.length === 0 && result.headers.extra.length === 0) {
- html += '
All expected columns found
';
- }
-
- // Sample data
- if (result.sample_data && result.sample_data.length > 0) {
- html += '
Sample Data (First 10 rows)
';
- html += '
';
- html += '
';
- html += '';
- Object.keys(result.sample_data[0]).forEach(header => {
- html += `| ${header} | `;
- });
- html += '
';
-
- result.sample_data.forEach(row => {
- html += '';
- Object.values(row).forEach(value => {
- html += `| ${value || ''} | `;
- });
- html += '
';
- });
- html += '
';
- }
-
- // Validation errors
- if (result.validation_errors && result.validation_errors.length > 0) {
- html += '
Data Issues Found
';
- html += '
';
- result.validation_errors.forEach(error => {
- html += `
Row ${error.row}, Field "${error.field}": ${error.error}
`;
- });
- if (result.total_errors > result.validation_errors.length) {
- html += `
... and ${result.total_errors - result.validation_errors.length} more errors
`;
- }
- html += '
';
- }
-
- container.innerHTML = html;
- panel.style.display = 'block';
-}
-
-async function handleAdminImport(event) {
- event.preventDefault();
-
- if (importInProgress) {
- showAlert('Import already in progress', 'error');
- return;
- }
-
- const fileType = document.getElementById('adminFileType').value;
- const fileInput = document.getElementById('adminCsvFile');
- const replaceExisting = document.getElementById('adminReplaceExisting').checked;
-
- if (!fileType || !fileInput.files[0]) {
- showAlert('Please select both file type and CSV file', 'error');
- return;
- }
-
- importInProgress = true;
-
- const formData = new FormData();
- formData.append('file', fileInput.files[0]);
- formData.append('replace_existing', replaceExisting);
-
- try {
- showAdminProgress(true, 'Importing data...');
-
- const response = await window.http.wrappedFetch(`/api/import/upload/${fileType}`, {
- method: 'POST',
- body: formData
- });
-
- if (!response.ok) {
- throw await window.http.toError(response, 'Import failed');
- }
-
- const result = await response.json();
- displayAdminImportResults(result);
-
- // Refresh status after successful import
- await loadImportStatus();
-
- // Reset form
- document.getElementById('adminImportForm').reset();
-
- } catch (error) {
- console.error('Import error:', error);
- const message = window.http && typeof window.http.formatAlert === 'function'
- ? window.http.formatAlert(error, 'Import failed')
- : 'Import failed: ' + (error && error.message ? error.message : String(error));
- showAlert(message, 'error');
- } finally {
- importInProgress = false;
- showAdminProgress(false);
- }
-}
-
-function displayAdminImportResults(result) {
- const panel = document.getElementById('adminResultsPanel');
- const container = document.getElementById('adminImportResults');
-
- const successClass = result.errors && result.errors.length > 0 ? 'warning' : 'success';
-
- let html = `
-
-
Import Completed
-
- File Type: ${result.file_type}
- Records Imported: ${result.imported_count}
- Errors: ${result.total_errors || 0}
-
-
- `;
-
- if (result.errors && result.errors.length > 0) {
- html += '
Import Errors
';
- html += '
';
- result.errors.forEach(error => {
- html += `
Row ${error.row}: ${error.error}
`;
- });
- if (result.total_errors > result.errors.length) {
- html += `
... and ${result.total_errors - result.errors.length} more errors
`;
- }
- html += '
';
- }
-
- // Add summary for printers
- if (result.file_type === 'PRINTERS.csv') {
- html += `
-
- Printers: ${result.created_count || 0} created, ${result.updated_count || 0} updated
-
- `;
- // Auto-refresh printers tab list
- try { loadPrinters(); } catch (_) {}
- }
-
- container.innerHTML = html;
- panel.style.display = 'block';
-}
-
-function showAdminProgress(show, message = '') {
- const panel = document.getElementById('adminProgressPanel');
- const status = document.getElementById('adminProgressStatus');
- const bar = document.getElementById('adminProgressBar');
-
- if (show) {
- status.textContent = message;
- bar.style.width = '100%';
- bar.textContent = 'Processing...';
- panel.style.display = 'block';
- } else {
- panel.style.display = 'none';
- }
-}
-
-async function clearAdminTable() {
- const fileType = document.getElementById('adminClearTableType').value;
-
- if (!fileType) {
- showAlert('Please select a table to clear', 'error');
- return;
- }
-
- if (!confirm(`Are you sure you want to clear all data from ${fileType}? This action cannot be undone.`)) {
- return;
- }
-
- try {
- const response = await window.http.wrappedFetch(`/api/import/clear/${fileType}`, {
- method: 'DELETE'
- });
-
- if (!response.ok) {
- throw await window.http.toError(response, 'Clear operation failed');
- }
-
- const result = await response.json();
- showAlert(`Successfully cleared ${result.deleted_count} records from ${result.table_name}`, 'success');
-
- // Refresh status
- await loadImportStatus();
-
- } catch (error) {
- console.error('Clear table error:', error);
- const message = window.http && typeof window.http.formatAlert === 'function'
- ? window.http.formatAlert(error, 'Clear operation failed')
- : 'Clear operation failed: ' + (error && error.message ? error.message : String(error));
- showAlert(message, 'error');
- }
-}
-
-function viewImportLogs() {
- showAlert('Import logs functionality coming soon', 'info');
-}
function searchUsers() {
const searchTerm = document.getElementById('user-search').value.toLowerCase();
diff --git a/templates/documents.html b/templates/documents.html
index 6d35652..754290d 100644
--- a/templates/documents.html
+++ b/templates/documents.html
@@ -804,7 +804,7 @@ function clearUploadFileNo() {
async function loadTemplates() {
try {
- console.log('๐ DEBUG: loadTemplates() called');
+ // Loading templates...
const search = document.getElementById('templateSearch').value;
const category = document.getElementById('categoryFilter').value;
@@ -814,17 +814,17 @@ async function loadTemplates() {
// Ensure we have auth token for this API call
const token = localStorage.getItem('auth_token');
- console.log('๐ DEBUG: Token exists:', !!token, 'Length:', token?.length);
+ // Token validation
if (!token) {
- console.log('๐ DEBUG: No token found, redirecting to login');
+ // No token found, redirecting to login
window.location.href = '/login';
return;
}
- console.log('๐ DEBUG: Making API call to:', url);
+ // Making API call
const response = await window.http.wrappedFetch(url);
- console.log('๐ DEBUG: Response status:', response.status);
+ // Processing response
if (!response.ok) {
const errorData = await response.json().catch(() => ({ detail: 'Unknown error' }));
@@ -832,10 +832,10 @@ async function loadTemplates() {
}
const templates = await response.json();
- console.log('๐ DEBUG: Templates loaded:', templates.length, 'items');
+ // Templates loaded successfully
displayTemplates(templates);
} catch (error) {
- console.error('๐ DEBUG: Error in loadTemplates:', error);
+ console.error('Error in loadTemplates:', error);
try { logClientError({ message: 'Error loading templates', action: 'loadTemplates', error }); } catch (_) {}
showAlert('Error loading templates: ' + (error && error.message ? error.message : 'Unknown error'), 'danger');
}