Add rich dashboard animations with reduced-motion support
This commit is contained in:
1 parent
25abce19e8
commit
f646339781
6 files changed
+255
-21
No files matched your search
+85
-16
@@ -5,7 +5,14 @@ const $ = selector => document.querySelector(selector);
|
||||
const $$ = selector => [...document.querySelectorAll(selector)];
|
||||
const html = value => String(value ?? '—').replace(/[&<>"']/g, char => ({'&': '&', '<': '<', '>': '>', '"': '"', "'": '''}[char]));
|
||||
const icon = name => `<svg class="icon" aria-hidden="true"><use href="#icon-${name}"/></svg>`;
|
||||
const set = (id, value) => { const node = $(`#${id}`); if (node) node.textContent = value; };
|
||||
const set = (id, value) => {
|
||||
const node = $(`#${id}`);
|
||||
if (!node || node.textContent === String(value)) return;
|
||||
node.textContent = value;
|
||||
if (node.matches('.summary-card strong, .metric-line strong, .nav-count')) {
|
||||
animate(node, [{opacity: .45, transform: 'translateY(3px)'}, {opacity: 1, transform: 'translateY(0)'}], {duration: 300});
|
||||
}
|
||||
};
|
||||
const percent = value => Math.max(0, Math.min(100, Number(value) || 0));
|
||||
const bar = (id, value) => { const node = $(`#${id}`); if (node) node.style.width = `${percent(value)}%`; };
|
||||
let language = localStorage.getItem('dashboard-language') === 'en' ? 'en' : 'de';
|
||||
@@ -14,6 +21,45 @@ const number = value => Number(value || 0).toLocaleString(language === 'en' ? 'e
|
||||
const empty = message => `<div class="empty-state">${html(message)}</div>`;
|
||||
let activeView = 'dashboard';
|
||||
const snapshots = {};
|
||||
const motionPreference = window.matchMedia('(prefers-reduced-motion: reduce)');
|
||||
const entranceAnimations = new WeakMap();
|
||||
const renderedContainers = new WeakSet();
|
||||
let viewInitialized = false;
|
||||
|
||||
function animate(node, frames, options = {}) {
|
||||
if (motionPreference.matches || document.hidden || !node.getClientRects().length || typeof node.animate !== 'function') return;
|
||||
entranceAnimations.get(node)?.cancel();
|
||||
const animation = node.animate(frames, {duration: 420, easing: 'cubic-bezier(.22, 1, .36, 1)', fill: 'backwards', ...options});
|
||||
entranceAnimations.set(node, animation);
|
||||
}
|
||||
|
||||
motionPreference.addEventListener('change', event => {
|
||||
if (event.matches) document.getAnimations().forEach(animation => animation.cancel());
|
||||
});
|
||||
|
||||
function animateEntrance(root) {
|
||||
const targets = root.querySelectorAll('.page-heading, .summary-card, .panel, .toolbar, .series, .service-row, .raid-disk, .disk-row, .graphics-process');
|
||||
// Bound the work even when a media library contains thousands of entries.
|
||||
[...targets].slice(0, 24).forEach((node, index) => {
|
||||
animate(node, [{opacity: 0, transform: 'translateY(12px)'}, {opacity: 1, transform: 'translateY(0)'}], {delay: Math.min(index * 35, 210)});
|
||||
});
|
||||
}
|
||||
|
||||
function renderContent(id, markup) {
|
||||
const root = $(`#${id}`);
|
||||
if (!root || root.innerHTML === markup) return;
|
||||
const previousWidths = [...root.querySelectorAll('.track > span')].map(node => node.style.width);
|
||||
root.innerHTML = markup;
|
||||
root.querySelectorAll('.track > span').forEach((node, index) => {
|
||||
const from = previousWidths[index] || '0%';
|
||||
if (from !== node.style.width) animate(node, [{width: from}, {width: node.style.width}], {duration: 650});
|
||||
});
|
||||
// Polling updates must not make whole panels re-enter every few seconds.
|
||||
if (!renderedContainers.has(root)) {
|
||||
animateEntrance(root);
|
||||
renderedContainers.add(root);
|
||||
}
|
||||
}
|
||||
|
||||
function closeSidebar() {
|
||||
document.body.classList.remove('sidebar-open');
|
||||
@@ -24,6 +70,7 @@ function closeSidebar() {
|
||||
function switchView(view) {
|
||||
const button = $(`.nav button[data-view="${view}"]`);
|
||||
if (!button || !$(`#${view}`)) return;
|
||||
const changed = !viewInitialized || activeView !== view;
|
||||
activeView = view;
|
||||
$$('.view').forEach(node => node.classList.toggle('active', node.id === view));
|
||||
$$('.nav button').forEach(node => {
|
||||
@@ -35,6 +82,10 @@ function switchView(view) {
|
||||
sessionStorage.setItem('dashboard-active-view', view);
|
||||
if (['radarr', 'sonarr', 'missing'].includes(view)) $('#scanSource').value = view;
|
||||
closeSidebar();
|
||||
if (changed) {
|
||||
animateEntrance($(`#${view}`));
|
||||
viewInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
function translateLayout() {
|
||||
@@ -107,6 +158,15 @@ function applyFilters(prefix) {
|
||||
$(`#${prefix}NoResults`)?.classList.toggle('hidden', visible > 0);
|
||||
}
|
||||
|
||||
function animateFilterResults(prefix) {
|
||||
const root = $(prefix === 'movie' ? '#movies tbody' : '#seriesList');
|
||||
if (!root) return;
|
||||
const selector = prefix === 'movie' ? 'tr[data-title]:not(.hidden)' : '.series:not(.hidden)';
|
||||
[...root.querySelectorAll(selector)].slice(0, 12).forEach((node, index) => {
|
||||
animate(node, [{opacity: .35}, {opacity: 1}], {duration: 240, delay: index * 15});
|
||||
});
|
||||
}
|
||||
|
||||
function updateSeasonDividers(root) {
|
||||
root.querySelectorAll('.season-divider').forEach(divider => {
|
||||
let next = divider.nextElementSibling, count = 0;
|
||||
@@ -138,7 +198,9 @@ $$('[data-filter] input, [data-filter] select').forEach(input => {
|
||||
else if (input.id.endsWith('Subs')) input.value = localStorage.getItem('preferred-subs') || '';
|
||||
input.addEventListener(input.type === 'search' ? 'input' : 'change', () => {
|
||||
sessionStorage.setItem(`filter-${input.id}`, input.value);
|
||||
applyFilters(input.closest('[data-filter]').dataset.filter);
|
||||
const prefix = input.closest('[data-filter]').dataset.filter;
|
||||
applyFilters(prefix);
|
||||
animateFilterResults(prefix);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -217,14 +279,14 @@ function renderSystem(data) {
|
||||
set('ramDetail', `${memory.used || '—'} / ${memory.total || '—'}`);
|
||||
bar('cpuBar', cpu); bar('ramBar', memory.percent);
|
||||
set('systemUpdated', `${t('Aktualisiert', 'Updated')} ${new Date().toLocaleTimeString(language === 'de' ? 'de-DE' : 'en-GB')}`);
|
||||
$('#systemDetails').innerHTML = `<div><small>Load Average</small><strong>${(data.load || []).map(value => Number(value).toFixed(2)).join(' · ') || '—'}</strong></div><div><small>Uptime</small><strong>${html(duration(data.uptime_seconds))}</strong></div><div><small>${t('Prozesse', 'Processes')}</small><strong>${number(data.processes)}</strong></div>`;
|
||||
$('#diskList').innerHTML = (data.disks || []).map(disk => `<div class="disk-row"><div>${html(disk.label)}<small>${html(disk.path)}</small></div><div class="track"><span style="width:${percent(disk.percent)}%"></span></div><div class="disk-values">${html(disk.used)} / ${html(disk.total)}<small>${percent(disk.percent).toFixed(1)}%</small></div></div>`).join('') || empty(t('Keine Laufwerke erkannt.', 'No disks detected.'));
|
||||
renderContent('systemDetails', `<div><small>Load Average</small><strong>${(data.load || []).map(value => Number(value).toFixed(2)).join(' · ') || '—'}</strong></div><div><small>Uptime</small><strong>${html(duration(data.uptime_seconds))}</strong></div><div><small>${t('Prozesse', 'Processes')}</small><strong>${number(data.processes)}</strong></div>`);
|
||||
renderContent('diskList', (data.disks || []).map(disk => `<div class="disk-row"><div>${html(disk.label)}<small>${html(disk.path)}</small></div><div class="track"><span style="width:${percent(disk.percent)}%"></span></div><div class="disk-values">${html(disk.used)} / ${html(disk.total)}<small>${percent(disk.percent).toFixed(1)}%</small></div></div>`).join('') || empty(t('Keine Laufwerke erkannt.', 'No disks detected.')));
|
||||
}
|
||||
|
||||
function renderServices(data) {
|
||||
set('serviceSummary', `${data.online || 0} / ${data.total || 0} online`);
|
||||
const labels = {online: t('Aktiv', 'Online'), offline: 'Offline', timeout: 'Timeout', checking: t('Prüfe …', 'Checking …'), error: t('Fehler', 'Error')};
|
||||
$('#serviceList').innerHTML = (data.services || []).map(service => `<div class="service-row"><span class="service-logo">${html(service.name.slice(0, 1))}</span><div><strong>${html(service.name)}</strong><small title="${html(service.detail)}">${html(service.detail || '—')}</small></div><span class="service-status ${html(service.status)}">${html(labels[service.status] || service.label)}</span></div>`).join('');
|
||||
renderContent('serviceList', (data.services || []).map(service => `<div class="service-row"><span class="service-logo">${html(service.name.slice(0, 1))}</span><div><strong>${html(service.name)}</strong><small title="${html(service.detail)}">${html(service.detail || '—')}</small></div><span class="service-status ${html(service.status)}">${html(labels[service.status] || service.label)}</span></div>`).join(''));
|
||||
}
|
||||
|
||||
function downloadRow(item) {
|
||||
@@ -246,7 +308,7 @@ function renderDownloads(data) {
|
||||
const others = items.filter(item => !active.includes(item));
|
||||
for (const [id, list] of [['activeDownloads', active], ['otherDownloads', others]]) {
|
||||
set(`${id}Count`, number(list.length));
|
||||
$(`#${id}Body`).innerHTML = list.length ? list.map(downloadRow).join('') : `<tr><td colspan="7" class="empty-state">${t('Keine Einträge.', 'No entries.')}</td></tr>`;
|
||||
renderContent(`${id}Body`, list.length ? list.map(downloadRow).join('') : `<tr><td colspan="7" class="empty-state">${t('Keine Einträge.', 'No entries.')}</td></tr>`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,7 +321,7 @@ function renderDatastore(data) {
|
||||
set('datastoreUpdated', storage.scanned_at ? `${t('Speicher-Scan', 'Storage scan')} ${new Date(storage.scanned_at * 1000).toLocaleTimeString()}` : t('Nicht verfügbar', 'Unavailable'));
|
||||
$('#storageWarning').classList.toggle('hidden', !storage.error && !storage.warning);
|
||||
set('storageWarning', storage.error || storage.warning || '');
|
||||
$('#datastoreCategories').innerHTML = (storage.categories || []).map(category => `<div class="category-row"><div class="metric-line"><span>${html(category.label)}</span><strong>${html(category.size || '0 B')}</strong></div><div class="track"><span style="width:${percent(category.percent)}%"></span></div><small>${Number(category.percent || 0).toFixed(1)}% ${t('vom belegten Speicher', 'of used storage')} · ${number(category.files)} ${t('Dateien', 'files')}</small></div>`).join('') || empty(t('Keine Kategorien erkannt.', 'No categories detected.'));
|
||||
renderContent('datastoreCategories', (storage.categories || []).map(category => `<div class="category-row"><div class="metric-line"><span>${html(category.label)}</span><strong>${html(category.size || '0 B')}</strong></div><div class="track"><span style="width:${percent(category.percent)}%"></span></div><small>${Number(category.percent || 0).toFixed(1)}% ${t('vom belegten Speicher', 'of used storage')} · ${number(category.files)} ${t('Dateien', 'files')}</small></div>`).join('') || empty(t('Keine Kategorien erkannt.', 'No categories detected.')));
|
||||
const io = data.io_pressure || {}, some = Number(io.some?.avg10) || 0, full = Number(io.full?.avg10) || 0;
|
||||
const pressure = Math.max(some, full);
|
||||
set('ioPressureLabel', io.available ? pressure >= 20 ? t('Hoch', 'High') : pressure >= 5 ? t('Beobachten', 'Watch') : t('Normal', 'Normal') : t('Nicht verfügbar', 'Unavailable'));
|
||||
@@ -267,11 +329,11 @@ function renderDatastore(data) {
|
||||
set('raidDevice', raid.device || '—'); set('raidStatusBadge', raid.label || 'UNKNOWN');
|
||||
$('#raidStatusBadge').className = `badge raid-status ${raid.status || 'unknown'}`;
|
||||
$('#raidWarning').classList.toggle('hidden', !raid.error && !raid.warning); set('raidWarning', raid.error || raid.warning || '');
|
||||
$('#raidSummary').innerHTML = `<div><small>Level</small><strong>${html(raid.level)}</strong></div><div><small>${t('Aktive Laufwerke', 'Active drives')}</small><strong>${html(raid.active_devices)} / ${html(raid.raid_devices)}</strong></div><div><small>${t('Fehlend', 'Missing')}</small><strong>${html(raid.failed_devices ?? '—')}</strong></div>`;
|
||||
renderContent('raidSummary', `<div><small>Level</small><strong>${html(raid.level)}</strong></div><div><small>${t('Aktive Laufwerke', 'Active drives')}</small><strong>${html(raid.active_devices)} / ${html(raid.raid_devices)}</strong></div><div><small>${t('Fehlend', 'Missing')}</small><strong>${html(raid.failed_devices ?? '—')}</strong></div>`);
|
||||
const recovery = raid.recovery || {};
|
||||
$('#raidRecovery').classList.toggle('hidden', !recovery.active); set('raidRecoveryPercent', `${Number(recovery.percent || 0).toFixed(1)}%`);
|
||||
set('raidRecoverySpeed', recovery.speed || '—'); set('raidRecoveryFinish', recovery.finish || '—'); bar('raidRecoveryBar', recovery.percent);
|
||||
$('#raidDisks').innerHTML = (raid.devices || []).map(disk => `<div class="raid-disk"><span class="disk-status ${html(disk.status)}"></span><div><strong>${html(disk.device)}</strong><small>Slot ${html(disk.slot)} · ${html(disk.model)}</small><small>${html(disk.size)} · Serial: ${html(disk.serial)}</small><small>SMART: ${html(disk.smart || t('Nicht aktiviert', 'Not enabled'))} · ${html(disk.temperature || '—')}</small></div><b>${html(disk.status)}</b></div>`).join('') || empty(t('Keine RAID-Mitglieder erkannt.', 'No RAID members detected.'));
|
||||
renderContent('raidDisks', (raid.devices || []).map(disk => `<div class="raid-disk"><span class="disk-status ${html(disk.status)}"></span><div><strong>${html(disk.device)}</strong><small>Slot ${html(disk.slot)} · ${html(disk.model)}</small><small>${html(disk.size)} · Serial: ${html(disk.serial)}</small><small>SMART: ${html(disk.smart || t('Nicht aktiviert', 'Not enabled'))} · ${html(disk.temperature || '—')}</small></div><b>${html(disk.status)}</b></div>`).join('') || empty(t('Keine RAID-Mitglieder erkannt.', 'No RAID members detected.')));
|
||||
}
|
||||
|
||||
const gpuValue = (value, unit = '') => value == null || value === '' ? '—' : `${html(value)}${unit}`;
|
||||
@@ -284,12 +346,12 @@ function renderGraphics(data) {
|
||||
};
|
||||
const used = gpus.reduce((sum, gpu) => sum + (Number(gpu['memory.used']) || 0), 0), total = gpus.reduce((sum, gpu) => sum + (Number(gpu['memory.total']) || 0), 0);
|
||||
const metrics = [['GPUs', gpus.length], [t('GPU-Auslastung', 'GPU usage'), gpuValue(average('utilization.gpu'), '%')], ['VRAM', total ? `${(used / 1024).toFixed(1)} / ${(total / 1024).toFixed(1)} GB` : '—'], [t('Temperatur', 'Temperature'), gpuValue(average('temperature.gpu'), ' °C')]];
|
||||
$('#graphicsSummary').innerHTML = metrics.map(([label, value]) => `<article class="summary-card"><span class="summary-icon purple">${icon('chip')}</span><div><strong>${value}</strong><span>${html(label)}</span></div></article>`).join('');
|
||||
$('#graphicsCards').innerHTML = gpus.length ? gpus.map(gpu => {
|
||||
renderContent('graphicsSummary', metrics.map(([label, value]) => `<article class="summary-card"><span class="summary-icon purple">${icon('chip')}</span><div><strong>${value}</strong><span>${html(label)}</span></div></article>`).join(''));
|
||||
renderContent('graphicsCards', gpus.length ? gpus.map(gpu => {
|
||||
const used = Number(gpu['memory.used']) || 0, total = Number(gpu['memory.total']) || 0;
|
||||
return `<article class="panel"><div class="panel-heading"><div><small class="muted">GPU ${html(gpu.index)}</small><h2>${html(gpu.name)}</h2></div><span class="badge">${gpuValue(gpu['temperature.gpu'], ' °C')}</span></div><div class="graphics-meta-grid"><div><small>${t('GPU-Last', 'GPU load')}</small><strong>${gpuValue(gpu['utilization.gpu'], '%')}</strong></div><div><small>${t('Memory-Last', 'Memory load')}</small><strong>${gpuValue(gpu['utilization.memory'], '%')}</strong></div><div><small>${t('Leistung', 'Power')}</small><strong>${gpuValue(gpu['power.draw'], ' W')} / ${gpuValue(gpu['power.limit'], ' W')}</strong></div><div><small>P-State</small><strong>${html(gpu.pstate)}</strong></div></div><div class="coverage-row" style="margin-top:22px"><div class="metric-line"><span>VRAM</span><strong>${total ? `${(used / 1024).toFixed(1)} / ${(total / 1024).toFixed(1)} GB` : '—'}</strong></div><div class="track purple-track"><span style="width:${total ? percent(used / total * 100) : 0}%"></span></div></div><div class="graphics-details"><span>${t('Treiber', 'Driver')}: ${html(gpu.driver_version)} · PCI: ${html(gpu['pci.bus_id'])}</span><span>UUID: ${html(gpu.uuid)}</span><span>Serial: ${html(gpu.serial)}</span><span>Clocks: ${gpuValue(gpu['clocks.current.graphics'], ' MHz')} · Memory: ${gpuValue(gpu['clocks.current.memory'], ' MHz')}</span><span>Fan: ${gpuValue(gpu['fan.speed'], '%')} · Compute: ${html(gpu.compute_mode)}</span></div></article>`;
|
||||
}).join('') : `<div class="panel">${empty(data.error || t('Keine NVIDIA-GPU erkannt.', 'No NVIDIA GPU detected.'))}</div>`;
|
||||
$('#graphicsProcesses').innerHTML = (data.processes || []).map(process => `<div class="graphics-process"><strong>${html(process.name)}</strong><span>PID ${html(process.pid)}</span><span>${html(process.memory)}</span></div>`).join('') || empty(t('Keine GPU-Prozesse erkannt.', 'No GPU processes detected.'));
|
||||
}).join('') : `<div class="panel">${empty(data.error || t('Keine NVIDIA-GPU erkannt.', 'No NVIDIA GPU detected.'))}</div>`);
|
||||
renderContent('graphicsProcesses', (data.processes || []).map(process => `<div class="graphics-process"><strong>${html(process.name)}</strong><span>PID ${html(process.pid)}</span><span>${html(process.memory)}</span></div>`).join('') || empty(t('Keine GPU-Prozesse erkannt.', 'No GPU processes detected.')));
|
||||
}
|
||||
|
||||
let scanRunning = false;
|
||||
@@ -305,19 +367,26 @@ function renderScanStatus(data) {
|
||||
job.state === 'done' ? t('Scan abgeschlossen', 'Scan complete') : job.state === 'error' ? `${t('Scanfehler', 'Scan error')}: ${job.error}` : t('Scan bereit', 'Ready to scan');
|
||||
}
|
||||
$('#rescan').disabled = scanRunning;
|
||||
$('#rescan').classList.toggle('is-scanning', scanRunning);
|
||||
$('#rescan').setAttribute('aria-busy', String(scanRunning));
|
||||
const label = $('#rescan span');
|
||||
label.textContent = scanRunning ? t('Scan läuft …', 'Scanning …') : t('Neu scannen', 'Rescan');
|
||||
}
|
||||
|
||||
$('#rescan').addEventListener('click', async () => {
|
||||
$('#rescan').disabled = true; $('#actionError').classList.add('hidden');
|
||||
$('#rescan').disabled = true; $('#rescan').classList.add('is-scanning');
|
||||
$('#rescan').setAttribute('aria-busy', 'true'); $('#actionError').classList.add('hidden');
|
||||
try {
|
||||
const data = await api(`/api/rescan?source=${encodeURIComponent($('#scanSource').value)}`, {method: 'POST'});
|
||||
if (!data.ok) throw new Error(data.error || t('Scan konnte nicht gestartet werden.', 'Could not start scan.'));
|
||||
renderScanStatus(await api('/api/scan-status'));
|
||||
} catch (error) {
|
||||
set('actionError', `${t('Scan fehlgeschlagen', 'Scan failed')}: ${error.message}`); $('#actionError').classList.remove('hidden');
|
||||
} finally { $('#rescan').disabled = scanRunning; }
|
||||
} finally {
|
||||
$('#rescan').disabled = scanRunning;
|
||||
$('#rescan').classList.toggle('is-scanning', scanRunning);
|
||||
$('#rescan').setAttribute('aria-busy', String(scanRunning));
|
||||
}
|
||||
});
|
||||
|
||||
const renderers = {system: renderSystem, services: renderServices, downloads: renderDownloads, datastore: renderDatastore, graphics: renderGraphics, scans: renderScanStatus};
|
||||
@@ -354,4 +423,4 @@ monitor('graphics', '/api/graphics', 5000, () => renderGraphics({error: t('GPU-S
|
||||
monitor('scans', '/api/scan-status', 1500);
|
||||
if (config.sabEnabled) monitor('downloads', '/api/downloads', 4000, () => renderDownloads({error: t('SABnzbd nicht erreichbar.', 'SABnzbd unavailable.')}));
|
||||
pollLibrary();
|
||||
if ('serviceWorker' in navigator) window.addEventListener('load', () => navigator.serviceWorker.register('/sw.js?v=8', {scope: '/'}).catch(() => {}));
|
||||
if ('serviceWorker' in navigator) window.addEventListener('load', () => navigator.serviceWorker.register('/sw.js?v=10', {scope: '/'}).catch(() => {}));
|
||||
Reference in new issue
Block a user