-
Keine Aktivitäten gefunden
-
- `;
- }
- } catch (error) {
- console.error('Error loading activities:', error);
- container.innerHTML = `
-
-
Fehler beim Laden der Aktivitäten
-
- `;
- }
-}
-
-async function loadSystemStatus() {
- try {
- const response = await fetch('/api/stats');
-
- if (!response.ok) {
- throw new Error(`HTTP ${response.status}: ${response.statusText}`);
- }
-
- const data = await response.json();
-
- // Prüfen ob data gültig ist
- if (!data || typeof data !== 'object') {
- throw new Error('Ungültige Antwort vom Server erhalten');
- }
-
- // Update system stats mit Fallback-Werten
- const totalPrintTimeEl = document.getElementById('total-print-time');
- if (totalPrintTimeEl) {
- totalPrintTimeEl.textContent = formatPrintTime(data.total_print_time_hours);
- }
-
- const completedJobsEl = document.getElementById('completed-jobs-count');
- if (completedJobsEl) {
- completedJobsEl.textContent = data.total_jobs_completed || 0;
- }
-
- const totalMaterialEl = document.getElementById('total-material-used');
- if (totalMaterialEl) {
- totalMaterialEl.textContent = formatMaterialUsed(data.total_material_used);
- }
-
- const lastUpdatedEl = document.getElementById('last-updated-time');
- if (lastUpdatedEl) {
- lastUpdatedEl.textContent = data.last_updated ? formatDateTime(data.last_updated) : '-';
- }
-
- console.log('✅ Systemstatus erfolgreich geladen:', data);
- } catch (error) {
- console.error('Error loading system status:', error);
- const errorMessage = error.message || 'Unbekannter Systemfehler';
- showToast(`Fehler beim Laden des Systemstatus: ${errorMessage}`, 'error');
-
- // Fallback-Werte anzeigen
- const elements = [
- 'total-print-time',
- 'completed-jobs-count',
- 'total-material-used',
- 'last-updated-time'
- ];
-
- elements.forEach(id => {
- const el = document.getElementById(id);
- if (el) {
- el.textContent = 'Fehler beim Laden';
- el.classList.add('text-red-500');
- }
- });
- }
-}
-
-function formatPrintTime(hours) {
- if (!hours) return '-';
- return `${hours} Stunden`;
-}
-
-function formatMaterialUsed(grams) {
- if (!grams) return '-';
- return `${grams} g`;
-}
-
-function formatDateTime(dateString) {
- if (!dateString) return '-';
-
- const date = new Date(dateString);
- return date.toLocaleString('de-DE', {
- year: 'numeric',
- month: '2-digit',
- day: '2-digit',
- hour: '2-digit',
- minute: '2-digit'
- });
-}
-
-/**
- * Global refresh function
- */
-function refreshAllData() {
- // Get active section
- const activeSection = document.querySelector('.admin-section.active');
- if (activeSection) {
- const sectionId = activeSection.id;
- const section = sectionId.replace('-section', '');
-
- // Reload data based on active section
- switch(section) {
- case 'dashboard':
- loadDashboardData();
- break;
- case 'users':
- loadUsers();
- break;
- case 'printers':
- loadPrinters();
- break;
- case 'scheduler':
- loadSchedulerStatus();
- break;
- case 'logs':
- loadLogs();
- break;
- }
- }
-
- showToast('Daten aktualisiert', 'success');
-}
-/**
- * Benutzer laden und anzeigen
- */
-function loadUsers() {
- const usersContainer = document.getElementById('users-container');
- if (!usersContainer) return;
-
- // Lade-Animation anzeigen
- usersContainer.innerHTML = `
-
-
Fehler beim Laden der Benutzer
-
${error.message}
-
-
- `;
- });
-}
-
-/**
- * Drucker laden und anzeigen
- */
-function loadPrinters() {
- const printersContainer = document.getElementById('printers-container');
- if (!printersContainer) return;
-
- // Lade-Animation anzeigen
- printersContainer.innerHTML = `
-
-
Fehler beim Laden der Drucker
-
${error.message}
-
-
- `;
- });
-}
-
-/**
- * Scheduler-Status laden und anzeigen
- */
-function loadSchedulerStatus() {
- const schedulerContainer = document.getElementById('scheduler-container');
- if (!schedulerContainer) return;
-
- // Lade-Animation anzeigen
- schedulerContainer.innerHTML = `
-
-
Fehler beim Laden des Scheduler-Status
-
${error.message}
-
-
- `;
- });
-}
-
-/**
- * Logs laden und anzeigen
- */
-function loadLogs() {
- const logsContainer = document.getElementById('logs-container');
- if (!logsContainer) return;
-
- // Lade-Animation anzeigen
- logsContainer.innerHTML = `
-
-
Fehler beim Laden der Logs
-
${error.message}
-
-
- `;
- });
-}
\ No newline at end of file
diff --git a/backend/static/js/admin-live.js b/backend/static/js/admin-live.js
deleted file mode 100644
index e4b56660..00000000
--- a/backend/static/js/admin-live.js
+++ /dev/null
@@ -1,585 +0,0 @@
-/**
- * Mercedes-Benz MYP Admin Live Dashboard
- * Echtzeit-Updates für das Admin Panel mit echten Daten
- */
-
-class AdminLiveDashboard {
- constructor() {
- this.isLive = false;
- this.updateInterval = null;
- this.retryCount = 0;
- this.maxRetries = 3;
-
- // Dynamische API-Base-URL-Erkennung
- this.apiBaseUrl = this.detectApiBaseUrl();
- console.log('🔗 API Base URL erkannt:', this.apiBaseUrl);
-
- this.init();
- }
-
- detectApiBaseUrl() {
- const currentHost = window.location.hostname;
- const currentProtocol = window.location.protocol;
- const currentPort = window.location.port;
-
- console.log('🔍 Live Dashboard API URL Detection:', { currentHost, currentProtocol, currentPort });
-
- // Prüfe ob wir bereits auf dem richtigen Port sind
- if (currentPort === '5000') {
- console.log('✅ Verwende relative URLs (bereits auf Port 5000)');
- return '';
- }
-
- // Für Entwicklung: Verwende HTTP Port 5000
- const devUrl = `http://${currentHost}:5000`;
- console.log('🔄 Fallback zu HTTP:5000:', devUrl);
-
- return devUrl;
- }
-
- init() {
- console.log('🚀 Mercedes-Benz MYP Admin Live Dashboard gestartet');
-
- // Live-Status anzeigen
- this.updateLiveTime();
- this.startLiveUpdates();
-
- // Event Listeners
- this.bindEvents();
-
- // Initial Load
- this.loadLiveStats();
-
- // Error Monitoring System
- this.initErrorMonitoring();
- }
-
- bindEvents() {
- // Quick Action Buttons
- const systemStatusBtn = document.getElementById('system-status-btn');
- const analyticsBtn = document.getElementById('analytics-btn');
- const maintenanceBtn = document.getElementById('maintenance-btn');
-
- if (systemStatusBtn) {
- systemStatusBtn.addEventListener('click', () => this.showSystemStatus());
- }
-
- if (analyticsBtn) {
- analyticsBtn.addEventListener('click', () => this.showAnalytics());
- }
-
- if (maintenanceBtn) {
- maintenanceBtn.addEventListener('click', () => this.showMaintenance());
- }
-
- // Page Visibility API für optimierte Updates
- document.addEventListener('visibilitychange', () => {
- if (document.hidden) {
- this.pauseLiveUpdates();
- } else {
- this.resumeLiveUpdates();
- }
- });
- }
-
- startLiveUpdates() {
- this.isLive = true;
- this.updateLiveIndicator(true);
-
- // Live Stats alle 30 Sekunden aktualisieren
- this.updateInterval = setInterval(() => {
- this.loadLiveStats();
- }, 30000);
-
- // Zeit jede Sekunde aktualisieren
- setInterval(() => {
- this.updateLiveTime();
- }, 1000);
- }
-
- pauseLiveUpdates() {
- this.isLive = false;
- this.updateLiveIndicator(false);
- if (this.updateInterval) {
- clearInterval(this.updateInterval);
- }
- }
-
- resumeLiveUpdates() {
- if (!this.isLive) {
- this.startLiveUpdates();
- this.loadLiveStats(); // Sofortiges Update beim Fortsetzen
- }
- }
-
- updateLiveIndicator(isLive) {
- const indicator = document.getElementById('live-indicator');
- if (indicator) {
- if (isLive) {
- indicator.className = 'w-2 h-2 bg-green-400 rounded-full animate-pulse';
- } else {
- indicator.className = 'w-2 h-2 bg-gray-400 rounded-full';
- }
- }
- }
-
- updateLiveTime() {
- const timeElement = document.getElementById('live-time');
- if (timeElement) {
- const now = new Date();
- timeElement.textContent = now.toLocaleTimeString('de-DE');
- }
- }
-
- async loadLiveStats() {
- try {
- const url = `${this.apiBaseUrl}/api/admin/stats/live`;
- console.log('🔄 Lade Live-Statistiken von:', url);
-
- const response = await fetch(url, {
- method: 'GET',
- headers: {
- 'Content-Type': 'application/json',
- 'X-CSRFToken': this.getCSRFToken()
- }
- });
-
- if (!response.ok) {
- throw new Error(`HTTP ${response.status}: ${response.statusText}`);
- }
-
- const data = await response.json();
-
- if (data.success) {
- this.updateStatsDisplay(data);
- this.retryCount = 0; // Reset retry count on success
-
- // Success notification (optional)
- this.showQuietNotification('Live-Daten aktualisiert', 'success');
- } else {
- throw new Error(data.error || 'Unbekannter Fehler beim Laden der Live-Statistiken');
- }
-
- } catch (error) {
- console.error('Fehler beim Laden der Live-Statistiken:', error);
-
- this.retryCount++;
- if (this.retryCount <= this.maxRetries) {
- console.log(`Versuche erneut... (${this.retryCount}/${this.maxRetries})`);
- setTimeout(() => this.loadLiveStats(), 5000); // Retry nach 5 Sekunden
- } else {
- this.handleConnectionError();
- }
- }
- }
-
- updateStatsDisplay(data) {
- // Benutzer Stats
- this.updateCounter('live-users-count', data.total_users);
- this.updateProgress('users-progress', Math.min((data.total_users / 20) * 100, 100)); // Max 20 users = 100%
-
- // Drucker Stats
- this.updateCounter('live-printers-count', data.total_printers);
- this.updateElement('live-printers-online', `${data.online_printers} online`);
- if (data.total_printers > 0) {
- this.updateProgress('printers-progress', (data.online_printers / data.total_printers) * 100);
- }
-
- // Jobs Stats
- this.updateCounter('live-jobs-active', data.active_jobs);
- this.updateElement('live-jobs-queued', `${data.queued_jobs} in Warteschlange`);
- this.updateProgress('jobs-progress', Math.min(data.active_jobs * 20, 100)); // Max 5 jobs = 100%
-
- // Erfolgsrate Stats
- this.updateCounter('live-success-rate', `${data.success_rate}%`);
- this.updateProgress('success-progress', data.success_rate);
-
- // Trend Analysis
- this.updateSuccessTrend(data.success_rate);
-
- console.log('📊 Live-Statistiken aktualisiert:', data);
- }
-
- updateCounter(elementId, newValue) {
- const element = document.getElementById(elementId);
- if (element) {
- const currentValue = parseInt(element.textContent) || 0;
- if (currentValue !== newValue) {
- this.animateCounter(element, currentValue, newValue);
- }
- }
- }
-
- animateCounter(element, from, to) {
- const duration = 1000; // 1 Sekunde
- const increment = (to - from) / (duration / 16); // 60 FPS
- let current = from;
-
- const timer = setInterval(() => {
- current += increment;
- if ((increment > 0 && current >= to) || (increment < 0 && current <= to)) {
- current = to;
- clearInterval(timer);
- }
- element.textContent = Math.round(current);
- }, 16);
- }
-
- updateElement(elementId, newValue) {
- const element = document.getElementById(elementId);
- if (element && element.textContent !== newValue) {
- element.textContent = newValue;
- }
- }
-
- updateProgress(elementId, percentage) {
- const element = document.getElementById(elementId);
- if (element) {
- element.style.width = `${Math.max(0, Math.min(100, percentage))}%`;
- }
- }
-
- updateSuccessTrend(successRate) {
- const trendElement = document.getElementById('success-trend');
- if (trendElement) {
- let trendText = 'Stabil';
- let trendClass = 'text-green-500';
- let trendIcon = 'M5 10l7-7m0 0l7 7m-7-7v18'; // Up arrow
-
- if (successRate >= 95) {
- trendText = 'Excellent';
- trendClass = 'text-green-600';
- } else if (successRate >= 80) {
- trendText = 'Gut';
- trendClass = 'text-green-500';
- } else if (successRate >= 60) {
- trendText = 'Mittel';
- trendClass = 'text-yellow-500';
- trendIcon = 'M5 12h14'; // Horizontal line
- } else {
- trendText = 'Niedrig';
- trendClass = 'text-red-500';
- trendIcon = 'M19 14l-7 7m0 0l-7-7m7 7V3'; // Down arrow
- }
-
- trendElement.className = `text-sm ${trendClass}`;
- trendElement.innerHTML = `
-
-
Fehler beim Laden der Logs
-
${error.message}
-
-
- `;
- }
-}
-
-// Logs rendern
-function renderLogs() {
- const logsContainer = document.getElementById('logs-container');
- if (!logsContainer || !window.filteredLogs) return;
-
- if (window.filteredLogs.length === 0) {
- logsContainer.innerHTML = `
-