🎉 Refactored backend structure: Removed unused files including app_cleaned.py, admin_api.py, admin.py, user.py, and others. Updated settings.local.json to include additional Bash commands. Enhanced admin templates for better navigation and functionality. Improved logging and error handling across various modules.
This commit is contained in:
@ -232,40 +232,44 @@ class AdminDashboard {
|
||||
}
|
||||
|
||||
attachModalEvents() {
|
||||
// Error-Alert Buttons
|
||||
this.addEventListenerSafe('#fix-errors-btn', 'click', (e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
this.fixErrors();
|
||||
});
|
||||
|
||||
this.addEventListenerSafe('#dismiss-errors-btn', 'click', (e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
this.dismissErrors();
|
||||
});
|
||||
|
||||
this.addEventListenerSafe('#view-error-details-btn', 'click', (e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
window.location.href = '/admin-dashboard?tab=logs';
|
||||
});
|
||||
|
||||
// Logs-Funktionalität
|
||||
// Logs-Funktionalität Event-Listener
|
||||
this.addEventListenerSafe('#refresh-logs-btn', 'click', (e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
this.loadLogs();
|
||||
});
|
||||
|
||||
|
||||
this.addEventListenerSafe('#export-logs-btn', 'click', (e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
this.exportLogs();
|
||||
});
|
||||
|
||||
|
||||
this.addEventListenerSafe('#log-level-filter', 'change', (e) => {
|
||||
this.loadLogs();
|
||||
e.preventDefault();
|
||||
const selectedLevel = e.target.value;
|
||||
this.loadLogs(selectedLevel);
|
||||
});
|
||||
|
||||
// Modal-bezogene Event-Listener (existierende)
|
||||
document.addEventListener('click', (e) => {
|
||||
// User-Modal schließen bei Klick außerhalb
|
||||
if (e.target.id === 'user-modal') {
|
||||
this.closeUserModal();
|
||||
}
|
||||
|
||||
// Printer-Modal schließen bei Klick außerhalb
|
||||
if (e.target.id === 'printer-modal') {
|
||||
this.closePrinterModal();
|
||||
}
|
||||
});
|
||||
|
||||
// ESC-Taste für Modal-Schließen
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Escape') {
|
||||
this.closeUserModal();
|
||||
this.closePrinterModal();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -301,28 +305,26 @@ class AdminDashboard {
|
||||
}
|
||||
|
||||
async loadInitialData() {
|
||||
await this.loadLiveStats();
|
||||
await this.checkSystemHealth();
|
||||
|
||||
// Button-Test ausführen
|
||||
setTimeout(() => {
|
||||
this.testButtons();
|
||||
}, 1000);
|
||||
|
||||
// Logs laden falls wir auf dem Logs-Tab sind
|
||||
if (window.location.search.includes('tab=logs') || document.querySelector('.tabs [href*="logs"]')?.classList.contains('active')) {
|
||||
await this.loadLogs();
|
||||
}
|
||||
// Prüfe auch ob der Logs-Tab durch die URL-Parameter aktiv ist
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const activeTab = urlParams.get('tab');
|
||||
if (activeTab === 'logs') {
|
||||
await this.loadLogs();
|
||||
}
|
||||
// Oder prüfe ob das Logs-Container-Element sichtbar ist
|
||||
const logsContainer = document.getElementById('logs-container');
|
||||
if (logsContainer && logsContainer.offsetParent !== null) {
|
||||
await this.loadLogs();
|
||||
try {
|
||||
console.log('📋 Lade initiale Admin-Daten...');
|
||||
|
||||
// Live-Statistiken laden
|
||||
await this.loadLiveStats();
|
||||
|
||||
// System-Health prüfen
|
||||
await this.checkSystemHealth();
|
||||
|
||||
// Falls wir auf der Logs-Seite sind, Logs laden
|
||||
const currentPath = window.location.pathname;
|
||||
if (currentPath.includes('/admin/logs') || document.querySelector('.admin-logs-tab')) {
|
||||
await this.loadLogs();
|
||||
}
|
||||
|
||||
console.log('✅ Initiale Admin-Daten geladen');
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Fehler beim Laden der initialen Daten:', error);
|
||||
this.showNotification('Fehler beim Laden der Admin-Daten', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
@ -1060,7 +1062,7 @@ class AdminDashboard {
|
||||
|
||||
try {
|
||||
const filter = level || document.getElementById('log-level-filter')?.value || 'all';
|
||||
const url = `${this.apiBaseUrl}/api/admin/logs?level=${filter}&limit=100`;
|
||||
const url = `${this.apiBaseUrl}/admin/api/logs?level=${filter}&limit=100`;
|
||||
|
||||
const response = await fetch(url, {
|
||||
headers: {
|
||||
@ -1203,30 +1205,42 @@ class AdminDashboard {
|
||||
this.showNotification('📥 Logs werden exportiert...', 'info');
|
||||
|
||||
const filter = document.getElementById('log-level-filter')?.value || 'all';
|
||||
const url = `${this.apiBaseUrl}/api/admin/logs/export?level=${filter}`;
|
||||
const url = `${this.apiBaseUrl}/admin/api/logs/export`;
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRFToken': this.csrfToken
|
||||
}
|
||||
},
|
||||
body: JSON.stringify({
|
||||
level: filter,
|
||||
format: 'csv'
|
||||
})
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
||||
}
|
||||
|
||||
// Download als Datei
|
||||
const blob = await response.blob();
|
||||
const downloadUrl = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = downloadUrl;
|
||||
a.download = `system-logs-${new Date().toISOString().split('T')[0]}.csv`;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
window.URL.revokeObjectURL(downloadUrl);
|
||||
const data = await response.json();
|
||||
|
||||
this.showNotification('✅ Logs erfolgreich exportiert!', 'success');
|
||||
if (data.success && data.content) {
|
||||
// Download als Datei
|
||||
const blob = new Blob([data.content], { type: data.content_type });
|
||||
const downloadUrl = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = downloadUrl;
|
||||
a.download = data.filename;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
window.URL.revokeObjectURL(downloadUrl);
|
||||
|
||||
this.showNotification('✅ Logs erfolgreich exportiert!', 'success');
|
||||
} else {
|
||||
throw new Error(data.error || 'Unbekannter Fehler beim Export');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Exportieren der Logs:', error);
|
||||
@ -1334,11 +1348,31 @@ class AdminDashboard {
|
||||
let adminDashboardInstance = null;
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
if (!adminDashboardInstance) {
|
||||
adminDashboardInstance = new AdminDashboard();
|
||||
window.AdminDashboard = adminDashboardInstance;
|
||||
console.log('🎯 Admin Dashboard erfolgreich initialisiert (unified)');
|
||||
// Verhindere doppelte Initialisierung
|
||||
if (window.adminDashboard) {
|
||||
console.log('⚠️ Admin Dashboard bereits initialisiert, überspringe...');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('🚀 Starte Mercedes-Benz MYP Admin Dashboard...');
|
||||
|
||||
// Dashboard erstellen
|
||||
window.adminDashboard = new AdminDashboard();
|
||||
|
||||
// Überprüfe, ob wir auf dem Logs-Tab sind und lade Logs
|
||||
setTimeout(() => {
|
||||
const currentUrl = window.location.pathname;
|
||||
const isLogsTab = currentUrl.includes('/admin/logs') ||
|
||||
document.querySelector('[href*="logs"]')?.closest('.bg-gradient-to-r') ||
|
||||
document.getElementById('logs-container');
|
||||
|
||||
if (isLogsTab) {
|
||||
console.log('📋 Logs-Tab erkannt, lade Logs...');
|
||||
window.adminDashboard.loadLogs();
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
console.log('✅ Admin Dashboard Initialisierung abgeschlossen');
|
||||
});
|
||||
|
||||
// Export für globalen Zugriff
|
||||
|
Reference in New Issue
Block a user