Funktion zum relode der Tische aus der Session und der Gäste laden

This commit is contained in:
Michael Stangl
2026-07-12 17:03:23 +02:00
parent f880ae1c97
commit db69f3498d
+47 -9
View File
@@ -153,6 +153,23 @@ function status(id, text, klasse) {
} }
/* ------------------------------------------------ 1. Tische */ /* ------------------------------------------------ 1. Tische */
let geladenerRadius = 1.5; // zuletzt aus der Session geladener Nachbar-Radius
async function tischeAusSessionLaden() {
// Sektion 1 aus dem serverseitigen Session-Layout fuellen (z.B. was der
// grafische Editor gespeichert hat) statt fest das Preset zu zeigen.
try {
const r = await api('/sitzung/' + sitzung + '/tische');
if (r.tische && r.tische.length) {
tischeLeeren();
for (const t of r.tische) tischZeile(t.plaetze, t.x, t.y, t.id);
geladenerRadius = r.nachbarRadius || 1.5;
return;
}
} catch (e) { /* frische/abgelaufene Session — Preset als Fallback */ }
presetReihe();
}
function tischZeile(plaetze, x, y, tid) { function tischZeile(plaetze, x, y, tid) {
const tbody = document.querySelector('#tischTabelle tbody'); const tbody = document.querySelector('#tischTabelle tbody');
const nr = tid ?? tbody.children.length + 1; const nr = tid ?? tbody.children.length + 1;
@@ -204,7 +221,7 @@ async function tischeSpeichern() {
const r = await api('/sitzung/' + sitzung + '/tische', { const r = await api('/sitzung/' + sitzung + '/tische', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ tische }), body: JSON.stringify({ tische, nachbarRadius: geladenerRadius }),
}); });
const nachbarn = r.tische.map(t => 'Tisch ' + t.id + ' ↔ [' + t.nachbarn.join(', ') + ']').join(' '); const nachbarn = r.tische.map(t => 'Tisch ' + t.id + ' ↔ [' + t.nachbarn.join(', ') + ']').join(' ');
status('tischStatus', '✓ ' + r.tische.length + ' Tische, ' + r.plaetzeGesamt + status('tischStatus', '✓ ' + r.tische.length + ' Tische, ' + r.plaetzeGesamt +
@@ -250,14 +267,30 @@ Gast;Kollegium;;Kollegen;;4
Karl;Einzelgast;;;; Karl;Einzelgast;;;;
`; `;
async function gaesteHochladen() { async function csvDateiGewaehlt(ev) {
const dateiInput = document.getElementById('csvDatei'); // Ausgewaehlte CSV sofort sichtbar in die Textarea laden (Single Source):
let blob; // dekodieren wie das Backend (utf-8-sig, sonst cp1252), BOM strippen.
if (dateiInput.files.length > 0) { const datei = ev.target.files[0];
blob = dateiInput.files[0]; if (!datei) return;
} else { const puffer = await datei.arrayBuffer();
blob = new Blob([document.getElementById('csvText').value], { type: 'text/csv' }); let text;
try {
text = new TextDecoder('utf-8', { fatal: true }).decode(puffer);
} catch (e) {
text = new TextDecoder('windows-1252').decode(puffer); // Excel/Windows
} }
text = text.replace(/^/, '');
document.getElementById('csvText').value = text;
// stale Ausgabe eines frueheren Uploads entfernen
document.getElementById('gruppenUebersicht').innerHTML = '';
status('gaesteStatus', 'Datei „' + datei.name + '“ geladen — zum Übernehmen ' +
'„Gästeliste übernehmen“ klicken.', 'ok');
ev.target.value = ''; // Textarea ist ab jetzt die alleinige Quelle
}
async function gaesteHochladen() {
// immer die (ggf. aus einer Datei befuellte) Textarea senden
const blob = new Blob([document.getElementById('csvText').value], { type: 'text/csv' });
const form = new FormData(); const form = new FormData();
form.append('datei', blob, 'gaeste.csv'); form.append('datei', blob, 'gaeste.csv');
try { try {
@@ -356,12 +389,17 @@ async function zeigeVariante(i) {
/* ------------------------------------------------ Start */ /* ------------------------------------------------ Start */
window.addEventListener('DOMContentLoaded', async () => { window.addEventListener('DOMContentLoaded', async () => {
document.getElementById('csvText').value = beispielCSV; document.getElementById('csvText').value = beispielCSV;
presetReihe(); document.getElementById('csvDatei').addEventListener('change', csvDateiGewaehlt);
try { try {
sitzung = await sitzungHolen(); sitzung = await sitzungHolen();
document.getElementById('sitzungsId').textContent = sitzung; document.getElementById('sitzungsId').textContent = sitzung;
// Tische aus der (ggf. mit dem Editor geteilten) Session laden;
// Preset nur, wenn die Session noch keine Tische hat
await tischeAusSessionLaden();
berechnenFreigeben();
} catch (e) { } catch (e) {
document.getElementById('sitzungsId').textContent = 'Fehler: ' + e.message; document.getElementById('sitzungsId').textContent = 'Fehler: ' + e.message;
presetReihe();
} }
}); });