-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequests.html
More file actions
336 lines (298 loc) · 12.6 KB
/
requests.html
File metadata and controls
336 lines (298 loc) · 12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
<!doctype html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lied wünschen</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2LwA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="styles.css">
</head>
<body class="festive subpage">
<div class="scene-decor" aria-hidden="true">
<div class="tree"></div>
<div class="ornament ornament-star star-bright"></div>
<div class="ornament ornament-star star-soft"></div>
<div class="ornament ornament-star star-twinkle"></div>
<div class="snowflake snowflake-main"></div>
<div class="snowflake snowflake-mid"></div>
<div class="snowflake snowflake-small"></div>
</div>
<div class="card">
<header>
<h1 id="headline"></h1>
<p class="subtitle">Wunschliste</p>
</header>
<div class="request-panel show">
<div class="request-header">
<h2>Verfügbare Lieder</h2>
<button class="link-like" id="back-home">Zurück</button>
</div>
<div class="request-list" id="request-list">
<p>Wird geladen …</p>
</div>
</div>
<div class="status" id="status">
<span class="indicator" aria-hidden="true"></span>
<span id="status-text">Status wird geladen …</span>
</div>
<p class="note" id="note"></p>
<footer class="social-footer hidden" id="social-footer">
<h3 class="social-footer-title">Unsere Kanäle:</h3>
<div class="social-icons" id="social-icons"></div>
</footer>
</div>
<div class="toast-container" id="toast-container"></div>
<script src="config.js"></script>
<script>
const config = window.FPP_CONFIG || {};
const headline = document.getElementById('headline');
const requestList = document.getElementById('request-list');
const statusBox = document.getElementById('status');
const statusText = document.getElementById('status-text');
const note = document.getElementById('note');
const backHome = document.getElementById('back-home');
const toastContainer = document.getElementById('toast-container');
const statusPollMs = Math.max(3000, Number(config.statusPollMs || 10000));
const previewMode = Boolean(config.previewMode);
const accessCode = (config.accessCode || '').trim();
const accessKey = 'fpp-access-granted';
let requestsDisabled = false;
const toastDisplayDuration = 4000; // Duration in milliseconds
const toastAnimationDuration = 300; // CSS transition duration in milliseconds
const sampleSongs = [
{ title: 'Jingle Bells (Fast Remix)', duration: 155, sequenceName: 'Jingle_Bells.fseq', mediaName: 'jingle_bells.mp3' },
{ title: 'Stille Nacht (Orchester)', duration: 241, sequenceName: 'Stille_Nacht.fseq', mediaName: 'stille_nacht.mp3' },
{ title: 'Carol of the Bells', duration: 192, sequenceName: 'Carol_Of_The_Bells.fseq', mediaName: 'carol_of_the_bells.mp3' },
{ title: 'O Tannenbaum', duration: 178, sequenceName: 'O_Tannenbaum.fseq', mediaName: 'o_tannenbaum.mp3' },
{ title: 'Feliz Navidad', duration: 203, sequenceName: 'Feliz_Navidad.fseq', mediaName: 'feliz_navidad.mp3' },
];
headline.textContent = `${config.siteName || 'FPP Lichtershow'}`;
if (accessCode && localStorage.getItem(accessKey) !== 'yes') {
window.location.href = '/';
}
function authHeaders() {
if (!accessCode) return {};
return { 'X-Access-Code': accessCode };
}
function showToast(message) {
const toast = document.createElement('div');
toast.className = 'toast';
toast.textContent = message;
toastContainer.appendChild(toast);
// Trigger animation
requestAnimationFrame(() => {
toast.classList.add('show');
});
// Hide and remove after duration
setTimeout(() => {
toast.classList.remove('show');
toast.classList.add('hide');
setTimeout(() => {
toast.remove();
}, toastAnimationDuration);
}, toastDisplayDuration);
}
function markStatus(type, text) {
statusBox.classList.remove('running', 'error');
if (type) statusBox.classList.add(type);
statusText.textContent = text;
}
function formatDuration(sec) {
if (typeof sec !== 'number' || Number.isNaN(sec)) return '';
const minutes = Math.floor(sec / 60);
const seconds = String(Math.floor(sec % 60)).padStart(2, '0');
return `${minutes}:${seconds}`;
}
async function fetchState() {
if (previewMode) {
markStatus('', 'Bereit (Vorschau).');
note.textContent = 'Dies ist eine Vorschau ohne FPP-Verbindung.';
return;
}
try {
const response = await fetch('/api/state');
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const data = await response.json();
const status = data.status || {};
const isRunning = Boolean(status.is_running);
const isIdle = Boolean(status.is_idle);
const locks = data.locks || {};
const isOutsideWindow = Boolean(locks.outsideShowWindow);
const isQuiet = Boolean(locks.quiet);
markStatus(isRunning ? 'running' : '', isRunning ? 'Show läuft gerade.' : 'Bereit.');
note.textContent = data.note || '';
// Disable requests when outside show window, during quiet hours, or when all buttons are disabled
requestsDisabled = Boolean(locks.disableAllButtons);
if (isOutsideWindow) {
note.textContent = 'Außerhalb des Showzeitraums – Wünsche sind nicht möglich.';
} else if (isQuiet) {
note.textContent = 'Ruhezeit 22:00–16:30 – Wünsche sind nicht möglich.';
} else {
const disable = isRunning && !isIdle;
if (disable) {
note.textContent = data.note || 'Aktuell läuft eine Show – Wünsche pausiert.';
}
}
updateRequestButtons(requestsDisabled);
} catch (err) {
console.error('Statusfehler', err);
markStatus('error', 'Status konnte nicht geladen werden.');
note.textContent = 'Bitte Verbindung prüfen.';
}
}
function updateRequestButtons(disabled) {
const buttons = requestList.querySelectorAll('button');
buttons.forEach((btn) => {
btn.disabled = disabled;
});
}
async function loadRequestSongs() {
requestList.innerHTML = '<p>Wird geladen …</p>';
if (previewMode) {
renderSampleSongs('Vorschau: Beispiel-Lieder aus der Wunschliste.');
return;
}
try {
const response = await fetch('/api/requests/songs', { headers: authHeaders() });
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const data = await response.json();
const songs = data.songs || [];
if (!songs.length) {
renderSampleSongs('Keine Songs aus der FPP-Playlist gefunden – Beispiel-Liste wird angezeigt.');
return;
}
renderRequestList(songs);
} catch (err) {
console.error('Playlist-Ladefehler', err);
renderSampleSongs('Playlist konnte nicht geladen werden – Vorschau mit Beispiel-Liedern.');
}
}
function renderRequestList(songs) {
requestList.innerHTML = '';
songs.forEach((song) => {
const { title, duration } = song;
const row = document.createElement('div');
row.className = 'request-item';
const label = document.createElement('div');
label.className = 'request-meta';
const titleEl = document.createElement('div');
titleEl.className = 'request-title';
titleEl.textContent = title;
const durationEl = document.createElement('div');
durationEl.className = 'request-duration';
durationEl.textContent = formatDuration(duration);
label.append(titleEl, durationEl);
const action = document.createElement('button');
action.textContent = 'Wünschen';
action.disabled = requestsDisabled;
action.addEventListener('click', () => submitRequest(song));
row.append(label, action);
requestList.appendChild(row);
});
}
function renderSampleSongs(message) {
const info = document.createElement('p');
info.className = 'note';
info.textContent = message;
requestList.innerHTML = '';
requestList.appendChild(info);
renderRequestList(sampleSongs);
}
async function submitRequest(song) {
const { title, sequenceName, mediaName, duration } = song;
if (previewMode) {
// Store song request info for home page toast
sessionStorage.setItem('pendingToast', JSON.stringify({ message: `Vorschau: "${title}" würde hinzugefügt.` }));
window.location.href = '/';
return;
}
try {
markStatus('', `Wunsch "${title}" wird eingeplant …`);
const response = await fetch('/api/requests', {
method: 'POST',
headers: { 'Content-Type': 'application/json', ...authHeaders() },
body: JSON.stringify({ song: title, sequenceName, mediaName, duration })
});
const data = await response.json();
// Handle duplicate song (409 Conflict)
if (response.status === 409) {
sessionStorage.setItem('pendingToast', JSON.stringify({ message: data.message || `"${title}" ist bereits in der Warteschlange.` }));
window.location.href = '/';
return;
}
if (!response.ok) throw new Error(`HTTP ${response.status}`);
// Store song request info for home page toast
sessionStorage.setItem('pendingToast', JSON.stringify({ message: data.message || `Wunsch "${title}" wurde hinzugefügt.` }));
window.location.href = '/';
} catch (err) {
console.error('Wunschfehler', err);
showToast('Wunsch konnte nicht angelegt werden.');
markStatus('error', 'Wunsch konnte nicht angelegt werden.');
}
}
backHome.addEventListener('click', () => { window.location.href = '/'; });
// Social Media Footer
function renderSocialFooter() {
const socialFooter = document.getElementById('social-footer');
const socialIcons = document.getElementById('social-icons');
const socialLinks = [
{ key: 'socialFacebook', icon: 'fa-brands fa-facebook-f', label: 'Facebook' },
{ key: 'socialInstagram', icon: 'fa-brands fa-instagram', label: 'Instagram' },
{ key: 'socialTiktok', icon: 'fa-brands fa-tiktok', label: 'TikTok' },
{ key: 'socialWhatsapp', icon: 'fa-brands fa-whatsapp', label: 'WhatsApp' },
{ key: 'socialYoutube', icon: 'fa-brands fa-youtube', label: 'YouTube' },
{ key: 'socialWebsite', icon: 'fa-solid fa-globe', label: 'Website' },
{ key: 'socialEmail', icon: 'fa-solid fa-envelope', label: 'E-Mail', isEmail: true }
];
function isValidUrl(url) {
try {
const parsed = new URL(url);
return ['http:', 'https:'].includes(parsed.protocol);
} catch {
return false;
}
}
let hasAny = false;
socialLinks.forEach(({ key, icon, label, isEmail }) => {
const value = (config[key] || '').trim();
if (value) {
if (isEmail) {
hasAny = true;
const link = document.createElement('a');
link.className = 'social-icon';
link.href = `mailto:${value}`;
link.setAttribute('aria-label', label);
link.title = label;
const iconEl = document.createElement('i');
iconEl.className = icon;
iconEl.setAttribute('aria-hidden', 'true');
link.appendChild(iconEl);
socialIcons.appendChild(link);
} else if (isValidUrl(value)) {
hasAny = true;
const link = document.createElement('a');
link.className = 'social-icon';
link.href = value;
link.target = '_blank';
link.rel = 'noopener noreferrer';
link.setAttribute('aria-label', label);
link.title = label;
const iconEl = document.createElement('i');
iconEl.className = icon;
iconEl.setAttribute('aria-hidden', 'true');
link.appendChild(iconEl);
socialIcons.appendChild(link);
}
}
});
if (hasAny) {
socialFooter.classList.remove('hidden');
}
}
renderSocialFooter();
fetchState();
setInterval(fetchState, statusPollMs);
loadRequestSongs();
</script>
</body>
</html>