🎉 Improved codebase structure & documentation 🖥️📚

This commit is contained in:
2025-06-01 01:54:09 +02:00
parent b9b64c9f98
commit 35caefdbfd
40 changed files with 3745 additions and 24 deletions

View File

@ -1315,7 +1315,7 @@ document.addEventListener('DOMContentLoaded', function() {
document.getElementById('exportEndDate').value = endDate.toISOString().split('T')[0];
};
window.performExport = async function() {
window.performExport = async function(retryCount = 0) {
try {
// Export-Parameter sammeln
const format = document.querySelector('input[name="exportFormat"]:checked').value;
@ -1349,12 +1349,19 @@ document.addEventListener('DOMContentLoaded', function() {
const exportButton = document.querySelector('button[onclick="performExport()"]');
const originalHTML = exportButton.innerHTML;
exportButton.disabled = true;
// Retry-spezifische Loading-Anzeige
let loadingText = 'Exportiere...';
if (retryCount > 0) {
loadingText = `Wiederhole Export (${retryCount}/3)...`;
}
exportButton.innerHTML = `
<svg class="animate-spin w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
</svg>
Exportiere...
${loadingText}
`;
// Export-Request
@ -1386,23 +1393,87 @@ document.addEventListener('DOMContentLoaded', function() {
window.URL.revokeObjectURL(url);
// Erfolg anzeigen
showSuccessNotification(`📊 ${format.toUpperCase()}-Export erfolgreich heruntergeladen`);
let successMessage = `📊 ${format.toUpperCase()}-Export erfolgreich heruntergeladen`;
if (retryCount > 0) {
successMessage += ` (nach ${retryCount} Wiederholung${retryCount > 1 ? 'en' : ''})`;
}
showSuccessNotification(successMessage);
hideExportModal();
} else if (response.status === 404 && retryCount < 3) {
// Temporärer 404-Fehler: Automatische Wiederholung
console.warn(`Temporärer 404-Fehler beim Export (Versuch ${retryCount + 1}/3). Wiederhole in 2 Sekunden...`);
// Button-Text für Retry aktualisieren
exportButton.innerHTML = `
<svg class="animate-pulse w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
Wiederhole in 2s...
`;
// Nach 2 Sekunden automatisch wiederholen
setTimeout(() => {
window.performExport(retryCount + 1);
}, 2000);
return; // Nicht den finally-Block ausführen
} else if (response.status === 401 || response.status === 302) {
// Authentifizierung erforderlich
showErrorNotification('⚠️ Sitzung abgelaufen. Bitte melden Sie sich erneut an.');
// Optional: Automatische Weiterleitung zur Login-Seite
setTimeout(() => {
window.location.href = '/auth/login?next=' + encodeURIComponent(window.location.pathname);
}, 2000);
} else {
const errorData = await response.json();
throw new Error(errorData.error || 'Export fehlgeschlagen');
const errorData = await response.json().catch(() => null);
const errorMessage = errorData?.error || `HTTP ${response.status}: ${response.statusText}`;
throw new Error(errorMessage);
}
} catch (error) {
console.error('Export-Fehler:', error);
showErrorNotification(`Export fehlgeschlagen: ${error.message}`);
// Bei Netzwerkfehlern oder anderen temporären Problemen: Retry
if ((error.name === 'NetworkError' || error.message.includes('fetch')) && retryCount < 3) {
console.warn(`Netzwerkfehler beim Export (Versuch ${retryCount + 1}/3). Wiederhole in 3 Sekunden...`);
const exportButton = document.querySelector('button[onclick="performExport()"]');
exportButton.innerHTML = `
<svg class="animate-pulse w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
Netzwerkfehler - Wiederhole in 3s...
`;
setTimeout(() => {
window.performExport(retryCount + 1);
}, 3000);
return; // Nicht den finally-Block ausführen
}
// Finaler Fehler nach allen Retry-Versuchen
let errorMessage = `Export fehlgeschlagen: ${error.message}`;
if (retryCount > 0) {
errorMessage = `Export nach ${retryCount} Wiederholung${retryCount > 1 ? 'en' : ''} fehlgeschlagen: ${error.message}`;
}
showErrorNotification(errorMessage);
} finally {
// Loading-State zurücksetzen
// Loading-State zurücksetzen (nur wenn kein Retry läuft)
const exportButton = document.querySelector('button[onclick="performExport()"]');
if (exportButton) {
if (exportButton && !exportButton.innerHTML.includes('Wiederhole')) {
exportButton.disabled = false;
exportButton.innerHTML = originalHTML;
exportButton.innerHTML = `
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
</svg>
Export starten
`;
}
}
};