📝 "Refactor backend files
This commit is contained in:
@ -3,6 +3,72 @@
|
||||
* Sammelt alle Refresh-Funktionen für verschiedene Seiten und Komponenten
|
||||
*/
|
||||
|
||||
/**
|
||||
* Utility-Funktionen für robustes DOM-Element-Handling
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sicheres Aktualisieren von Element-Inhalten
|
||||
* @param {string} elementId - Die ID des Elements
|
||||
* @param {string|number} value - Der zu setzende Wert
|
||||
* @param {Object} options - Optionale Parameter
|
||||
* @returns {boolean} - true wenn erfolgreich, false wenn Element nicht gefunden
|
||||
*/
|
||||
function safeUpdateElement(elementId, value, options = {}) {
|
||||
const {
|
||||
fallbackValue = '-',
|
||||
logWarning = true,
|
||||
attribute = 'textContent',
|
||||
transform = null
|
||||
} = options;
|
||||
|
||||
const element = document.getElementById(elementId);
|
||||
if (!element) {
|
||||
if (logWarning) {
|
||||
console.warn(`🔍 Element mit ID '${elementId}' nicht gefunden`);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
const finalValue = value !== undefined && value !== null ? value : fallbackValue;
|
||||
const displayValue = transform ? transform(finalValue) : finalValue;
|
||||
|
||||
element[attribute] = displayValue;
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error(`❌ Fehler beim Aktualisieren von Element '${elementId}':`, error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sicheres Aktualisieren mehrerer Elemente
|
||||
* @param {Object} updates - Objekt mit elementId: value Paaren
|
||||
* @param {Object} options - Optionale Parameter
|
||||
*/
|
||||
function safeBatchUpdate(updates, options = {}) {
|
||||
const results = {};
|
||||
Object.entries(updates).forEach(([elementId, value]) => {
|
||||
results[elementId] = safeUpdateElement(elementId, value, options);
|
||||
});
|
||||
|
||||
const successful = Object.values(results).filter(Boolean).length;
|
||||
const total = Object.keys(updates).length;
|
||||
|
||||
console.log(`📊 Batch-Update: ${successful}/${total} Elemente erfolgreich aktualisiert`);
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüfen ob Element existiert
|
||||
* @param {string} elementId - Die ID des Elements
|
||||
* @returns {boolean} - true wenn Element existiert
|
||||
*/
|
||||
function elementExists(elementId) {
|
||||
return document.getElementById(elementId) !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dashboard-Refresh-Funktion
|
||||
*/
|
||||
@ -301,7 +367,10 @@ function updateDashboardStats(stats) {
|
||||
*/
|
||||
function updateStatsCounter(elementId, value, animate = true) {
|
||||
const element = document.getElementById(elementId);
|
||||
if (!element) return;
|
||||
if (!element) {
|
||||
console.warn(`Element mit ID '${elementId}' nicht gefunden`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (animate) {
|
||||
// Animierte Zählung
|
||||
|
Reference in New Issue
Block a user