Add visualization_tool/js/app.js
This commit is contained in:
parent
5e13076af4
commit
58df668499
1 changed files with 65 additions and 0 deletions
65
visualization_tool/js/app.js
Normal file
65
visualization_tool/js/app.js
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file js/app.js
|
||||||
|
* @description Hauptinitialisierungsskript: Setup von Events, Laden erster Daten, Koordination zwischen Modulen.
|
||||||
|
* @module app
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { fetchRunData } from './api.js';
|
||||||
|
import { renderCharts, updateCharts } from './chartRenderer.js';
|
||||||
|
import { setupDashboardSummary } from './dashboardSummary.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Liest aktuelle Filterwerte aus dem UI aus.
|
||||||
|
* @returns {{run?: string, policy_hash?: string, filter_pinned?: boolean|null}}
|
||||||
|
*/
|
||||||
|
function getCurrentFilters() {
|
||||||
|
const runInput = document.getElementById('filter-run');
|
||||||
|
const hashInput = document.getElementById('filter-policy-hash');
|
||||||
|
const pinnedInput = document.getElementById('filter-pinned');
|
||||||
|
|
||||||
|
return {
|
||||||
|
run: runInput?.value?.trim() || undefined,
|
||||||
|
policy_hash: hashInput?.value?.trim() || undefined,
|
||||||
|
filter_pinned: pinnedInput?.checked ?? null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reagiert auf Filteränderungen in der Sidebar, triggert neuen Datenabruf und Aktualisierung der Visualisierungen.
|
||||||
|
* @param {Event} event
|
||||||
|
*/
|
||||||
|
export async function handleFilterChange(event) {
|
||||||
|
event?.preventDefault?.();
|
||||||
|
|
||||||
|
const filters = getCurrentFilters();
|
||||||
|
try {
|
||||||
|
const data = await fetchRunData(filters);
|
||||||
|
updateCharts(data);
|
||||||
|
setupDashboardSummary(data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Fehler beim Aktualisieren der Daten:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialisiert die Anwendung, ruft erste Daten ab und bindet Event-Listener an die Filter.
|
||||||
|
*/
|
||||||
|
export async function initApp() {
|
||||||
|
const filterForm = document.getElementById('filter-form');
|
||||||
|
|
||||||
|
if (filterForm) {
|
||||||
|
filterForm.addEventListener('input', handleFilterChange);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const initialData = await fetchRunData({});
|
||||||
|
renderCharts(initialData);
|
||||||
|
setupDashboardSummary(initialData);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Fehler bei der Initialisierung der Anwendung:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('load', initApp);
|
||||||
Loading…
Reference in a new issue