initial commit [141.14.140.180,mike]

This commit is contained in:
mike committed 2026-10-21 13:05:13 +02:00
commit 5fd2f4d00c
40 files changed
+27365

No files matched your search

+243
View File
@@ -0,0 +1,243 @@
#pragma once
// Einstellungsseite unter http://tdisplay.local/
// Liest und speichert über /api/settings; Orts- und Haltestellensuche fragt der Browser direkt
// bei Open-Meteo und v6.bvg.transport.rest an (beide erlauben das per CORS).
static const char WEB_PAGE[] = R"HTML(<!doctype html>
<html lang="de">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>T-Display</title>
<style>
:root { --bg:#0a0e17; --card:#131a27; --line:#283042; --text:#f2f4f8; --dim:#8a93a6; --ok:#4cd964; --accent:#4fa3ff; --bad:#ff5252; }
* { box-sizing: border-box; }
body { margin: 0; padding: 16px; background: var(--bg); color: var(--text); font: 16px/1.4 system-ui, -apple-system, sans-serif; }
main { max-width: 560px; margin: 0 auto; }
h1 { font-size: 22px; margin: 4px 0 16px; }
section { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-bottom: 14px; }
h2 { font-size: 13px; margin: 0 0 10px; color: var(--dim); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
label { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 10px 0 0; }
input[type=number], input[type=text] { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; font: inherit; }
input[type=number] { width: 6.5em; }
input[type=text] { flex: 1; min-width: 0; }
textarea { width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; font: 14px/1.4 ui-monospace, monospace; resize: vertical; }
small.hint { display: block; margin-top: 6px; color: var(--dim); }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
.row { display: flex; gap: 8px; }
button { background: var(--line); color: var(--text); border: 0; border-radius: 6px; padding: 8px 12px; font: inherit; cursor: pointer; }
button.link { background: none; color: var(--accent); padding: 8px 0 0; }
button.primary { width: 100%; padding: 11px; background: var(--accent); color: #04121f; font-weight: 600; }
.current { color: var(--dim); margin-bottom: 10px; }
.current b { color: var(--text); font-weight: 500; }
ul { list-style: none; margin: 0; padding: 0; }
li button { width: 100%; margin-top: 6px; text-align: left; background: var(--bg); border: 1px solid var(--line); }
li small { display: block; margin-top: 8px; color: var(--dim); }
.pages { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.pages label { justify-content: flex-start; }
#msg { min-height: 1.4em; margin-top: 10px; text-align: center; }
</style>
</head>
<body>
<main>
<h1>T-Display</h1>
<section>
<h2>Seiten</h2>
<div class="pages" id="pages"></div>
<label>Zurück zur Uhr nach Sekunden (0 = nie)<input type="number" id="timeout" min="0" max="3600"></label>
<label>Display um 180° drehen<input type="checkbox" id="flip"></label>
</section>
<section>
<h2>Wetter-Standort</h2>
<div class="current" id="placeCur"></div>
<div class="row"><input type="text" id="placeQ" placeholder="Ort suchen, z.&nbsp;B. Berlin"><button type="button" id="placeBtn">Suchen</button></div>
<ul id="placeRes"></ul>
<button type="button" class="link" id="placeAuto">Automatisch über die IP-Adresse</button>
</section>
<section>
<h2>Abfahrten</h2>
<div class="current" id="stopCur"></div>
<div class="row"><input type="text" id="stopQ" placeholder="Haltestelle suchen"><button type="button" id="stopBtn">Suchen</button></div>
<ul id="stopRes"></ul>
<button type="button" class="link" id="stopAuto">Nächste Haltestelle am Standort</button>
<label>Fußweg in Minuten (frühere Abfahrten ausblenden)<input type="number" id="walk" min="0" max="30"></label>
</section>
<section>
<h2>Termine</h2>
<div class="current" id="calCur"></div>
<textarea id="calUrls" rows="3" placeholder="iCal-Links, einer pro Zeile (https://… oder webcal://…)"></textarea>
<div class="current" id="wasteCur" style="margin-top:12px"></div>
<textarea id="wasteUrl" rows="1" placeholder="Müllabfuhr als iCal-Link"></textarea>
<small class="hint">Gespeicherte Links werden aus Sicherheitsgründen nicht angezeigt. Ein leeres Feld lässt sie unverändert.</small>
<button type="button" class="link" id="calClear">Alle Kalender-Links entfernen</button>
</section>
<section>
<h2>Eigene Server</h2>
<textarea id="servers" rows="4" placeholder="eine Adresse pro Zeile, z. B. https://example.org/"></textarea>
<small class="hint">Geprüft werden Erreichbarkeit, Antwortzeit und die Restlaufzeit des Zertifikats (höchstens 6).</small>
</section>
<section>
<h2>Blutzucker (mg/dL)</h2>
<label>Zielbereich ab<input type="number" id="bzLow" min="40" max="150"></label>
<label>Zielbereich bis<input type="number" id="bzHigh" min="50" max="400"></label>
<label>Sehr hoch ab<input type="number" id="bzVeryHigh" min="50" max="500"></label>
</section>
<button type="button" class="primary" id="save">Speichern</button>
<div id="msg"></div>
</main>
<script>
const $ = id => document.getElementById(id);
let s = {};
function bold(text) {
const b = document.createElement('b');
b.textContent = text;
return b;
}
function showPlace() {
const el = $('placeCur');
if (s.lat || s.lon) el.replaceChildren('Gewählt: ', bold(s.place || s.lat.toFixed(3) + ', ' + s.lon.toFixed(3)));
else el.replaceChildren('Automatisch über die IP-Adresse', ...(s.autoPlace ? [': ', bold(s.autoPlace)] : []));
}
function showStop() {
const el = $('stopCur');
if (s.stopId) el.replaceChildren('Gewählt: ', bold(s.stopName));
else el.replaceChildren('Nächste Haltestelle am Standort', ...(s.autoStop ? [': ', bold(s.autoStop)] : []));
}
function note(ul, text) {
const li = document.createElement('li');
const small = document.createElement('small');
small.textContent = text;
li.append(small);
ul.replaceChildren(li);
}
// Sucht über url + Suchbegriff; items() holt die Treffer aus der Antwort, label() beschriftet, pick() übernimmt
async function search(input, ul, url, items, label, pick) {
const q = input.value.trim();
if (!q) return;
note(ul, 'Suche …');
try {
const r = await fetch(url + encodeURIComponent(q));
if (!r.ok) throw new Error(r.status);
const found = items(await r.json());
if (!found.length) return note(ul, 'Nichts gefunden');
ul.replaceChildren(...found.map(it => {
const li = document.createElement('li');
const b = document.createElement('button');
b.type = 'button';
b.textContent = label(it);
b.onclick = () => { pick(it); ul.replaceChildren(); input.value = ''; };
li.append(b);
return li;
}));
} catch (e) {
note(ul, 'Suche fehlgeschlagen, bitte noch einmal versuchen');
}
}
const cleanStop = name => name.replace(' (Berlin)', '');
function searchPlace() {
search($('placeQ'), $('placeRes'),
'https://geocoding-api.open-meteo.com/v1/search?count=8&language=de&name=',
j => j.results || [],
r => [r.name, r.admin3 || r.admin2, r.admin1, r.country].filter(Boolean).join(', '),
r => { s.lat = r.latitude; s.lon = r.longitude; s.place = r.name; showPlace(); });
}
function searchStop() {
search($('stopQ'), $('stopRes'),
'https://v6.bvg.transport.rest/locations?results=8&addresses=false&poi=false&query=',
j => j.filter(x => x.type === 'stop' || x.type === 'station'),
x => cleanStop(x.name),
x => { s.stopId = x.id; s.stopName = cleanStop(x.name); showStop(); });
}
$('placeBtn').onclick = searchPlace;
$('stopBtn').onclick = searchStop;
$('placeQ').onkeydown = e => { if (e.key === 'Enter') searchPlace(); };
$('stopQ').onkeydown = e => { if (e.key === 'Enter') searchStop(); };
$('placeAuto').onclick = () => { s.lat = 0; s.lon = 0; s.place = ''; showPlace(); };
$('stopAuto').onclick = () => { s.stopId = ''; s.stopName = ''; showStop(); };
let clearCalendars = false;
function showCalendars() {
const list = hosts => hosts.length ? hosts.join(', ') : 'keiner';
$('calCur').replaceChildren('Kalender gespeichert: ', bold(clearCalendars ? 'werden entfernt' : list(s.calHosts)));
$('wasteCur').replaceChildren('Müllabfuhr gespeichert: ', bold(clearCalendars ? 'wird entfernt' : list(s.wasteHosts)));
}
$('calClear').onclick = () => { clearCalendars = true; showCalendars(); };
const numbers = ['timeout', 'walk', 'bzLow', 'bzHigh', 'bzVeryHigh'];
async function load() {
s = await (await fetch('/api/settings')).json();
numbers.forEach(id => $(id).value = s[id]);
$('flip').checked = s.flip;
$('servers').value = s.servers;
$('calUrls').value = '';
$('wasteUrl').value = '';
clearCalendars = false;
$('pages').replaceChildren(...s.pages.map(p => {
const label = document.createElement('label');
const box = document.createElement('input');
box.type = 'checkbox';
box.checked = p.on;
box.disabled = p.id === 0; // die Uhr ist immer dabei
box.dataset.id = p.id;
label.append(box, p.name);
return label;
}));
showPlace();
showStop();
showCalendars();
}
$('save').onclick = async () => {
const msg = $('msg');
const body = {
lat: s.lat, lon: s.lon, place: s.place, stopId: s.stopId, stopName: s.stopName,
flip: $('flip').checked,
servers: $('servers').value.trim(),
pages: [...$('pages').querySelectorAll('input')].map(b => ({ id: +b.dataset.id, on: b.checked })),
};
// Kalender-Links nur senden, wenn neue eingetragen oder alle entfernt werden sollen
const cal = $('calUrls').value.trim(), waste = $('wasteUrl').value.trim();
if (clearCalendars) { body.calUrls = cal; body.wasteUrl = waste; }
else {
if (cal) body.calUrls = cal;
if (waste) body.wasteUrl = waste;
}
numbers.forEach(id => {
const v = parseInt($(id).value, 10);
if (!isNaN(v)) body[id] = v; // leere Felder behalten den alten Wert
});
try {
const r = await fetch('/api/settings', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) });
if (!r.ok) throw new Error(r.status);
msg.style.color = 'var(--ok)';
msg.textContent = 'Gespeichert';
setTimeout(load, 4000); // automatisch gewählter Ort/Haltestelle ist dann neu ermittelt
} catch (e) {
msg.style.color = 'var(--bad)';
msg.textContent = 'Speichern fehlgeschlagen';
}
};
load();
</script>
</body>
</html>
)HTML";