78 lines
2.6 KiB
JavaScript
78 lines
2.6 KiB
JavaScript
/* VitFit display.js — used by workout-display.html and crossfit-display.html */
|
|
'use strict';
|
|
|
|
const Display = (() => {
|
|
let _keepAliveEl = null;
|
|
|
|
function renderWorkout(workout) {
|
|
const gridEl = document.getElementById('display-video-grid');
|
|
if (!gridEl) return;
|
|
|
|
const slots = (workout.videos || []).filter(s => s.video);
|
|
const count = Math.min(slots.length, 4);
|
|
|
|
if (!count) {
|
|
gridEl.innerHTML = '<div class="display-no-videos">No exercises assigned.</div>';
|
|
return;
|
|
}
|
|
|
|
const jwt = Auth.getJwt();
|
|
const selectedOrg = Auth.getSelectedOrg();
|
|
const orgParam = selectedOrg ? `&orgId=${selectedOrg.id}` : '';
|
|
|
|
const isPreview = new URLSearchParams(window.location.search).get('preview') === '1';
|
|
|
|
gridEl.className = `display-video-grid panes-${count}`;
|
|
gridEl.innerHTML = slots.slice(0, 4).map(slot => {
|
|
const streamSrc = slot.video.streamUrl
|
|
? `${slot.video.streamUrl}?token=${encodeURIComponent(jwt || '')}${orgParam}`
|
|
: '';
|
|
return `
|
|
<div class="display-pane">
|
|
${streamSrc
|
|
? `<video class="display-pane-video" src="${streamSrc}" autoplay loop muted playsinline></video>`
|
|
: `<div class="display-pane-missing">${isPreview ? (slot.video.description || 'Video') : 'Missing Video'}</div>`}
|
|
${slot.reps ? `<div class="display-pane-corner">${slot.reps}</div>` : ''}
|
|
</div>`;
|
|
}).join('');
|
|
}
|
|
|
|
function renderCrossfit(workout) {
|
|
const nameEl = document.getElementById('display-cf-name');
|
|
const dateEl = document.getElementById('display-cf-date');
|
|
const listEl = document.getElementById('display-cf-list');
|
|
|
|
if (nameEl) nameEl.textContent = workout.name || '';
|
|
if (dateEl && workout.workoutDate) {
|
|
dateEl.textContent = new Date(workout.workoutDate).toLocaleDateString('en-US', { month: 'long', day: 'numeric' });
|
|
}
|
|
|
|
if (listEl) {
|
|
listEl.innerHTML = '';
|
|
(workout.workoutItems || []).forEach(item => {
|
|
const li = document.createElement('li');
|
|
li.className = 'display-crossfit-item';
|
|
li.textContent = item;
|
|
listEl.appendChild(li);
|
|
});
|
|
}
|
|
}
|
|
|
|
function setOffline(isOffline) {
|
|
document.getElementById('display-offline-banner')?.classList.toggle('visible', isOffline);
|
|
}
|
|
|
|
function startKeepAlive() {
|
|
if (_keepAliveEl) return;
|
|
_keepAliveEl = document.createElement('div');
|
|
_keepAliveEl.className = 'keep-alive';
|
|
document.body.appendChild(_keepAliveEl);
|
|
}
|
|
|
|
function applyBranding(branding) {
|
|
Branding.apply(branding);
|
|
}
|
|
|
|
return { renderWorkout, renderCrossfit, setOffline, startKeepAlive, applyBranding };
|
|
})();
|