Formatting

This commit is contained in:
Carsten Graf
2025-07-12 17:06:42 +02:00
parent 337e12078b
commit 3b4c5d2b92
6 changed files with 1651 additions and 1462 deletions

View File

@@ -192,7 +192,8 @@ html {
}
@keyframes batteryPulse {
0%, 100% {
0%,
100% {
opacity: 1;
}
50% {
@@ -201,10 +202,12 @@ html {
}
@keyframes batteryBlink {
0%, 50% {
0%,
50% {
opacity: 1;
}
51%, 100% {
51%,
100% {
opacity: 0.5;
}
}

View File

@@ -3,10 +3,9 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="index.css" />
<link rel="icon" type="image/x-icon" href="/pictures/favicon.ico">
<link rel="icon" type="image/x-icon" href="/pictures/favicon.ico" />
<title>NinjaCross Timer</title>
</head>
<body>
<!-- Batterie-Banner -->
@@ -27,9 +26,17 @@
<a href="/settings" class="settings-btn">⚙️</a>
<div class="heartbeat-indicators">
<div class="heartbeat-indicator" id="heartbeat1" data-label="Start1"></div>
<div
class="heartbeat-indicator"
id="heartbeat1"
data-label="Start1"
></div>
<div class="heartbeat-indicator" id="heartbeat2" data-label="Stop1"></div>
<div class="heartbeat-indicator" id="heartbeat3" data-label="Start2"></div>
<div
class="heartbeat-indicator"
id="heartbeat3"
data-label="Start2"
></div>
<div class="heartbeat-indicator" id="heartbeat4" data-label="Stop2"></div>
</div>
@@ -47,14 +54,14 @@
<div class="timer-container">
<div class="lane">
<div id="name1" class="swimmer-name" style="display: none;"></div>
<div id="name1" class="swimmer-name" style="display: none"></div>
<h2>🏊‍♀️ Bahn 1</h2>
<div id="time1" class="time-display">00.00</div>
<div id="status1" class="status ready">Bereit</div>
</div>
<div class="lane">
<div id="name2" class="swimmer-name" style="display: none;"></div>
<div id="name2" class="swimmer-name" style="display: none"></div>
<h2>🏊‍♂️ Bahn 2</h2>
<div id="time2" class="time-display">00.00</div>
<div id="status2" class="status ready">Bereit</div>
@@ -102,8 +109,8 @@
};
// Set all heartbeats to red initially
["heartbeat1", "heartbeat2", "heartbeat3", "heartbeat4"].forEach(id => {
document.getElementById(id).classList.remove('active');
["heartbeat1", "heartbeat2", "heartbeat3", "heartbeat4"].forEach((id) => {
document.getElementById(id).classList.remove("active");
});
// Handle WebSocket events
@@ -136,15 +143,21 @@
if (indicatorId) {
heartbeatTimeouts[data.button] = Date.now();
document.getElementById(indicatorId).classList.add('active');
document.getElementById(indicatorId).classList.add("active");
}
}
// Namen-Handling
if ((data.firstname == "" || data.lastname == "") && data.lane == "start1") {
if (
(data.firstname == "" || data.lastname == "") &&
data.lane == "start1"
) {
name1 = "";
}
if ((data.firstname == "" || data.lastname == "") && data.lane == "start2") {
if (
(data.firstname == "" || data.lastname == "") &&
data.lane == "start2"
) {
name2 = "";
}
@@ -184,7 +197,7 @@
lowBatteryDevices.add({
button: data.button,
mac: data.mac,
battery: batteryLevel
battery: batteryLevel,
});
}
@@ -193,7 +206,7 @@
}
} else {
// Gerät aus niedrige Batterie Liste entfernen
lowBatteryDevices.forEach(device => {
lowBatteryDevices.forEach((device) => {
if (device.button === data.button && device.mac === data.mac) {
lowBatteryDevices.delete(device);
}
@@ -217,11 +230,11 @@
lowBatteryDevices.clear();
if (data.devices && data.devices.length > 0) {
data.devices.forEach(device => {
data.devices.forEach((device) => {
lowBatteryDevices.add({
button: device.button,
mac: device.mac,
battery: device.battery || 0
battery: device.battery || 0,
});
});
@@ -235,27 +248,29 @@
// Batterie-Banner anzeigen
function showBatteryBanner() {
const banner = document.getElementById('battery-banner');
const deviceList = document.getElementById('low-battery-list');
const banner = document.getElementById("battery-banner");
const deviceList = document.getElementById("low-battery-list");
// Geräteliste erstellen
const deviceNames = Array.from(lowBatteryDevices).map(device => {
const deviceNames = Array.from(lowBatteryDevices)
.map((device) => {
const buttonName = getButtonDisplayName(device.button);
return `${buttonName} (${device.battery}%)`;
}).join(', ');
})
.join(", ");
deviceList.textContent = deviceNames;
// Banner anzeigen
banner.classList.add('show');
document.body.classList.add('content-shifted');
banner.classList.add("show");
document.body.classList.add("content-shifted");
}
// Batterie-Banner verstecken
function hideBatteryBanner() {
const banner = document.getElementById('battery-banner');
banner.classList.remove('show');
document.body.classList.remove('content-shifted');
const banner = document.getElementById("battery-banner");
banner.classList.remove("show");
document.body.classList.remove("content-shifted");
batteryBannerDismissed = false;
}
@@ -268,11 +283,16 @@
// Button-Namen für Anzeige
function getButtonDisplayName(button) {
switch (button) {
case 'start1': return 'Start Bahn 1';
case 'stop1': return 'Stop Bahn 1';
case 'start2': return 'Start Bahn 2';
case 'stop2': return 'Stop Bahn 2';
default: return button;
case "start1":
return "Start Bahn 1";
case "stop1":
return "Stop Bahn 1";
case "start2":
return "Start Bahn 2";
case "stop2":
return "Stop Bahn 2";
default:
return button;
}
}
@@ -340,7 +360,8 @@
// Lernmodus
const learningDisplay = document.getElementById("learning-display");
if (learningMode) {
document.getElementById("learning-button").textContent = learningButton;
document.getElementById("learning-button").textContent =
learningButton;
learningDisplay.style.display = "block";
} else {
learningDisplay.style.display = "none";
@@ -363,7 +384,7 @@
updateDisplay();
})
.catch((error) =>
console.error("Fehler beim Laden der Daten:", error)
console.error("Fehler beim Laden der Daten:", error),
);
}
@@ -383,7 +404,7 @@
{ button: "stop2", id: "heartbeat4" },
].forEach(({ button, id }) => {
if (now - heartbeatTimeouts[button] > 10000) {
document.getElementById(id).classList.remove('active');
document.getElementById(id).classList.remove("active");
}
});
}, 1000);

View File

@@ -5,7 +5,7 @@
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
@@ -174,9 +174,15 @@
}
@keyframes pulse {
0% { transform: scale(1); }
50% { transform: scale(1.05); }
100% { transform: scale(1); }
0% {
transform: scale(1);
}
50% {
transform: scale(1.05);
}
100% {
transform: scale(1);
}
}
@keyframes fadeIn {
@@ -201,7 +207,8 @@
}
.date-input-group input[type="date"]::-webkit-calendar-picker-indicator {
background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="%23667eea" viewBox="0 0 16 16"><path d="M3.5 0a.5.5 0 0 1 .5.5V1h8V.5a.5.5 0 0 1 1 0V1h1a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V3a2 2 0 0 1 2-2h1V.5a.5.5 0 0 1 .5-.5zM1 4v10a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V4H1z"/></svg>') no-repeat;
background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="%23667eea" viewBox="0 0 16 16"><path d="M3.5 0a.5.5 0 0 1 .5.5V1h8V.5a.5.5 0 0 1 1 0V1h1a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V3a2 2 0 0 1 2-2h1V.5a.5.5 0 0 1 .5-.5zM1 4v10a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V4H1z"/></svg>')
no-repeat;
background-size: contain;
width: 20px;
height: 20px;

View File

@@ -1,19 +1,40 @@
<!DOCTYPE html>
<!doctype html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="rfid.css" />
<link rel="icon" type="image/x-icon" href="/pictures/favicon.ico">
<link rel="icon" type="image/x-icon" href="/pictures/favicon.ico" />
<title>RFID Daten Eingabe</title>
</head>
<body>
<div class="container">
<div class="header">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px;">
<button onclick="window.location.href='/settings'" class="back-btn" style="background: #6c757d; color: white; border: none; padding: 8px 15px; border-radius: 5px; cursor: pointer; font-size: 14px; display: flex; align-items: center; gap: 5px;">
<div
style="
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
"
>
<button
onclick="window.location.href='/settings'"
class="back-btn"
style="
background: #6c757d;
color: white;
border: none;
padding: 8px 15px;
border-radius: 5px;
cursor: pointer;
font-size: 14px;
display: flex;
align-items: center;
gap: 5px;
"
>
← Zurück zu Einstellungen
</button>
</div>
@@ -21,16 +42,28 @@
<p>Erfassen Sie RFID-Tag Informationen</p>
</div>
<div id="successMessage" class="success-message" style="display: none;">
<div id="successMessage" class="success-message" style="display: none">
✅ Daten erfolgreich gespeichert!
</div>
<form id="rfidForm">
<div class="form-group">
<label for="uid">RFID UID <span class="required">*</span></label>
<div style="display: flex; gap: 10px; align-items: stretch;">
<input type="text" id="uid" name="uid" placeholder="z.B. A1:B2:C3:D4" required style="flex: 1;">
<button type="button" id="readUidBtn" class="read-uid-btn" onclick="readRFIDUID()">
<div style="display: flex; gap: 10px; align-items: stretch">
<input
type="text"
id="uid"
name="uid"
placeholder="z.B. A1:B2:C3:D4"
required
style="flex: 1"
/>
<button
type="button"
id="readUidBtn"
class="read-uid-btn"
onclick="readRFIDUID()"
>
📡 Read Chip
</button>
</div>
@@ -38,28 +71,53 @@
<div class="form-group">
<label for="vorname">Vorname <span class="required">*</span></label>
<input type="text" id="vorname" name="vorname" placeholder="Vorname eingeben" required>
<input
type="text"
id="vorname"
name="vorname"
placeholder="Vorname eingeben"
required
/>
</div>
<div class="form-group">
<label for="nachname">Nachname <span class="required">*</span></label>
<input type="text" id="nachname" name="nachname" placeholder="Nachname eingeben" required>
<input
type="text"
id="nachname"
name="nachname"
placeholder="Nachname eingeben"
required
/>
</div>
<div class="form-group">
<label for="geburtsdatum">Geburtsdatum <span class="required">*</span></label>
<label for="geburtsdatum"
>Geburtsdatum <span class="required">*</span></label
>
<div class="date-input-group">
<input type="date" id="geburtsdatum" name="geburtsdatum" required max="">
<div id="ageDisplay" class="age-display" style="display: none;"></div>
<input
type="date"
id="geburtsdatum"
name="geburtsdatum"
required
max=""
/>
<div
id="ageDisplay"
class="age-display"
style="display: none"
></div>
</div>
</div>
<div class="btn-container">
<button type="submit" class="btn btn-primary">💾 Speichern</button>
<button type="button" class="btn btn-secondary" onclick="clearForm()">🗑️ Zurücksetzen</button>
<button type="button" class="btn btn-secondary" onclick="clearForm()">
🗑️ Zurücksetzen
</button>
</div>
</form>
</div>
<script>
@@ -70,9 +128,9 @@
var APIKey;
// Maximales Datum auf heute setzen
document.addEventListener('DOMContentLoaded', function() {
const today = new Date().toISOString().split('T')[0];
document.getElementById('geburtsdatum').setAttribute('max', today);
document.addEventListener("DOMContentLoaded", function () {
const today = new Date().toISOString().split("T")[0];
document.getElementById("geburtsdatum").setAttribute("max", today);
});
// Alter berechnen und anzeigen
@@ -82,7 +140,10 @@
let age = today.getFullYear() - birth.getFullYear();
const monthDiff = today.getMonth() - birth.getMonth();
if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birth.getDate())) {
if (
monthDiff < 0 ||
(monthDiff === 0 && today.getDate() < birth.getDate())
) {
age--;
}
@@ -90,52 +151,60 @@
}
// Geburtsdatum Change Event
document.getElementById('geburtsdatum').addEventListener('change', function(e) {
document
.getElementById("geburtsdatum")
.addEventListener("change", function (e) {
const birthDate = e.target.value;
const ageDisplay = document.getElementById('ageDisplay');
const ageDisplay = document.getElementById("ageDisplay");
if (birthDate) {
const age = calculateAge(birthDate);
if (age >= 0 && age <= 150) {
ageDisplay.textContent = `${age} Jahre`;
ageDisplay.style.display = 'block';
ageDisplay.style.display = "block";
} else {
ageDisplay.style.display = 'none';
ageDisplay.style.display = "none";
if (age < 0) {
showErrorMessage('Das Geburtsdatum kann nicht in der Zukunft liegen!');
e.target.value = '';
showErrorMessage(
"Das Geburtsdatum kann nicht in der Zukunft liegen!",
);
e.target.value = "";
} else {
showErrorMessage('Bitte überprüfen Sie das Geburtsdatum!');
e.target.value = '';
showErrorMessage("Bitte überprüfen Sie das Geburtsdatum!");
e.target.value = "";
}
}
} else {
ageDisplay.style.display = 'none';
ageDisplay.style.display = "none";
}
});
// Form Submit Handler
document.getElementById('rfidForm').addEventListener('submit', async function(e) {
document
.getElementById("rfidForm")
.addEventListener("submit", async function (e) {
e.preventDefault();
if (isLoading) return;
// Daten aus dem Formular holen
const uid = document.getElementById('uid').value.trim();
const vorname = document.getElementById('vorname').value.trim();
const nachname = document.getElementById('nachname').value.trim();
const geburtsdatum = document.getElementById('geburtsdatum').value;
const uid = document.getElementById("uid").value.trim();
const vorname = document.getElementById("vorname").value.trim();
const nachname = document.getElementById("nachname").value.trim();
const geburtsdatum = document.getElementById("geburtsdatum").value;
// Validierung
if (!uid || !vorname || !nachname || !geburtsdatum) {
showErrorMessage('Bitte füllen Sie alle Pflichtfelder aus!');
showErrorMessage("Bitte füllen Sie alle Pflichtfelder aus!");
return;
}
// Alter berechnen
const alter = calculateAge(geburtsdatum);
if (alter < 0) {
showErrorMessage('Das Geburtsdatum kann nicht in der Zukunft liegen!');
showErrorMessage(
"Das Geburtsdatum kann nicht in der Zukunft liegen!",
);
return;
}
@@ -145,61 +214,64 @@
try {
// API Aufruf zum Erstellen des Benutzers
const response = await fetch(`/api/users/insert`, {
method: 'POST',
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
uid: uid,
vorname: vorname,
nachname: nachname,
geburtsdatum: geburtsdatum,
alter: alter // Berechnetes Alter wird mit gesendet
})
alter: alter, // Berechnetes Alter wird mit gesendet
}),
});
const result = await response.json();
if (result.success) {
// Erfolg anzeigen
showSuccessMessage('Benutzer erfolgreich gespeichert!');
showSuccessMessage("Benutzer erfolgreich gespeichert!");
// Formular zurücksetzen
clearForm();
// UID Feld fokussieren für nächsten Eintrag
setTimeout(() => {
document.getElementById('uid').focus();
document.getElementById("uid").focus();
}, 100);
} else {
// Fehler anzeigen
showErrorMessage(result.error || 'Fehler beim Speichern der Daten');
showErrorMessage(
result.error || "Fehler beim Speichern der Daten",
);
}
} catch (error) {
console.error('Fehler beim Speichern:', error);
showErrorMessage('Verbindungsfehler zum Server. Bitte versuchen Sie es später erneut.');
console.error("Fehler beim Speichern:", error);
showErrorMessage(
"Verbindungsfehler zum Server. Bitte versuchen Sie es später erneut.",
);
} finally {
setLoadingState(false);
}
});
function showSuccessMessage(message = 'Daten erfolgreich gespeichert!') {
const successMsg = document.getElementById('successMessage');
function showSuccessMessage(message = "Daten erfolgreich gespeichert!") {
const successMsg = document.getElementById("successMessage");
successMsg.textContent = `${message}`;
successMsg.style.display = 'block';
successMsg.style.display = "block";
setTimeout(() => {
successMsg.style.display = 'none';
successMsg.style.display = "none";
}, 3000);
}
function showErrorMessage(message) {
// Fehlermeldung dynamisch erstellen
let errorDiv = document.getElementById('errorMessage');
let errorDiv = document.getElementById("errorMessage");
if (!errorDiv) {
errorDiv = document.createElement('div');
errorDiv.id = 'errorMessage';
errorDiv.className = 'error-message';
errorDiv = document.createElement("div");
errorDiv.id = "errorMessage";
errorDiv.className = "error-message";
errorDiv.style.cssText = `
background: #f8d7da;
color: #721c24;
@@ -210,144 +282,150 @@
animation: fadeIn 0.3s ease-out;
display: none;
`;
document.querySelector('.container').insertBefore(errorDiv, document.getElementById('rfidForm'));
document
.querySelector(".container")
.insertBefore(errorDiv, document.getElementById("rfidForm"));
}
errorDiv.textContent = `${message}`;
errorDiv.style.display = 'block';
errorDiv.style.display = "block";
setTimeout(() => {
errorDiv.style.display = 'none';
errorDiv.style.display = "none";
}, 10000);
}
function setLoadingState(loading) {
isLoading = loading;
const submitBtn = document.querySelector('.btn-primary');
const form = document.getElementById('rfidForm');
const submitBtn = document.querySelector(".btn-primary");
const form = document.getElementById("rfidForm");
if (loading) {
submitBtn.textContent = '⏳ Speichern...';
submitBtn.textContent = "⏳ Speichern...";
submitBtn.disabled = true;
form.style.opacity = '0.7';
form.style.opacity = "0.7";
} else {
submitBtn.textContent = '💾 Speichern';
submitBtn.textContent = "💾 Speichern";
submitBtn.disabled = false;
form.style.opacity = '1';
form.style.opacity = "1";
}
}
function clearForm() {
document.getElementById('rfidForm').reset();
document.getElementById('ageDisplay').style.display = 'none';
document.getElementById('uid').focus();
document.getElementById("rfidForm").reset();
document.getElementById("ageDisplay").style.display = "none";
document.getElementById("uid").focus();
}
// Beim Laden der Seite
window.addEventListener('load', function() {
document.getElementById('uid').focus();
window.addEventListener("load", function () {
document.getElementById("uid").focus();
checkServerStatus();
loadLicence();
});
// Enter-Taste in UID Feld zum nächsten Feld springen
document.getElementById('uid').addEventListener('keydown', function(e) {
if (e.key === 'Enter') {
document.getElementById("uid").addEventListener("keydown", function (e) {
if (e.key === "Enter") {
e.preventDefault();
document.getElementById('vorname').focus();
document.getElementById("vorname").focus();
}
});
// Automatische UID Formatierung
document.getElementById('uid').addEventListener('input', function(e) {
document.getElementById("uid").addEventListener("input", function (e) {
let value = e.target.value.toUpperCase();
// Entfernen aller nicht-hexadezimalen Zeichen außer Doppelpunkt
value = value.replace(/[^0-9A-F:]/g, '');
value = value.replace(/[^0-9A-F:]/g, "");
e.target.value = value;
});
// RFID UID lesen
async function readRFIDUID() {
const readBtn = document.getElementById('readUidBtn');
const uidInput = document.getElementById('uid');
const readBtn = document.getElementById("readUidBtn");
const uidInput = document.getElementById("uid");
// Button Status ändern
readBtn.disabled = true;
readBtn.className = 'read-uid-btn reading';
readBtn.innerHTML = '📡 Lese UID...';
readBtn.className = "read-uid-btn reading";
readBtn.innerHTML = "📡 Lese UID...";
try {
// API Aufruf zum RFID Reader
const response = await fetch(`/api/rfid/read`, {
method: 'GET',
method: "GET",
headers: {
'Content-Type': 'application/json',
}
"Content-Type": "application/json",
},
});
const result = await response.json();
if (result.success && result.uid) {
// UID in das Eingabefeld setzen
uidInput.value = result.uid.match(/.{1,2}/g).join(':').toUpperCase();
uidInput.value = result.uid
.match(/.{1,2}/g)
.join(":")
.toUpperCase();
uidInput.focus();
// Visuelles Feedback
uidInput.style.borderColor = '#28a745';
uidInput.style.borderColor = "#28a745";
setTimeout(() => {
uidInput.style.borderColor = '#e1e5e9';
uidInput.style.borderColor = "#e1e5e9";
}, 2000);
showSuccessMessage('UID erfolgreich gelesen!');
showSuccessMessage("UID erfolgreich gelesen!");
// Automatisch zum nächsten Feld springen
setTimeout(() => {
document.getElementById('vorname').focus();
document.getElementById("vorname").focus();
}, 500);
} else {
// Fehler beim Lesen
const errorMsg = result.error || 'Keine UID gefunden';
const errorMsg = result.error || "Keine UID gefunden";
showErrorMessage(`RFID Fehler: ${errorMsg}`);
// UID Feld rot markieren
uidInput.style.borderColor = '#dc3545';
uidInput.style.borderColor = "#dc3545";
setTimeout(() => {
uidInput.style.borderColor = '#e1e5e9';
uidInput.style.borderColor = "#e1e5e9";
}, 10000);
}
} catch (error) {
console.error('Fehler beim Lesen der UID:', error);
showErrorMessage('Verbindungsfehler zum RFID Reader. Bitte prüfen Sie die Verbindung.');
console.error("Fehler beim Lesen der UID:", error);
showErrorMessage(
"Verbindungsfehler zum RFID Reader. Bitte prüfen Sie die Verbindung.",
);
// UID Feld rot markieren
uidInput.style.borderColor = '#dc3545';
uidInput.style.borderColor = "#dc3545";
setTimeout(() => {
uidInput.style.borderColor = '#e1e5e9';
uidInput.style.borderColor = "#e1e5e9";
}, 3000);
} finally {
// Button Status zurücksetzen
readBtn.disabled = false;
readBtn.className = 'read-uid-btn';
readBtn.innerHTML = '📡 Read Chip';
readBtn.className = "read-uid-btn";
readBtn.innerHTML = "📡 Read Chip";
}
}
async function checkServerStatus() {
try {
const response = await fetch('/api/health');
const response = await fetch("/api/health");
const data = await response.json();
if (!data.status || data.status !== 'connected') {
showErrorMessage('Server nicht verbunden. Einige Funktionen könnten eingeschränkt sein.');
if (!data.status || data.status !== "connected") {
showErrorMessage(
"Server nicht verbunden. Einige Funktionen könnten eingeschränkt sein.",
);
return false;
}
return true;
} catch (error) {
console.error('Server Status Check fehlgeschlagen:', error);
showErrorMessage('Verbindung zum Server nicht möglich.');
console.error("Server Status Check fehlgeschlagen:", error);
showErrorMessage("Verbindung zum Server nicht möglich.");
return false;
}
}
@@ -357,10 +435,9 @@
.then((response) => response.json())
.then((data) => {
APIKey = data.licence || "";
})
.catch((error) =>
showMessage("Fehler beim Laden der Lizenz", "error")
showMessage("Fehler beim Laden der Lizenz", "error"),
);
}
</script>

View File

@@ -1,10 +1,10 @@
<!DOCTYPE html>
<!doctype html>
<html lang="de">
<head>
<!-- Meta Tags -->
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" type="image/x-icon" href="/pictures/favicon.ico">
<link rel="icon" type="image/x-icon" href="/pictures/favicon.ico" />
<!-- Stylesheets -->
<link rel="stylesheet" href="settings.css" />
@@ -143,8 +143,14 @@
<!-- WiFi Configuration Section -->
<div class="section" id="wifiSection">
<h2>📡 WLAN-Konfiguration</h2>
<div id="wifiRestrictionNotice" class="restriction-notice" style="display: none;">
🔒 WLAN-Konfiguration ist nur mit Lizenz Level 3 oder höher verfügbar. Aktuelle Lizenz: Level <span id="currentLicenseLevel">0</span>
<div
id="wifiRestrictionNotice"
class="restriction-notice"
style="display: none"
>
🔒 WLAN-Konfiguration ist nur mit Lizenz Level 3 oder höher
verfügbar. Aktuelle Lizenz: Level
<span id="currentLicenseLevel">0</span>
</div>
<form id="wifiForm">
<div class="form-group">
@@ -176,8 +182,14 @@
<div class="section">
<h2>📍 Standort</h2>
<div id="locationRestrictionNotice" class="restriction-notice" style="display: none;">
🔒 Standort-Konfiguration ist nur mit Lizenz Level 3 oder höher verfügbar. Aktuelle Lizenz: Level <span id="currentLocationLicenseLevel">0</span>
<div
id="locationRestrictionNotice"
class="restriction-notice"
style="display: none"
>
🔒 Standort-Konfiguration ist nur mit Lizenz Level 3 oder höher
verfügbar. Aktuelle Lizenz: Level
<span id="currentLocationLicenseLevel">0</span>
</div>
<form id="locationForm">
<div class="form-group">
@@ -187,7 +199,11 @@
</select>
</div>
<div class="button-group">
<button type="submit" id="locationSubmitBtn" class="btn btn-primary">
<button
type="submit"
id="locationSubmitBtn"
class="btn btn-primary"
>
💾 Standort speichern
</button>
</div>
@@ -197,8 +213,13 @@
<!-- OTA Update Section -->
<div class="section">
<h2>🔄 OTA Update</h2>
<div id="otaRestrictionNotice" class="restriction-notice" style="display: none;">
🔒 OTA Updates sind nur mit Lizenz Level 2 oder höher verfügbar. Aktuelle Lizenz: Level <span id="currentLicenseLevel">0</span>
<div
id="otaRestrictionNotice"
class="restriction-notice"
style="display: none"
>
🔒 OTA Updates sind nur mit Lizenz Level 2 oder höher verfügbar.
Aktuelle Lizenz: Level <span id="currentLicenseLevel">0</span>
</div>
<div class="button-group">
<button
@@ -235,7 +256,9 @@
<div>Kanal: <span id="channel">Laden...</span></div>
<div>MAC-Adresse: <span id="macAddress">Laden...</span></div>
<div>Freier Speicher: <span id="freeMemory">Laden...</span></div>
<div>Verbundene Buttons: <span id="connectedButtons">Laden...</span></div>
<div>
Verbundene Buttons: <span id="connectedButtons">Laden...</span>
</div>
<div>Lizenz gültig: <span id="isLicenceValid">Laden...</span></div>
<div>Lizenz Level: <span id="licenceLevel">Laden...</span></div>
</div>
@@ -247,7 +270,12 @@
<form id="licenceForm">
<div class="form-group">
<label for="licencekey">Lizensschlüssel:</label>
<input type="password" id="licencekey" name="licence" value="Key" />
<input
type="password"
id="licencekey"
name="licence"
value="Key"
/>
</div>
<div class="button-group">
<button type="submit" class="btn btn-primary">
@@ -297,9 +325,8 @@
minute: "2-digit",
second: "2-digit",
});
document.getElementById(
"currentTime"
).textContent = `System Zeit: ${timeString}`;
document.getElementById("currentTime").textContent =
`System Zeit: ${timeString}`;
} else {
document.getElementById("currentTime").textContent =
"Aktuelle Zeit: Fehler beim Laden";
@@ -329,7 +356,7 @@
})
.catch((error) => {
console.log(
"Zeit konnte nicht geladen werden, verwende Browser-Zeit"
"Zeit konnte nicht geladen werden, verwende Browser-Zeit",
);
syncWithBrowserTime();
});
@@ -374,12 +401,13 @@
}
})
.catch((error) =>
showMessage("Verbindungsfehler beim Setzen der Zeit", "error")
showMessage("Verbindungsfehler beim Setzen der Zeit", "error"),
);
}
// Zeit setzen
document.getElementById("timeForm")
document
.getElementById("timeForm")
.addEventListener("submit", function (e) {
e.preventDefault();
@@ -410,11 +438,13 @@
}
})
.catch((error) =>
showMessage("Verbindungsfehler beim Setzen der Zeit", "error")
showMessage("Verbindungsfehler beim Setzen der Zeit", "error"),
);
});
document.getElementById("licenceForm").addEventListener("submit", function(e) {
document
.getElementById("licenceForm")
.addEventListener("submit", function (e) {
e.preventDefault();
saveLicence();
});
@@ -429,7 +459,7 @@
data.maxTimeDisplay || 20;
})
.catch((error) =>
showMessage("Fehler beim Laden der Einstellungen", "error")
showMessage("Fehler beim Laden der Einstellungen", "error"),
);
}
@@ -455,7 +485,7 @@
// Check license level and update OTA button accordingly
updateOTAButtonAccess(data.tier || 0);
updateWifiButtonAccess(data.tier || 0)
updateWifiButtonAccess(data.tier || 0);
updateLocationAccess(data.tier || 0);
})
.catch((error) => console.log("Info konnte nicht geladen werden"));
@@ -469,7 +499,7 @@
loadLocations();
})
.catch((error) =>
showMessage("Fehler beim Laden der Lizenz", "error")
showMessage("Fehler beim Laden der Lizenz", "error"),
);
}
@@ -500,19 +530,24 @@
// WLAN-Einstellungen laden
function loadWifiSettings() {
fetch("/api/get-wifi")
.then(response => response.json())
.then(data => {
.then((response) => response.json())
.then((data) => {
document.getElementById("wifi-ssid").value = data.ssid || "";
document.getElementById("wifi-password").value = data.password || "";
document.getElementById("wifi-password").value =
data.password || "";
})
.catch(error => showMessage("Fehler beim Laden der WLAN-Einstellungen", "error"));
.catch((error) =>
showMessage("Fehler beim Laden der WLAN-Einstellungen", "error"),
);
}
// WLAN-Einstellungen beim Laden der Seite abrufen
window.addEventListener('load', loadWifiSettings);
window.addEventListener("load", loadWifiSettings);
// WLAN-Formular Handler
document.getElementById("wifiForm").addEventListener("submit", function(e) {
document
.getElementById("wifiForm")
.addEventListener("submit", function (e) {
e.preventDefault();
const ssid = document.getElementById("wifi-ssid").value;
@@ -522,7 +557,11 @@
showMessage("Bitte WLAN-Namen eingeben", "error");
return;
}
if (!confirm("Der Server wird nach dem setzten neu gestartet. Fortsetzten?")) {
if (
!confirm(
"Der Server wird nach dem setzten neu gestartet. Fortsetzten?",
)
) {
return;
}
@@ -533,23 +572,32 @@
},
body: `ssid=${encodeURIComponent(ssid)}&password=${encodeURIComponent(password)}`,
})
.then(response => response.json())
.then(data => {
.then((response) => response.json())
.then((data) => {
if (data.success) {
showMessage("WLAN-Einstellungen erfolgreich gespeichert!", "success");
showMessage(
"WLAN-Einstellungen erfolgreich gespeichert!",
"success",
);
} else {
showMessage(data.error || "Fehler beim Speichern der WLAN-Einstellungen", "error");
showMessage(
data.error || "Fehler beim Speichern der WLAN-Einstellungen",
"error",
);
}
})
.catch(error => showMessage("Verbindungsfehler", "error"));
.catch((error) => showMessage("Verbindungsfehler", "error"));
});
// Update OTA button access based on license level
function updateOTAButtonAccess(licenseLevel) {
const otaButton = document.getElementById("otaUpdateBtn");
const otarestrictionNotice = document.getElementById("otaRestrictionNotice");
const otacurrentLevelSpan = document.getElementById("currentLicenseLevel");
const otarestrictionNotice = document.getElementById(
"otaRestrictionNotice",
);
const otacurrentLevelSpan = document.getElementById(
"currentLicenseLevel",
);
const level = parseInt(licenseLevel) || 0;
@@ -571,24 +619,33 @@
function updateButtons() {
if (confirm("Update Buttons?")) {
fetch("/api/updateButtons", {
method: "GET"
method: "GET",
})
.then((response) => {
if (response.status === 200) {
showMessage("Buttons führen das Update erfolgreich aus!", "success");
showMessage(
"Buttons führen das Update erfolgreich aus!",
"success",
);
} else {
showMessage("Fehler beim Senden der MQTT Message", "error");
}
})
.catch((error) => showMessage("Verbindungsfehler beim MQTT Publish", "error"));
.catch((error) =>
showMessage("Verbindungsfehler beim MQTT Publish", "error"),
);
}
}
function updateWifiButtonAccess(licenseLevel) {
const wifiSubmitBtn = document.getElementById("wifiSubmitBtn");
const wifiForm = document.getElementById("wifiForm");
const wifiRestrictionNotice = document.getElementById("wifiRestrictionNotice");
const wifiCurrentLevelSpan = document.getElementById("currentLicenseLevel");
const wifiRestrictionNotice = document.getElementById(
"wifiRestrictionNotice",
);
const wifiCurrentLevelSpan = document.getElementById(
"currentLicenseLevel",
);
const level = parseInt(licenseLevel) || 0;
@@ -596,7 +653,7 @@
// License level 3 or higher - enable form
wifiSubmitBtn.classList.remove("btn-disabled");
wifiSubmitBtn.disabled = false;
wifiForm.querySelectorAll('input').forEach(input => {
wifiForm.querySelectorAll("input").forEach((input) => {
input.disabled = false;
});
wifiRestrictionNotice.style.display = "none";
@@ -604,7 +661,7 @@
// License level below 3 - disable form
wifiSubmitBtn.classList.add("btn-disabled");
wifiSubmitBtn.disabled = true;
wifiForm.querySelectorAll('input').forEach(input => {
wifiForm.querySelectorAll("input").forEach((input) => {
input.disabled = true;
});
wifiRestrictionNotice.style.display = "block";
@@ -616,24 +673,35 @@
function performOTAUpdate() {
const otaButton = document.getElementById("otaUpdateBtn");
if (otaButton.disabled || otaButton.classList.contains("btn-disabled")) {
showMessage("OTA Update erfordert Lizenz Level 2 oder höher", "error");
if (
otaButton.disabled ||
otaButton.classList.contains("btn-disabled")
) {
showMessage(
"OTA Update erfordert Lizenz Level 2 oder höher",
"error",
);
return;
}
if (confirm("Möchten Sie wirklich ein OTA Update durchführen? Das Gerät wird während des Updates neu gestartet.")) {
window.location.href = '/update';
if (
confirm(
"Möchten Sie wirklich ein OTA Update durchführen? Das Gerät wird während des Updates neu gestartet.",
)
) {
window.location.href = "/update";
}
}
// Einstellungen speichern
document.getElementById("settingsForm")
document
.getElementById("settingsForm")
.addEventListener("submit", function (e) {
e.preventDefault();
const maxTime = parseInt(document.getElementById("maxTime").value);
const maxTimeDisplay = parseInt(
document.getElementById("maxTimeDisplay").value
document.getElementById("maxTimeDisplay").value,
);
fetch("/api/set-max-time", {
@@ -652,7 +720,7 @@
if (data.success) {
showMessage(
"Einstellungen erfolgreich gespeichert!",
"success"
"success",
);
} else {
showMessage("Fehler beim Speichern der Einstellungen", "error");
@@ -670,7 +738,7 @@
if (data.success) {
showMessage(
"Beste Zeiten erfolgreich zurückgesetzt!",
"success"
"success",
);
} else {
showMessage("Fehler beim Zurücksetzen", "error");
@@ -718,13 +786,11 @@
// Anlern-Anweisung aktualisieren
function updateLearningInstruction() {
if (learningStep < learningSteps.length) {
document.getElementById(
"learningInstruction"
).innerHTML = `Drücken Sie jetzt den Button für: <strong>${learningSteps[learningStep]}</strong>`;
document.getElementById("learningInstruction").innerHTML =
`Drücken Sie jetzt den Button für: <strong>${learningSteps[learningStep]}</strong>`;
}
}
// Anlern-Status abfragen
function pollLearningStatus() {
const pollInterval = setInterval(() => {
@@ -748,7 +814,7 @@
if (learningStep > 0) {
showMessage(
`${learningSteps[learningStep - 1]} erfolgreich angelernt!`,
"success"
"success",
);
}
}
@@ -770,13 +836,13 @@
if (data.success) {
showMessage(
"Button-Zuweisungen erfolgreich zurückgesetzt!",
"success"
"success",
);
loadSystemInfo();
} else {
showMessage(
"Fehler beim Zurücksetzen der Button-Zuweisungen",
"error"
"error",
);
}
})
@@ -806,7 +872,7 @@
alert(statusText);
})
.catch((error) =>
showMessage("Fehler beim Laden des Button-Status", "error")
showMessage("Fehler beim Laden des Button-Status", "error"),
);
}
@@ -822,7 +888,6 @@
})
.then((response) => response.json())
.then((data) => {
const select = document.getElementById("locationSelect");
// Vorhandene Optionen löschen (außer der ersten "Bitte wählen...")
@@ -858,15 +923,22 @@
}
})
.catch((error) => {
console.log("Aktueller Standort konnte nicht geladen werden:", error);
console.log(
"Aktueller Standort konnte nicht geladen werden:",
error,
);
});
}
// Location-Zugriff basierend auf Lizenz-Level kontrollieren
function updateLocationAccess(licenseLevel) {
const locationSubmitBtn = document.getElementById("locationSubmitBtn");
const locationRestrictionNotice = document.getElementById("locationRestrictionNotice");
const locationCurrentLevelSpan = document.getElementById("currentLocationLicenseLevel");
const locationRestrictionNotice = document.getElementById(
"locationRestrictionNotice",
);
const locationCurrentLevelSpan = document.getElementById(
"currentLocationLicenseLevel",
);
const locationSelect = document.getElementById("locationSelect");
const level = parseInt(licenseLevel) || 0;
@@ -888,14 +960,23 @@
}
// Location Form Handler
document.getElementById("locationForm").addEventListener("submit", function(e) {
document
.getElementById("locationForm")
.addEventListener("submit", function (e) {
e.preventDefault();
const locationSubmitBtn = document.getElementById("locationSubmitBtn");
const locationSubmitBtn =
document.getElementById("locationSubmitBtn");
// Lizenz-Level prüfen
if (locationSubmitBtn.disabled || locationSubmitBtn.classList.contains("btn-disabled")) {
showMessage("Standort-Konfiguration erfordert Lizenz Level 3 oder höher", "error");
if (
locationSubmitBtn.disabled ||
locationSubmitBtn.classList.contains("btn-disabled")
) {
showMessage(
"Standort-Konfiguration erfordert Lizenz Level 3 oder höher",
"error",
);
return;
}