Skip to content

Commit 932ff81

Browse files
author
jacquesbach
committed
Change layout.js
1 parent 8108c79 commit 932ff81

1 file changed

Lines changed: 52 additions & 1 deletion

File tree

static/js/layout.js

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,55 @@ async function resetDatabaseLayout() {
7676
if (res.ok) {
7777
location.reload(); // Seite neu laden, um Standard-HTML zu zeigen
7878
}
79-
}
79+
}
80+
81+
document.addEventListener("DOMContentLoaded", async () => {
82+
// --- PHASE 1: Das Gerüst aufbauen ---
83+
initGridstack();
84+
await loadLayout(); // Wartet, bis Boxen aus DB oder LocalStorage da sind
85+
86+
// --- PHASE 2: Startwerte für Datumsfelder setzen ---
87+
const t = new Date().toISOString().split('T')[0];
88+
const startInput = document.getElementById('start');
89+
const endInput = document.getElementById('end');
90+
91+
if (startInput && endInput) {
92+
startInput.value = t;
93+
endInput.value = t;
94+
startInput.addEventListener('change', updateQuickButtonsActiveState);
95+
endInput.addEventListener('change', updateQuickButtonsActiveState);
96+
}
97+
98+
// --- PHASE 3: Daten in die Boxen pumpen ---
99+
// Wir prüfen bei jeder Funktion, ob sie existiert, um Fehler zu vermeiden
100+
try {
101+
if (typeof fetchData === "function") await fetchData();
102+
if (typeof updateWeather === "function") updateWeather();
103+
if (typeof updateLive === "function") updateLive();
104+
if (typeof updatePeaks === "function") updatePeaks();
105+
if (typeof updateQuickButtonsActiveState === "function") updateQuickButtonsActiveState();
106+
107+
// ML-Funktionen
108+
if (typeof loadForecast === "function") loadForecast();
109+
if (typeof loadGlobalShap === "function") loadGlobalShap();
110+
if (typeof loadFeatureImportance === "function") loadFeatureImportance();
111+
112+
// Heatmaps
113+
if (typeof initHeatmapYears === "function") initHeatmapYears();
114+
if (typeof initHourlyHeatmap === "function") initHourlyHeatmap();
115+
116+
} catch (err) {
117+
console.error("Fehler beim initialen Daten-Load:", err);
118+
}
119+
120+
// --- PHASE 4: Intervalle für Updates starten ---
121+
setInterval(() => { if (typeof updateLive === "function") updateLive(); }, 5000);
122+
setInterval(() => { if (typeof fetchData === "function") fetchData(); }, 60000);
123+
setInterval(() => { if (typeof updatePeaks === "function") updatePeaks(); }, 60000);
124+
setInterval(() => { if (typeof checkLoadingStatus === "function") checkLoadingStatus(); }, 500);
125+
126+
// WICHTIG: Einmal kräftig schütteln, damit Charts ihre Größe im neuen Grid finden
127+
setTimeout(() => {
128+
window.dispatchEvent(new Event('resize'));
129+
}, 200);
130+
});

0 commit comments

Comments
 (0)