ny
This commit is contained in:
@@ -226,7 +226,7 @@
|
|||||||
<div class="np-number" id="np-number"></div>
|
<div class="np-number" id="np-number"></div>
|
||||||
<div class="np-song" id="np-song"></div>
|
<div class="np-song" id="np-song"></div>
|
||||||
<div class="np-eta" id="np-eta" style="display:none">
|
<div class="np-eta" id="np-eta" style="display:none">
|
||||||
⏱ Næste dans starter om ca. <b id="np-eta-val"></b>
|
⏱ Næste dans starter ca. kl. <b id="np-eta-val"></b>
|
||||||
</div>
|
</div>
|
||||||
<!-- Fremgangsbar NEDERST -->
|
<!-- Fremgangsbar NEDERST -->
|
||||||
<div class="progress-section">
|
<div class="progress-section">
|
||||||
@@ -299,6 +299,10 @@ function fmtDur(secs) {
|
|||||||
return s === 0 ? `${m} min` : `${m}:${String(s).padStart(2,'0')}`;
|
return s === 0 ? `${m} min` : `${m}:${String(s).padStart(2,'0')}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function fmtClock(date) {
|
||||||
|
return date.toLocaleTimeString('da-DK', { hour: '2-digit', minute: '2-digit' });
|
||||||
|
}
|
||||||
|
|
||||||
function fmtTime(d) {
|
function fmtTime(d) {
|
||||||
if (!d) return '';
|
if (!d) return '';
|
||||||
return new Date(d).toLocaleTimeString('da-DK', { hour:'2-digit', minute:'2-digit', second:'2-digit' });
|
return new Date(d).toLocaleTimeString('da-DK', { hour:'2-digit', minute:'2-digit', second:'2-digit' });
|
||||||
@@ -425,17 +429,17 @@ function render(data) {
|
|||||||
document.getElementById('np-song').textContent = '';
|
document.getElementById('np-song').textContent = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// ETA til næste dans
|
// ETA til næste dans — klokkeslæt
|
||||||
const etaEl = document.getElementById('np-eta');
|
const etaEl = document.getElementById('np-eta');
|
||||||
const etaValEl = document.getElementById('np-eta-val');
|
const etaValEl = document.getElementById('np-eta-val');
|
||||||
if (playing && currentIdx >= 0) {
|
if (playing && currentIdx >= 0 && data.updated_at) {
|
||||||
// Find næste pending sang
|
|
||||||
const nextIdx = songs.findIndex((s, i) => i > currentIdx && s.status === 'pending');
|
const nextIdx = songs.findIndex((s, i) => i > currentIdx && s.status === 'pending');
|
||||||
if (nextIdx >= 0) {
|
if (nextIdx >= 0) {
|
||||||
// Varighed af nuværende sang + pause
|
const updatedAt = new Date(data.updated_at);
|
||||||
const remainSecs = songDuration(playing) + BETWEEN_DANCE_SEC;
|
const remainSecs = songDuration(playing) + BETWEEN_DANCE_SEC;
|
||||||
etaEl.style.display = '';
|
const nextStart = new Date(updatedAt.getTime() + remainSecs * 1000);
|
||||||
etaValEl.textContent = fmtDur(remainSecs);
|
etaEl.style.display = '';
|
||||||
|
etaValEl.textContent = fmtClock(nextStart);
|
||||||
} else {
|
} else {
|
||||||
etaEl.style.display = 'none';
|
etaEl.style.display = 'none';
|
||||||
}
|
}
|
||||||
@@ -460,9 +464,15 @@ function render(data) {
|
|||||||
document.getElementById('divider').style.display = hasList ? '' : 'none';
|
document.getElementById('divider').style.display = hasList ? '' : 'none';
|
||||||
document.getElementById('next-label').style.display = hasList ? '' : 'none';
|
document.getElementById('next-label').style.display = hasList ? '' : 'none';
|
||||||
|
|
||||||
// Beregn kumulative tidsestimater fra nuværende position
|
// Beregn klokkeslæt for alle sange ud fra updated_at
|
||||||
|
// Udgangspunkt: updated_at = hvornår nuværende sang startede
|
||||||
|
const baseTime = data.updated_at ? new Date(data.updated_at) : null;
|
||||||
const playingIdx = songs.findIndex(s => s.status === 'playing');
|
const playingIdx = songs.findIndex(s => s.status === 'playing');
|
||||||
let cumSecs = 0;
|
let cumSecs = 0; // akkumuleret tid fra nuværende sang
|
||||||
|
|
||||||
|
// Nuværende sang: start = baseTime, slutter baseTime + songDuration
|
||||||
|
// Næste sang: starter baseTime + songDuration + BETWEEN_DANCE_SEC
|
||||||
|
// Osv.
|
||||||
|
|
||||||
document.getElementById('song-list').innerHTML = songs.map((s, i) => {
|
document.getElementById('song-list').innerHTML = songs.map((s, i) => {
|
||||||
const icon = s.status === 'played' ? '✓' :
|
const icon = s.status === 'played' ? '✓' :
|
||||||
@@ -472,13 +482,23 @@ function render(data) {
|
|||||||
const name = getDanceName(s);
|
const name = getDanceName(s);
|
||||||
const sub = (!s.is_workshop && s.title) ? s.title + (s.artist ? ' · ' + s.artist : '') : '';
|
const sub = (!s.is_workshop && s.title) ? s.title + (s.artist ? ' · ' + s.artist : '') : '';
|
||||||
|
|
||||||
// ETA for pending sange efter den der spiller
|
|
||||||
let etaTxt = '';
|
let etaTxt = '';
|
||||||
if (s.status === 'pending' && playingIdx >= 0 && i > playingIdx) {
|
|
||||||
cumSecs += songDuration(songs[i-1] || s) + BETWEEN_DANCE_SEC;
|
if (s.status === 'playing' && baseTime) {
|
||||||
if (cumSecs > 0) etaTxt = `~${fmtDur(cumSecs)}`;
|
// Aktuel sang — viser ikke ETA (den vises i np-eta)
|
||||||
} else if (s.status === 'playing') {
|
cumSecs = songDuration(s) + BETWEEN_DANCE_SEC;
|
||||||
cumSecs = 0;
|
|
||||||
|
} else if (s.status === 'pending' && playingIdx >= 0 && i > playingIdx && baseTime) {
|
||||||
|
// Pending sang efter den aktive — beregn klokkeslæt
|
||||||
|
const startTime = new Date(baseTime.getTime() + cumSecs * 1000);
|
||||||
|
etaTxt = 'ca. ' + fmtClock(startTime);
|
||||||
|
cumSecs += songDuration(s) + BETWEEN_DANCE_SEC;
|
||||||
|
|
||||||
|
} else if (s.status === 'pending' && playingIdx < 0 && baseTime) {
|
||||||
|
// Ingen sang spiller — estimér fra nu
|
||||||
|
const startTime = new Date(baseTime.getTime() + cumSecs * 1000);
|
||||||
|
etaTxt = 'ca. ' + fmtClock(startTime);
|
||||||
|
cumSecs += songDuration(s) + BETWEEN_DANCE_SEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `
|
return `
|
||||||
|
|||||||
Reference in New Issue
Block a user