soulsync/webui/static/video/video-tools.js
BoulderBadgeDad 71f126f9d2 video side: Tools page + scan controls on dashboard (3 modes)
- New Tools page (video nav + subpage, mirrors music tools styling): a Library
  Scan tool card with Incremental / Full Refresh / Deep Scan buttons + a live
  status line. Room for more maintenance jobs later.
- Dashboard Library card now has Refresh (full) + Deep Scan buttons, like the
  music dashboard.
- Shared video-scan.js controller: one place triggers + polls scans for all
  surfaces (wires any [data-video-scan-mode]/[data-video-scan]); emits
  soulsync:video-scan-progress/done. Library/Tools/Dashboard just listen — no
  duplicated fetch/poll. video-library.js refactored onto it; dashboard reloads
  stats on scan-done.
- All isolated IIFEs, data-attr wired (no inline onclick). video-tools added to
  the nav (13 pages). 110 tests green.
2026-06-13 23:34:28 -07:00

56 lines
1.8 KiB
JavaScript

/*
* SoulSync — Video Tools page (isolated).
*
* The scan buttons (data-video-scan-mode) are wired by video-scan.js; this
* module just reflects scan progress/result into the tool card's status line
* and disables the buttons while a scan runs. Self-contained IIFE, no globals.
*/
(function () {
'use strict';
function statusNode() {
return document.querySelector('[data-video-tools-scan-status]');
}
function setStatus(text) {
var n = statusNode();
if (n) n.textContent = text;
}
function setButtonsDisabled(disabled) {
var btns = document.querySelectorAll(
'[data-video-subpage="video-tools"] [data-video-scan-mode]');
for (var i = 0; i < btns.length; i++) btns[i].disabled = disabled;
}
function onProgress(e) {
var s = e.detail || {};
if (s.state !== 'scanning') return;
setButtonsDisabled(true);
setStatus((s.phase || 'Scanning') + '… '
+ (s.movies || 0) + ' movies, ' + (s.shows || 0) + ' shows');
}
function onDone(e) {
var s = e.detail || {};
setButtonsDisabled(false);
if (s.state === 'error') {
setStatus('Failed' + (s.error ? ': ' + s.error : ''));
} else {
var msg = 'Done — ' + (s.movies || 0) + ' movies, ' + (s.shows || 0) + ' shows';
if (s.removed) msg += ', ' + s.removed + ' removed';
setStatus(msg);
}
}
function init() {
document.addEventListener('soulsync:video-scan-progress', onProgress);
document.addEventListener('soulsync:video-scan-done', onDone);
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
})();