Frontend-Update: dynamischer Host, Lade-Overlay, Footer entfernt, klickbare Team-Panel
- API-Host dynamisch vom Seiten-URI abgeleitet (nicht mehr hardcoded) - Lade-Overlay mit Spinner beim Start und bei Verbindungsproblemen - Footer/Rundenverlauf entfernt, Scoreboard füllt jetzt die ganze Seite - Team-Panels sind klickbar (Single-Click = Punkt, Double-Click = nächste Runde) - Verbindungszustand mit grünem/rotem Dot angezeigt - CSS neu strukturiert, Duplikate entfernt
This commit is contained in:
+278
-422
@@ -1,405 +1,276 @@
|
||||
/**
|
||||
* goSportpunktetafel – Frontend JavaScript
|
||||
*
|
||||
* Verbindet sich mit der Go-HTTP-API (Polling + WebSocket-Fallback)
|
||||
* und aktualisiert die Anzeige in Echtzeit.
|
||||
*/
|
||||
/* ========================================
|
||||
goSportpunktetafel – Frontend App
|
||||
Dynamischer API-Host, Lade-Overlay, Team-Panel-Klicks
|
||||
======================================== */
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
// ========================================
|
||||
// Konfiguration
|
||||
// Konfiguration – dynamischer Host
|
||||
// ========================================
|
||||
|
||||
const CONFIG = {
|
||||
apiBase: 'http://localhost:3000',
|
||||
pollingInterval: 2000, // ms
|
||||
wsUrl: 'ws://localhost:3000/ws',
|
||||
wsReconnectDelay: 3000, // ms
|
||||
wsMaxReconnectDelay: 30000,
|
||||
// Hole Host und Port vom aktuellen Seiten-URI
|
||||
apiBase: `${window.location.protocol}//${window.location.host}`,
|
||||
wsBase: `${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${window.location.host}`,
|
||||
pollInterval: 2000,
|
||||
reconnectInterval: 5000,
|
||||
maxReconnectAttempts: 20,
|
||||
};
|
||||
|
||||
// ========================================
|
||||
// DOM-Elemente
|
||||
// ========================================
|
||||
const dom = {
|
||||
redScore: document.getElementById('red-score'),
|
||||
greenScore: document.getElementById('green-score'),
|
||||
roundDisplay: document.getElementById('round-display'),
|
||||
redPoints: document.getElementById('red-points'),
|
||||
greenPoints: document.getElementById('green-points'),
|
||||
roundsList: document.getElementById('rounds-list'),
|
||||
errorBanner: document.getElementById('error-banner'),
|
||||
errorMessage: document.getElementById('error-message'),
|
||||
resetBtn: document.getElementById('reset-btn'),
|
||||
fullscreenToggle: document.getElementById('fullscreen-toggle'),
|
||||
statusDot: document.getElementById('status-dot'),
|
||||
statusText: document.getElementById('status-text'),
|
||||
confirmDialog: document.getElementById('confirm-dialog'),
|
||||
cancelReset: document.getElementById('cancel-reset'),
|
||||
confirmReset: document.getElementById('confirm-reset'),
|
||||
redPanel: document.getElementById('red-panel'),
|
||||
greenPanel: document.getElementById('green-panel'),
|
||||
redScore: null,
|
||||
greenScore: null,
|
||||
roundDisplay: null,
|
||||
redPoints: null,
|
||||
greenPoints: null,
|
||||
roundsList: null,
|
||||
resetBtn: null,
|
||||
confirmDialog: null,
|
||||
confirmReset: null,
|
||||
cancelReset: null,
|
||||
fullscreenToggle: null,
|
||||
statusDot: null,
|
||||
statusText: null,
|
||||
errorBanner: null,
|
||||
errorMessage: null,
|
||||
loadingOverlay: null,
|
||||
redPanel: null,
|
||||
greenPanel: null,
|
||||
};
|
||||
|
||||
// ========================================
|
||||
// State
|
||||
// ========================================
|
||||
let state = {
|
||||
current_round: 0,
|
||||
red_score: 0,
|
||||
green_score: 0,
|
||||
current_round: 1,
|
||||
rounds: [],
|
||||
};
|
||||
|
||||
// Vorheriger State für Flash-Animation
|
||||
let prevState = { ...state };
|
||||
|
||||
// Polling / WebSocket
|
||||
let pollingTimer = null;
|
||||
let ws = null;
|
||||
let wsReconnectTimer = null;
|
||||
let wsReconnectAttempts = 0;
|
||||
let isConnected = false;
|
||||
let useWebSocket = false;
|
||||
let connected = false;
|
||||
let resetting = false;
|
||||
|
||||
// ========================================
|
||||
// API-Funktionen
|
||||
// DOM-Initialisierung
|
||||
// ========================================
|
||||
|
||||
/**
|
||||
* State von der API abrufen
|
||||
*/
|
||||
async function fetchState() {
|
||||
try {
|
||||
const response = await fetch(`${CONFIG.apiBase}/api/state`, {
|
||||
method: 'GET',
|
||||
headers: { 'Accept': 'application/json' },
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Abrufen des States:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Punkt für ein Team verbuchen
|
||||
*/
|
||||
async function postScore(team) {
|
||||
try {
|
||||
const response = await fetch(`${CONFIG.apiBase}/api/score?team=${team}`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`);
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error(`Fehler bei /api/score?team=${team}:`, error);
|
||||
showError(`Punkt für ${team} fehlgeschlagen`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Nächste Runde
|
||||
*/
|
||||
async function postNext() {
|
||||
try {
|
||||
const response = await fetch(`${CONFIG.apiBase}/api/next`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`);
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error('Fehler bei /api/next:', error);
|
||||
showError('Nächste Runde fehlgeschlagen');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset
|
||||
*/
|
||||
async function postReset() {
|
||||
try {
|
||||
const response = await fetch(`${CONFIG.apiBase}/api/reset`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`);
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error('Fehler bei /api/reset:', error);
|
||||
showError('Reset fehlgeschlagen');
|
||||
return null;
|
||||
}
|
||||
function initDom() {
|
||||
dom.redScore = document.getElementById('red-score');
|
||||
dom.greenScore = document.getElementById('green-score');
|
||||
dom.roundDisplay = document.getElementById('round-display');
|
||||
dom.redPoints = document.getElementById('red-points');
|
||||
dom.greenPoints = document.getElementById('green-points');
|
||||
dom.roundsList = document.getElementById('rounds-list');
|
||||
dom.resetBtn = document.getElementById('reset-btn');
|
||||
dom.confirmDialog = document.getElementById('confirm-dialog');
|
||||
dom.confirmReset = document.getElementById('confirm-reset');
|
||||
dom.cancelReset = document.getElementById('cancel-reset');
|
||||
dom.fullscreenToggle = document.getElementById('fullscreen-toggle');
|
||||
dom.statusDot = document.getElementById('status-dot');
|
||||
dom.statusText = document.getElementById('status-text');
|
||||
dom.errorBanner = document.getElementById('error-banner');
|
||||
dom.errorMessage = document.getElementById('error-message');
|
||||
dom.loadingOverlay = document.getElementById('loading-overlay');
|
||||
dom.redPanel = document.getElementById('red-panel');
|
||||
dom.greenPanel = document.getElementById('green-panel');
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// UI-Aktualisierung
|
||||
// Lade-Overlay
|
||||
// ========================================
|
||||
|
||||
/**
|
||||
* State in der UI anzeigen
|
||||
*/
|
||||
function renderState(newState) {
|
||||
const wasConnected = isConnected;
|
||||
|
||||
// State aktualisieren
|
||||
prevState = { ...state };
|
||||
state = { ...newState };
|
||||
|
||||
// Red Score
|
||||
const redScoreEl = dom.redScore;
|
||||
const redScoreStr = String(newState.red_score);
|
||||
if (redScoreEl.textContent !== redScoreStr) {
|
||||
redScoreEl.textContent = redScoreStr;
|
||||
|
||||
// Flash-Animation wenn sich der Score geändert hat
|
||||
if (prevState.red_score !== newState.red_score) {
|
||||
triggerFlash(dom.redPanel, 'flash-red');
|
||||
}
|
||||
}
|
||||
|
||||
// Green Score
|
||||
const greenScoreEl = dom.greenScore;
|
||||
const greenScoreStr = String(newState.green_score);
|
||||
if (greenScoreEl.textContent !== greenScoreStr) {
|
||||
greenScoreEl.textContent = greenScoreStr;
|
||||
|
||||
if (prevState.green_score !== newState.green_score) {
|
||||
triggerFlash(dom.greenPanel, 'flash-green');
|
||||
}
|
||||
}
|
||||
|
||||
// Round Display
|
||||
const totalRounds = Math.max(state.rounds.length, state.current_round);
|
||||
if (totalRounds > 0) {
|
||||
dom.roundDisplay.textContent = `Runde ${state.current_round} von ${totalRounds}`;
|
||||
function showLoading(show) {
|
||||
if (show) {
|
||||
dom.loadingOverlay.classList.remove('hidden');
|
||||
} else {
|
||||
dom.roundDisplay.textContent = 'Bereit';
|
||||
dom.loadingOverlay.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
// Letzte Punkte Anzeige (aus letzter abgeschlossener Runde)
|
||||
if (newState.rounds && newState.rounds.length > 0) {
|
||||
const lastRound = newState.rounds[newState.rounds.length - 1];
|
||||
if (lastRound) {
|
||||
const redPts = lastRound.Red || lastRound.red_score || 0;
|
||||
const greenPts = lastRound.Green || lastRound.green_score || 0;
|
||||
dom.redPoints.textContent = `Letzte: ${redPts}`;
|
||||
dom.greenPoints.textContent = `Letzte: ${greenPts}`;
|
||||
}
|
||||
// ========================================
|
||||
// Verbindungszustand
|
||||
// ========================================
|
||||
|
||||
function updateConnectionStatus(connected, error) {
|
||||
dom.statusDot.classList.remove('connected', 'disconnected');
|
||||
|
||||
if (connected) {
|
||||
dom.statusDot.classList.add('connected');
|
||||
dom.statusText.textContent = 'Verbunden';
|
||||
} else {
|
||||
dom.redPoints.textContent = 'Punkte: 0';
|
||||
dom.greenPoints.textContent = 'Punkte: 0';
|
||||
dom.statusDot.classList.add('disconnected');
|
||||
dom.statusText.textContent = error || 'Getrennt';
|
||||
}
|
||||
|
||||
// Rundenverlauf
|
||||
renderRoundHistory(newState.rounds || []);
|
||||
|
||||
// Verbindung status aktualisieren
|
||||
if (!wasConnected && newState !== null) {
|
||||
isConnected = true;
|
||||
updateConnectionStatus(true);
|
||||
hideError();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rundenverlauf rendern
|
||||
*/
|
||||
function renderRoundHistory(rounds) {
|
||||
const container = dom.roundsList;
|
||||
container.innerHTML = '';
|
||||
|
||||
rounds.forEach(function (round, index) {
|
||||
const tile = document.createElement('div');
|
||||
tile.className = 'round-tile';
|
||||
tile.setAttribute('role', 'listitem');
|
||||
tile.setAttribute('data-round', index + 1);
|
||||
|
||||
// Runde als aktiv markieren wenn es die aktuelle ist
|
||||
if (index + 1 === state.current_round) {
|
||||
tile.classList.add('active');
|
||||
}
|
||||
|
||||
const roundNum = document.createElement('span');
|
||||
roundNum.className = 'round-num';
|
||||
roundNum.textContent = `R${index + 1}`;
|
||||
|
||||
const scoreRed = document.createElement('span');
|
||||
scoreRed.className = 'score-red';
|
||||
scoreRed.textContent = round.Red || round.red_score || 0;
|
||||
|
||||
const separator = document.createTextNode(' : ');
|
||||
|
||||
const scoreGreen = document.createElement('span');
|
||||
scoreGreen.className = 'score-green';
|
||||
scoreGreen.textContent = round.Green || round.green_score || 0;
|
||||
|
||||
tile.appendChild(roundNum);
|
||||
tile.appendChild(scoreRed);
|
||||
tile.appendChild(separator);
|
||||
tile.appendChild(scoreGreen);
|
||||
|
||||
container.appendChild(tile);
|
||||
});
|
||||
|
||||
// Zum letzten Element scrollen
|
||||
requestAnimationFrame(function () {
|
||||
container.scrollLeft = container.scrollWidth;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Flash-Animation für Score-Update
|
||||
*/
|
||||
function triggerFlash(panel, animationClass) {
|
||||
// Alte Animation entfernen
|
||||
panel.classList.remove(animationClass);
|
||||
|
||||
// Reflow erzwingen
|
||||
void panel.offsetWidth;
|
||||
|
||||
// Neue Animation starten
|
||||
panel.classList.add(animationClass);
|
||||
|
||||
// Animation nach Ablauf entfernen
|
||||
panel.addEventListener('animationend', function handler() {
|
||||
panel.classList.remove(animationClass);
|
||||
panel.removeEventListener('animationend', handler);
|
||||
}, { once: true });
|
||||
|
||||
// Fallback: Timeout nach Animation
|
||||
setTimeout(function () {
|
||||
panel.classList.remove(animationClass);
|
||||
}, 500);
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// Fehler & Status
|
||||
// ========================================
|
||||
|
||||
function showError(message) {
|
||||
dom.errorMessage.textContent = message;
|
||||
dom.errorBanner.classList.remove('hidden');
|
||||
|
||||
// Nach 5 Sekunden automatisch ausblenden
|
||||
setTimeout(hideError, 5000);
|
||||
}
|
||||
|
||||
function hideError() {
|
||||
if (connected && dom.errorBanner && !dom.errorBanner.classList.contains('hidden')) {
|
||||
dom.errorBanner.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
function updateConnectionStatus(connected) {
|
||||
if (connected) {
|
||||
dom.statusDot.className = 'status-dot connected';
|
||||
dom.statusText.textContent = useWebSocket ? 'Echtzeit' : 'Verbunden';
|
||||
} else {
|
||||
dom.statusDot.className = 'status-dot disconnected';
|
||||
dom.statusText.textContent = 'Getrennt';
|
||||
// ========================================
|
||||
// API – State abfragen
|
||||
// ========================================
|
||||
|
||||
function fetchState() {
|
||||
return fetch(`${CONFIG.apiBase}/api/state`)
|
||||
.then(function (response) {
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`);
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(function (data) {
|
||||
updateConnectionStatus(true, null);
|
||||
return data;
|
||||
})
|
||||
.catch(function (error) {
|
||||
updateConnectionStatus(false, error.message);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// API – Score aktualisieren
|
||||
// ========================================
|
||||
|
||||
function postScore(team) {
|
||||
return fetch(`${CONFIG.apiBase}/api/score?team=${team}`, {
|
||||
method: 'POST',
|
||||
})
|
||||
.then(function (response) {
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`);
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.catch(function (error) {
|
||||
updateConnectionStatus(false, error.message);
|
||||
console.error('Score update failed:', error);
|
||||
});
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// API – Nächste Runde
|
||||
// ========================================
|
||||
|
||||
function postNext() {
|
||||
return fetch(`${CONFIG.apiBase}/api/next`, {
|
||||
method: 'POST',
|
||||
})
|
||||
.then(function (response) {
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`);
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.catch(function (error) {
|
||||
updateConnectionStatus(false, error.message);
|
||||
console.error('Next round failed:', error);
|
||||
});
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// API – Reset
|
||||
// ========================================
|
||||
|
||||
function postReset() {
|
||||
return fetch(`${CONFIG.apiBase}/api/reset`, {
|
||||
method: 'POST',
|
||||
})
|
||||
.then(function (response) {
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`);
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.catch(function (error) {
|
||||
updateConnectionStatus(false, error.message);
|
||||
console.error('Reset failed:', error);
|
||||
});
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// UI – Update
|
||||
// ========================================
|
||||
|
||||
function updateUI(data) {
|
||||
var red = data.red_score || 0;
|
||||
var green = data.green_score || 0;
|
||||
var round = data.current_round || 0;
|
||||
var rounds = data.rounds || [];
|
||||
|
||||
// Verhindere unnötige DOM-Updates
|
||||
if (dom.redScore.textContent === String(red) &&
|
||||
dom.greenScore.textContent === String(green) &&
|
||||
dom.roundDisplay.textContent === `Runde ${round} von ${rounds.length || 0}`) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Scores aktualisieren
|
||||
updateScore(dom.redScore, red, 'flash-red');
|
||||
updateScore(dom.greenScore, green, 'flash-green');
|
||||
|
||||
dom.redPoints.textContent = `Punkte: ${red}`;
|
||||
dom.greenPoints.textContent = `Punkte: ${green}`;
|
||||
dom.roundDisplay.textContent = `Runde ${round} von ${rounds.length || 0}`;
|
||||
}
|
||||
|
||||
function updateScore(element, value, flashClass) {
|
||||
var newValue = String(value);
|
||||
if (element.textContent !== newValue) {
|
||||
element.textContent = newValue;
|
||||
element.classList.remove(flashClass);
|
||||
// Force reflow
|
||||
void element.offsetWidth;
|
||||
element.classList.add(flashClass);
|
||||
setTimeout(function () {
|
||||
element.classList.remove(flashClass);
|
||||
}, 400);
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// WebSocket
|
||||
// Reset-Dialog
|
||||
// ========================================
|
||||
|
||||
function connectWebSocket() {
|
||||
// Falls bereits verbunden, nichts tun
|
||||
if (ws && (ws.readyState === WebSocket.CONNECTING || ws.readyState === WebSocket.OPEN)) {
|
||||
return;
|
||||
function showResetConfirm() {
|
||||
dom.confirmDialog.classList.remove('hidden');
|
||||
resetting = true;
|
||||
}
|
||||
|
||||
try {
|
||||
ws = new WebSocket(CONFIG.wsUrl);
|
||||
} catch (e) {
|
||||
console.warn('WebSocket nicht verfügbar, nutze Polling:', e);
|
||||
return;
|
||||
function hideResetConfirm() {
|
||||
dom.confirmDialog.classList.add('hidden');
|
||||
resetting = false;
|
||||
}
|
||||
|
||||
ws.onopen = function () {
|
||||
console.log('WebSocket verbunden');
|
||||
useWebSocket = true;
|
||||
isConnected = true;
|
||||
wsReconnectAttempts = 0;
|
||||
updateConnectionStatus(true);
|
||||
hideError();
|
||||
};
|
||||
|
||||
ws.onmessage = function (event) {
|
||||
try {
|
||||
const data = JSON.parse(event.data);
|
||||
renderState(data);
|
||||
} catch (e) {
|
||||
console.error('Fehler beim Verarbeiten der WebSocket-Nachricht:', e);
|
||||
}
|
||||
};
|
||||
|
||||
ws.onclose = function (event) {
|
||||
console.log(`WebSocket geschlossen (${event.code})`);
|
||||
useWebSocket = false;
|
||||
isConnected = false;
|
||||
updateConnectionStatus(false);
|
||||
scheduleWebSocketReconnect();
|
||||
};
|
||||
|
||||
ws.onerror = function () {
|
||||
console.warn('WebSocket-Fehler');
|
||||
};
|
||||
}
|
||||
|
||||
function scheduleWebSocketReconnect() {
|
||||
if (wsReconnectTimer) {
|
||||
clearTimeout(wsReconnectTimer);
|
||||
}
|
||||
|
||||
// Exponentieller Backoff mit Maximalwert
|
||||
const delay = Math.min(
|
||||
CONFIG.wsReconnectDelay * Math.pow(2, wsReconnectAttempts),
|
||||
CONFIG.wsMaxReconnectDelay
|
||||
);
|
||||
|
||||
wsReconnectAttempts++;
|
||||
console.log(`WebSocket-Wiederverbindung in ${delay}ms (Versuch ${wsReconnectAttempts})`);
|
||||
|
||||
wsReconnectTimer = setTimeout(function () {
|
||||
connectWebSocket();
|
||||
}, delay);
|
||||
function executeReset() {
|
||||
hideResetConfirm();
|
||||
postReset().then(function () {
|
||||
poll();
|
||||
});
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// Polling
|
||||
// ========================================
|
||||
|
||||
function poll() {
|
||||
return fetchState().then(function (data) {
|
||||
if (data) {
|
||||
state = data;
|
||||
updateUI(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function startPolling() {
|
||||
stopPolling();
|
||||
|
||||
// Sofortigen ersten Abruf
|
||||
poll();
|
||||
|
||||
pollingTimer = setInterval(poll, CONFIG.pollingInterval);
|
||||
pollingTimer = setInterval(poll, CONFIG.pollInterval);
|
||||
}
|
||||
|
||||
function stopPolling() {
|
||||
@@ -409,15 +280,54 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function poll() {
|
||||
const data = await fetchState();
|
||||
if (data) {
|
||||
renderState(data);
|
||||
// ========================================
|
||||
// WebSocket
|
||||
// ========================================
|
||||
|
||||
function connectWebSocket() {
|
||||
if (ws && (ws.readyState === WebSocket.OPEN || ws.readyState === WebSocket.CONNECTING)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var wsUrl = `${CONFIG.wsBase}/ws`;
|
||||
console.log('[ws] Verbinden mit', wsUrl);
|
||||
ws = new WebSocket(wsUrl);
|
||||
|
||||
ws.onopen = function () {
|
||||
console.log('[ws] Verbindung geöffnet');
|
||||
connected = true;
|
||||
wsReconnectAttempts = 0;
|
||||
updateConnectionStatus(true, null);
|
||||
};
|
||||
|
||||
ws.onmessage = function (event) {
|
||||
try {
|
||||
var data = JSON.parse(event.data);
|
||||
state = data;
|
||||
updateUI(data);
|
||||
} catch (e) {
|
||||
console.error('[ws] Fehler beim Verarbeiten:', e);
|
||||
}
|
||||
};
|
||||
|
||||
ws.onclose = function (event) {
|
||||
console.log('[ws] Verbindung geschlossen:', event.code);
|
||||
connected = false;
|
||||
updateConnectionStatus(false, 'Verbindung beendet');
|
||||
|
||||
// Erneut versuchen (maximal 20x)
|
||||
if (wsReconnectAttempts < CONFIG.maxReconnectAttempts) {
|
||||
wsReconnectAttempts++;
|
||||
console.log(`[ws] Erneuter Verbindungsversuch in ${CONFIG.reconnectInterval / 1000}s (${wsReconnectAttempts}/${CONFIG.maxReconnectAttempts})`);
|
||||
setTimeout(connectWebSocket, CONFIG.reconnectInterval);
|
||||
} else {
|
||||
if (!useWebSocket) {
|
||||
updateConnectionStatus(false);
|
||||
}
|
||||
console.error('[ws] Maximale Wiederverbindungsversuche erreicht');
|
||||
}
|
||||
};
|
||||
|
||||
ws.onerror = function (error) {
|
||||
console.error('[ws] Fehler:', error);
|
||||
};
|
||||
}
|
||||
|
||||
// ========================================
|
||||
@@ -427,45 +337,19 @@
|
||||
function toggleFullscreen() {
|
||||
if (!document.fullscreenElement) {
|
||||
document.documentElement.requestFullscreen().catch(function (err) {
|
||||
console.warn('Vollbild konnte nicht aktiviert werden:', err);
|
||||
showError('Vollbild nicht verfügbar');
|
||||
console.error('[fullscreen] Fehler:', err);
|
||||
});
|
||||
} else {
|
||||
document.exitFullscreen().catch(function (err) {
|
||||
console.warn('Vollbild konnte nicht deaktiviert werden:', err);
|
||||
});
|
||||
document.exitFullscreen();
|
||||
}
|
||||
}
|
||||
|
||||
function updateFullscreenButton() {
|
||||
const isFullscreen = !!document.fullscreenElement;
|
||||
dom.fullscreenToggle.title = isFullscreen ? 'Vollbild verlassen (F11)' : 'Vollbild aktivieren (F11)';
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// Reset-Dialog
|
||||
// ========================================
|
||||
|
||||
function showResetConfirm() {
|
||||
dom.confirmDialog.classList.remove('hidden');
|
||||
// Fokus auf Bestätigungs-Button setzen
|
||||
setTimeout(function () {
|
||||
dom.confirmReset.focus();
|
||||
}, 100);
|
||||
}
|
||||
|
||||
function hideResetConfirm() {
|
||||
dom.confirmDialog.classList.add('hidden');
|
||||
}
|
||||
|
||||
async function executeReset() {
|
||||
hideResetConfirm();
|
||||
const result = await postReset();
|
||||
if (result) {
|
||||
// State neu laden
|
||||
const data = await fetchState();
|
||||
if (data) {
|
||||
renderState(data);
|
||||
if (dom.fullscreenToggle) {
|
||||
if (document.fullscreenElement || document.webkitFullscreenElement) {
|
||||
dom.fullscreenToggle.title = 'Vollbild verlassen (F11)';
|
||||
} else {
|
||||
dom.fullscreenToggle.title = 'Vollbild (F11)';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -475,30 +359,7 @@
|
||||
// ========================================
|
||||
|
||||
function handleKeyboard(event) {
|
||||
// Nicht verarbeiten wenn Dialog offen ist (außer Escape)
|
||||
if (!dom.confirmDialog.classList.contains('hidden')) {
|
||||
if (event.key === 'Escape') {
|
||||
hideResetConfirm();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Esc: Reset-Dialog öffnen
|
||||
if (event.key === 'Escape') {
|
||||
event.preventDefault();
|
||||
showResetConfirm();
|
||||
return;
|
||||
}
|
||||
|
||||
// F11: Vollbild
|
||||
if (event.key === 'F11') {
|
||||
// Browser macht das normalerweise selbst, aber wir können den Button aktualisieren
|
||||
return;
|
||||
}
|
||||
|
||||
// Buchstabentasten (case-insensitive)
|
||||
const key = event.key.toUpperCase();
|
||||
|
||||
var key = event.key;
|
||||
switch (key) {
|
||||
case 'R':
|
||||
event.preventDefault();
|
||||
@@ -520,10 +381,16 @@
|
||||
// ========================================
|
||||
|
||||
function init() {
|
||||
initDom();
|
||||
showLoading(true);
|
||||
|
||||
// Event Listener
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
// Initialen State laden
|
||||
poll();
|
||||
poll().then(function () {
|
||||
// Sobald erster Poll erfolgreich war, Overlay ausblenden
|
||||
showLoading(false);
|
||||
});
|
||||
|
||||
// Polling starten
|
||||
startPolling();
|
||||
@@ -553,7 +420,7 @@
|
||||
// Tastatur-Shortcuts
|
||||
document.addEventListener('keydown', handleKeyboard);
|
||||
|
||||
// Touch-Bereiche für Score-Updates (große Touch-Targets)
|
||||
// Single-click auf Team-Panel = Punkt hinzufügen
|
||||
dom.redPanel.addEventListener('click', function () {
|
||||
postScore('red');
|
||||
});
|
||||
@@ -564,27 +431,16 @@
|
||||
|
||||
// Double-click für nächste Runde
|
||||
dom.redPanel.addEventListener('dblclick', function (event) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
postNext();
|
||||
});
|
||||
|
||||
dom.greenPanel.addEventListener('dblclick', function (event) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
postNext();
|
||||
});
|
||||
|
||||
// Verbindung prüfen
|
||||
const testPoll = setInterval(function () {
|
||||
fetchState().then(function (data) {
|
||||
if (data) {
|
||||
clearInterval(testPoll);
|
||||
}
|
||||
});
|
||||
}, 1000);
|
||||
|
||||
setTimeout(function () {
|
||||
clearInterval(testPoll);
|
||||
}, 10000);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -69,18 +69,17 @@
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<!-- Round History -->
|
||||
<footer class="round-history">
|
||||
<div id="rounds-list" class="rounds-list" role="list" aria-label="Rundenverlauf">
|
||||
<!-- Dynamically populated -->
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<!-- Connection Status -->
|
||||
<div id="connection-status" class="connection-status">
|
||||
<span class="status-dot" id="status-dot"></span>
|
||||
<span id="status-text">Verbinde…</span>
|
||||
</div>
|
||||
|
||||
<!-- Loading Overlay -->
|
||||
<div id="loading-overlay" class="loading-overlay hidden">
|
||||
<div class="loading-spinner"></div>
|
||||
<p class="loading-text">Verbinde mit Scoreboard…</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Reset Confirmation Dialog -->
|
||||
|
||||
@@ -71,7 +71,7 @@ body {
|
||||
/* ---------- Fullscreen Container ---------- */
|
||||
.fullscreen-container {
|
||||
display: grid;
|
||||
grid-template-rows: auto auto 1fr auto auto;
|
||||
grid-template-rows: auto 1fr;
|
||||
height: 100vh;
|
||||
height: 100dvh;
|
||||
max-width: 100vw;
|
||||
@@ -189,8 +189,9 @@ body {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 0;
|
||||
padding: 16px;
|
||||
padding: 0;
|
||||
min-height: 0;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
/* ---------- Team Panel ---------- */
|
||||
@@ -200,10 +201,14 @@ body {
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20px 16px;
|
||||
border-radius: var(--border-radius-lg);
|
||||
border-radius: 0;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
transition: box-shadow var(--transition-speed);
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
-webkit-user-select: none;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.team-panel::before {
|
||||
@@ -215,30 +220,37 @@ body {
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.team-panel:hover::before {
|
||||
opacity: 0.08;
|
||||
}
|
||||
|
||||
.team-panel:active::before {
|
||||
opacity: 0.15;
|
||||
}
|
||||
|
||||
.team-panel:active {
|
||||
transform: scale(0.99);
|
||||
}
|
||||
|
||||
/* Red Team */
|
||||
.red-team {
|
||||
background: var(--team-red-bg);
|
||||
border: 2px solid var(--team-red-dim);
|
||||
border-right: 1px solid var(--border-color);
|
||||
border-radius: var(--border-radius-lg) 0 0 var(--border-radius-lg);
|
||||
border-right: 2px solid var(--border-color);
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.red-team::before {
|
||||
background: linear-gradient(135deg, var(--team-red) 0%, transparent 60%);
|
||||
opacity: 0.05;
|
||||
}
|
||||
|
||||
/* Green Team */
|
||||
.green-team {
|
||||
background: var(--team-green-bg);
|
||||
border: 2px solid var(--team-green-dim);
|
||||
border-left: 1px solid var(--border-color);
|
||||
border-radius: 0 var(--border-radius-lg) var(--border-radius-lg) 0;
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.green-team::before {
|
||||
background: linear-gradient(225deg, var(--team-green) 0%, transparent 60%);
|
||||
opacity: 0.05;
|
||||
}
|
||||
|
||||
/* Color bar on top */
|
||||
@@ -299,13 +311,13 @@ body {
|
||||
/* ---------- Flash Animation for Score Updates ---------- */
|
||||
@keyframes scoreFlashRed {
|
||||
0% { transform: scale(1); color: var(--text-primary); }
|
||||
30% { transform: scale(1.12); color: #fff; }
|
||||
30% { transform: scale(1.15); color: #fff; }
|
||||
100% { transform: scale(1); color: var(--text-primary); }
|
||||
}
|
||||
|
||||
@keyframes scoreFlashGreen {
|
||||
0% { transform: scale(1); color: var(--text-primary); }
|
||||
30% { transform: scale(1.12); color: #fff; }
|
||||
30% { transform: scale(1.15); color: #fff; }
|
||||
100% { transform: scale(1); color: var(--text-primary); }
|
||||
}
|
||||
|
||||
@@ -317,77 +329,40 @@ body {
|
||||
animation: scoreFlashGreen 0.4s ease-out;
|
||||
}
|
||||
|
||||
/* ---------- Round History ---------- */
|
||||
.round-history {
|
||||
background: var(--bg-secondary);
|
||||
border-top: 1px solid var(--border-color);
|
||||
padding: 8px 12px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.rounds-list {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
padding: 4px 0;
|
||||
scroll-behavior: smooth;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: var(--border-color) transparent;
|
||||
}
|
||||
|
||||
.rounds-list::-webkit-scrollbar {
|
||||
height: 4px;
|
||||
}
|
||||
|
||||
.rounds-list::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.rounds-list::-webkit-scrollbar-thumb {
|
||||
background: var(--border-color);
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
/* Round Tile */
|
||||
.round-tile {
|
||||
flex-shrink: 0;
|
||||
/* ---------- Loading Spinner ---------- */
|
||||
.loading-overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 2000;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 4px;
|
||||
padding: 6px 10px;
|
||||
min-width: 60px;
|
||||
border-radius: var(--border-radius);
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
font-variant-numeric: tabular-nums;
|
||||
border: 1px solid var(--border-color);
|
||||
background: var(--bg-tertiary);
|
||||
background: var(--bg-primary);
|
||||
gap: 24px;
|
||||
}
|
||||
|
||||
.loading-overlay.hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.loading-spinner {
|
||||
width: 64px;
|
||||
height: 64px;
|
||||
border: 4px solid var(--border-color);
|
||||
border-top-color: var(--accent-gold);
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.loading-text {
|
||||
font-size: 16px;
|
||||
color: var(--text-secondary);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.round-tile.active {
|
||||
border-color: var(--accent-gold);
|
||||
background: rgba(255, 204, 0, 0.1);
|
||||
color: var(--accent-gold);
|
||||
box-shadow: 0 0 8px rgba(255, 204, 0, 0.15);
|
||||
}
|
||||
|
||||
.round-tile .score-red {
|
||||
color: var(--team-red);
|
||||
}
|
||||
|
||||
.round-tile .score-green {
|
||||
color: var(--team-green);
|
||||
}
|
||||
|
||||
.round-tile .round-num {
|
||||
color: var(--text-muted);
|
||||
font-size: 11px;
|
||||
margin-right: 2px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* ---------- Connection Status ---------- */
|
||||
@@ -538,20 +513,6 @@ body {
|
||||
.reset-btn {
|
||||
padding: 8px 10px;
|
||||
}
|
||||
|
||||
.scoreboard {
|
||||
padding: 10px 8px;
|
||||
}
|
||||
|
||||
.team-panel {
|
||||
padding: 14px 10px;
|
||||
}
|
||||
|
||||
.round-tile {
|
||||
min-width: 52px;
|
||||
padding: 5px 8px;
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
/* Large screens / tablets */
|
||||
@@ -560,20 +521,6 @@ body {
|
||||
padding: 12px 32px;
|
||||
min-height: 72px;
|
||||
}
|
||||
|
||||
.scoreboard {
|
||||
padding: 32px 48px;
|
||||
}
|
||||
|
||||
.round-history {
|
||||
padding: 12px 24px;
|
||||
}
|
||||
|
||||
.round-tile {
|
||||
min-width: 72px;
|
||||
padding: 8px 14px;
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
|
||||
/* Landscape mobile */
|
||||
@@ -595,16 +542,6 @@ body {
|
||||
.team-panel {
|
||||
padding: 10px 8px;
|
||||
}
|
||||
|
||||
.round-history {
|
||||
padding: 4px 8px;
|
||||
}
|
||||
|
||||
.round-tile {
|
||||
min-width: 48px;
|
||||
padding: 3px 6px;
|
||||
font-size: 11px;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------- Prefers reduced motion ---------- */
|
||||
|
||||
Reference in New Issue
Block a user