LuminaWebsite/assets/js/consilium-map.js
Maaxxs 342301b082 Consilium: guests see only their shared tactic and go back to the session list when the share ends
Asked for: when the share for the Consilium ends, everyone from the Consilium is sent back to the live overview
(so far only the live view ended and the map stayed open); during the session they may not switch maps or see the
categories - really only the tactic.

- map_frame.php: Consilium guests get the map viewer only for a running shared session (?karte=...&taktik=...),
  otherwise the whole page goes back to the session list; the viewer gets LUMINA_GUEST.
- Viewer guest mode (body.guest-mode): no map picker, no markers or categories (not even loaded), no location
  sharing, no tactic list - only the tactic of the session (tactics_api.php ?taktik=).
- When the share ends (relay event, tactic gone, no ticket), TacticController.endGuestSession() sends the top page
  to map.php?beendet=stopped|ended with a note why; the page around the map also checks every 15 s.
- Calendar: no location picker for guests, meeting points are plain text for them (map_link_html()).
- README, patch note text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 02:04:24 +02:00

82 lines
3.3 KiB
JavaScript

/**
* Karte fuer Mitglieder verbuendeter Legionen (map.php, Consilium Elyseum).
* - Liste: Die freigegebenen Live-Sitzungen aktualisieren sich von selbst - neue erscheinen, beendete verschwinden.
* Dieselbe Darstellung wie in map.php.
* - Geoeffnete Sitzung: Endet sie, schickt die Karte selbst zurueck zur Liste (TacticController.endGuestSession).
* Zur Sicherheit prueft auch diese Seite regelmaessig, ob es die Sitzung noch gibt.
*/
(function () {
const source = '/tactics_api.php?sitzungen=1';
async function fetchSessions() {
const response = await fetch(source, { credentials: 'same-origin', headers: { Accept: 'application/json' } });
const data = await response.json();
if (data.status !== 'success') throw new Error(data.message || 'Fehler');
return data.sessions || [];
}
// Alle 15 Sekunden - im Hintergrund-Tab nicht, beim Zurueckkehren sofort
function every(ms, task) {
setInterval(() => {
if (!document.hidden) task();
}, ms);
document.addEventListener('visibilitychange', () => {
if (!document.hidden) task();
});
}
const watched = document.querySelector('[data-watch-session]');
if (watched) {
const id = parseInt(watched.dataset.watchSession, 10);
every(15000, async () => {
let sessions;
try {
sessions = await fetchSessions();
} catch (e) {
return; // nicht erreichbar - dann beim naechsten Mal
}
if (!sessions.some(s => s.tactic_id === id)) location.replace('/map.php?beendet=1');
});
return;
}
const list = document.getElementById('consilium-sessions');
const empty = document.getElementById('consilium-sessions-empty');
const error = document.getElementById('consilium-sessions-error');
if (!list || !empty) return;
// Der Hinweis "Sitzung beendet" soll beim Neuladen nicht wieder erscheinen
if (location.search) history.replaceState(null, '', location.pathname);
const esc = text => String(text).replace(/[&<>"']/g, c => ({
'&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;'
}[c]));
const time = since => new Date(since * 1000).toLocaleTimeString('de-DE', { hour: '2-digit', minute: '2-digit' });
function render(sessions) {
list.innerHTML = sessions.map(s => {
const people = (s.members > 0 ? `${s.members} aus der Legion` : 'Legion gerade nicht verbunden')
+ (s.guests > 0 ? ` · ${s.guests} ${s.guests === 1 ? 'Gast' : 'Gäste'}` : '');
return `<li>
<a href="${esc(s.url)}">
<span class="consilium-upcoming-date">seit ${esc(time(s.since))} Uhr</span>
<strong>${esc(s.name)}</strong>
<span class="text-muted">${esc(s.map_name)} · ${esc(people)}</span>
<span class="consilium-session-join">Beitreten →</span>
</a>
</li>`;
}).join('');
empty.hidden = sessions.length > 0;
}
every(15000, async () => {
let ok = false;
try {
render(await fetchSessions());
ok = true;
} catch (e) {
// dann beim naechsten Mal
}
if (error) error.hidden = ok;
});
})();