📚 Improved logging structure & added backup file 🔜

This commit is contained in:
2025-06-01 14:39:46 +02:00
parent 3287b4558b
commit 7fa7da74af
29 changed files with 1139 additions and 64 deletions

View File

@ -625,27 +625,50 @@ class MaintenanceModal {
this.closeBtn = document.getElementById('close-maintenance-modal');
this.isOpen = false;
this.isLoading = false;
this.isInitialized = false;
// Verhindere doppelte Initialisierung
if (window.maintenanceModalInstance) {
return window.maintenanceModalInstance;
}
this.initializeEventListeners();
this.isInitialized = true;
window.maintenanceModalInstance = this;
}
initializeEventListeners() {
// Modal öffnen
// Modal öffnen - mit Event-Delegation und Konflikt-Vermeidung
if (this.triggerBtn) {
this.triggerBtn.addEventListener('click', (e) => {
// Entferne alle existierenden Event-Listener
this.triggerBtn.removeEventListener('click', this.handleTriggerClick);
// Füge neuen Event-Listener hinzu
this.handleTriggerClick = (e) => {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
console.log('🛠️ Wartungs-Modal wird geöffnet...');
this.openModal();
});
};
this.triggerBtn.addEventListener('click', this.handleTriggerClick, { capture: true });
}
// Modal schließen
if (this.closeBtn) {
this.closeBtn.addEventListener('click', () => this.closeModal());
this.closeBtn.addEventListener('click', (e) => {
e.preventDefault();
e.stopPropagation();
this.closeModal();
});
}
// Modal schließen bei Klick außerhalb
// Modal schließen bei Klick außerhalb - aber nur auf das Overlay
if (this.modal) {
this.modal.addEventListener('click', (e) => {
// Nur schließen wenn direkt auf das Modal-Overlay geklickt wird
if (e.target === this.modal) {
this.closeModal();
}
@ -655,6 +678,7 @@ class MaintenanceModal {
// ESC-Taste zum Schließen
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && this.isOpen) {
e.preventDefault();
this.closeModal();
}
});
@ -665,36 +689,59 @@ class MaintenanceModal {
initializeMaintenanceActions() {
const actions = [
{ id: 'modal-clear-cache', handler: () => this.executeAction('clearCache') },
{ id: 'modal-optimize-db', handler: () => this.executeAction('optimizeDatabase') },
{ id: 'modal-create-backup', handler: () => this.executeAction('createBackup') },
{ id: 'modal-advanced-settings', handler: () => this.navigateToSettings() }
{ id: 'modal-clear-cache', handler: (e) => {
e.preventDefault();
e.stopPropagation();
this.executeAction('clearCache');
}},
{ id: 'modal-optimize-db', handler: (e) => {
e.preventDefault();
e.stopPropagation();
this.executeAction('optimizeDatabase');
}},
{ id: 'modal-create-backup', handler: (e) => {
e.preventDefault();
e.stopPropagation();
this.executeAction('createBackup');
}},
{ id: 'modal-advanced-settings', handler: (e) => {
e.preventDefault();
e.stopPropagation();
this.navigateToSettings();
}}
];
actions.forEach(action => {
const element = document.getElementById(action.id);
if (element) {
// Entferne existierende Event-Listener
element.removeEventListener('click', action.handler);
// Füge neuen Event-Listener hinzu
element.addEventListener('click', action.handler);
}
});
}
openModal() {
if (this.modal) {
if (this.modal && !this.isOpen) {
console.log('✅ Modal wird geöffnet');
this.modal.classList.remove('hidden');
this.isOpen = true;
document.body.style.overflow = 'hidden';
// Focus-Management für Barrierefreiheit
const firstFocusable = this.modal.querySelector('button');
if (firstFocusable) {
firstFocusable.focus();
}
setTimeout(() => {
const firstFocusable = this.modal.querySelector('button:not(#close-maintenance-modal)');
if (firstFocusable) {
firstFocusable.focus();
}
}, 100);
}
}
closeModal() {
if (this.modal) {
if (this.modal && this.isOpen) {
console.log('❌ Modal wird geschlossen');
this.modal.classList.add('hidden');
this.isOpen = false;
document.body.style.overflow = '';
@ -793,7 +840,7 @@ class MaintenanceModal {
if (response.ok && result.success) {
showNotification(successMessage, 'success');
this.closeModal();
// Modal NICHT automatisch schließen - Benutzer soll entscheiden
} else {
showNotification(result.message || 'Fehler bei der Ausführung der Wartungsaktion', 'error');
}
@ -820,11 +867,31 @@ class MaintenanceModal {
// Globale Wartungs-Modal Instanz
let maintenanceModal = null;
// Initialisierung nach DOM-Laden
// Initialisierung nach DOM-Laden - aber nur einmal
document.addEventListener('DOMContentLoaded', function() {
// Nur einmal initialisieren
if (!maintenanceModal) {
// Verhindere doppelte Initialisierung
if (!window.maintenanceModalInstance && !maintenanceModal) {
console.log('🔧 Wartungs-Modal wird initialisiert...');
maintenanceModal = new MaintenanceModal();
// Deaktiviere andere Event-Handler für den Wartungs-Button
const maintenanceBtn = document.getElementById('maintenance-btn');
if (maintenanceBtn) {
// Entferne alle anderen Event-Listener
const newBtn = maintenanceBtn.cloneNode(true);
maintenanceBtn.parentNode.replaceChild(newBtn, maintenanceBtn);
// Füge nur unseren Event-Listener hinzu
newBtn.addEventListener('click', (e) => {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
if (maintenanceModal) {
maintenanceModal.openModal();
}
}, { capture: true });
}
}
});