📚 Improved documentation and logs structure for better maintainability and troubleshooting. 🖥️🔍

This commit is contained in:
2025-06-01 04:46:49 +02:00
parent f0fe4c29d5
commit 3501bbfddf
30 changed files with 721 additions and 167 deletions

View File

@ -10,6 +10,10 @@ class GlassmorphismNotificationSystem {
this.soundEnabled = localStorage.getItem('myp-notification-sound') !== 'false';
this.animationsEnabled = !window.matchMedia('(prefers-reduced-motion: reduce)').matches;
// Callback-Registry für Actions hinzufügen
this.actionCallbacks = new Map();
this.callbackCounter = 0;
this.init();
this.setupGlobalFunctions();
this.injectStyles();
@ -49,6 +53,9 @@ class GlassmorphismNotificationSystem {
window.showPersistentAlert = this.showPersistentAlert.bind(this);
window.showConfirmationToast = this.showConfirmationToast.bind(this);
window.showProgressToast = this.showProgressToast.bind(this);
// Globale Callback-Ausführungsfunktion
window.executeNotificationCallback = this.executeCallback.bind(this);
}
setupEventListeners() {
@ -162,14 +169,23 @@ class GlassmorphismNotificationSystem {
}
createActionButtons(actions, toastId) {
return actions.map(action => `
<button class="toast-action-btn toast-action-${action.type || 'secondary'}"
onclick="${action.onClick}; ${action.closeAfter !== false ? `glassNotificationSystem.closeToast('${toastId}')` : ''}"
title="${action.title || action.text}">
${action.icon ? `<svg class="w-4 h-4">${action.icon}</svg>` : ''}
${action.text}
</button>
`).join('');
return actions.map(action => {
// Callback in Registry speichern falls vorhanden
let callbackId = '';
if (action.callback && typeof action.callback === 'function') {
callbackId = `callback-${++this.callbackCounter}`;
this.actionCallbacks.set(callbackId, action.callback);
}
return `
<button class="toast-action-btn toast-action-${action.type || 'secondary'}"
onclick="glassNotificationSystem.handleActionClick('${callbackId}', '${toastId}', ${action.closeAfter !== false})"
title="${action.title || action.text}">
${action.icon ? `<svg class="w-4 h-4">${action.icon}</svg>` : ''}
${action.text}
</button>
`;
}).join('');
}
getIconSvg(type) {
@ -299,6 +315,14 @@ class GlassmorphismNotificationSystem {
}
this.notifications.delete(toastId);
// Alle zugehörigen Callbacks löschen
this.actionCallbacks.forEach((callback, callbackId) => {
if (callbackId.includes(toastId)) {
this.actionCallbacks.delete(callbackId);
}
});
this.repositionAllToasts();
}
@ -331,21 +355,49 @@ class GlassmorphismNotificationSystem {
* Spezielle Toast-Typen
*/
showConfirmationToast(message, onConfirm, onCancel = null, options = {}) {
const confirmCallback = () => {
if (typeof onConfirm === 'function') {
try {
onConfirm();
} catch (error) {
console.error('Fehler beim Ausführen der Bestätigungslogik:', error);
}
}
};
const cancelCallback = () => {
if (typeof onCancel === 'function') {
try {
onCancel();
} catch (error) {
console.error('Fehler beim Ausführen der Abbruchlogik:', error);
}
}
};
const actions = [
{
text: options.confirmText || 'Bestätigen',
type: 'primary',
callback: confirmCallback,
closeAfter: true
}
];
// Cancel-Button nur hinzufügen wenn Callback vorhanden ist
if (onCancel || options.cancelText) {
actions.push({
text: options.cancelText || 'Abbrechen',
type: 'secondary',
callback: cancelCallback,
closeAfter: true
});
}
return this.showToast(message, 'warning', 0, {
persistent: true,
title: options.title || 'Bestätigung erforderlich',
actions: [
{
text: options.confirmText || 'Bestätigen',
type: 'primary',
onClick: `(${onConfirm.toString()})()`
},
{
text: options.cancelText || 'Abbrechen',
type: 'secondary',
onClick: onCancel ? `(${onCancel.toString()})()` : ''
}
],
actions: actions,
...options
});
}
@ -1485,6 +1537,43 @@ class GlassmorphismNotificationSystem {
document.head.appendChild(styles);
}
/**
* Behandelt Action-Button-Klicks
*/
handleActionClick(callbackId, toastId, shouldClose = true) {
// Callback ausführen falls vorhanden
if (callbackId && this.actionCallbacks.has(callbackId)) {
const callback = this.actionCallbacks.get(callbackId);
try {
callback();
} catch (error) {
console.error('Fehler beim Ausführen des Action-Callbacks:', error);
}
// Callback nach Ausführung löschen
this.actionCallbacks.delete(callbackId);
}
// Toast schließen falls gewünscht
if (shouldClose) {
this.closeToast(toastId);
}
}
/**
* Für Rückwärtskompatibilität - führt Callback-Funktionen aus
*/
executeCallback(callbackId) {
if (this.actionCallbacks.has(callbackId)) {
const callback = this.actionCallbacks.get(callbackId);
try {
callback();
} catch (error) {
console.error('Fehler beim Ausführen des Callbacks:', error);
}
this.actionCallbacks.delete(callbackId);
}
}
}
// Globale Instanz erstellen