Same pattern as GameStream (commit 6a46007), adapted for CollabTable being genuinely multi-user (not single-admin): admin user management (list/create/update/delete, role reassignment, superadmin protection) is fully proxied to AuthGuard, which already enforces the same rules CollabTable checked locally. Cookie forwarding, no local session token, AUTHGUARD_URL optional (unset = auth fully disabled), transport failures always surface as errAuthGuardUnavailable rather than ever letting a request through - proven with live tests against a closed socket. CollabTable's device-sync API token feature (separate from browser sessions) is deliberately left local-only regardless of AUTHGUARD_URL, keyed by a new currentUserID helper (AuthGuard's id when enabled, the shared placeholder id 0 when disabled) - a real, functional token either way, not faked data. Real bug found and fixed: api_tokens.user_id had a hard FK into the local auth_users table, which would reject new tokens once accounts stop being written locally. Dropped the now-invalid FK. Known, accepted gap (same as GameStream): self-service profile editing for non-admin accounts is lost, since AuthGuard only exposes an admin endpoint, no self-edit. TOTP QR issuer branding now comes from AuthGuard rather than CollabTable. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
123 lines
4.1 KiB
JavaScript
123 lines
4.1 KiB
JavaScript
// NCSpinner - shared circular loading spinner component
|
|
// Served at /shared/js/ui/spinner.js by applySharedBase.
|
|
//
|
|
// API:
|
|
// NCSpinner.create([opts]) -> returns wrapper element (not inserted into DOM)
|
|
// NCSpinner.show(container, [opts]) -> inserts full-area overlay spinner; returns element
|
|
// NCSpinner.hide(el) -> removes element from DOM safely
|
|
//
|
|
// opts:
|
|
// size : 'sm'|'md'|'lg'|'xl' - maps to CSS utility class pairs in index.css (default 'lg')
|
|
// color : CSS text-color utility class from index.css (default 'text-slate-400')
|
|
// label : accessible label string (default 'Loading...')
|
|
// text : visible text string displayed below the spinner (default none)
|
|
// id : optional id attribute on the wrapper
|
|
// overlay : bool - if true (default), wrapper fills its positioned parent absolutely
|
|
|
|
(function (global) {
|
|
'use strict';
|
|
|
|
var SIZES = { sm: 'h-8 w-8', md: 'h-10 w-10', lg: 'h-12 w-12', xl: 'h-16 w-16' };
|
|
var SVG_NS = 'http://www.w3.org/2000/svg';
|
|
|
|
function makeSvg(sizeClass, color) {
|
|
var svg = document.createElementNS(SVG_NS, 'svg');
|
|
svg.setAttribute('class', 'animate-spin ' + sizeClass + ' ' + color);
|
|
svg.setAttribute('fill', 'none');
|
|
svg.setAttribute('viewBox', '0 0 24 24');
|
|
svg.setAttribute('aria-hidden', 'true');
|
|
|
|
var circle = document.createElementNS(SVG_NS, 'circle');
|
|
circle.setAttribute('class', 'opacity-25');
|
|
circle.setAttribute('cx', '12');
|
|
circle.setAttribute('cy', '12');
|
|
circle.setAttribute('r', '10');
|
|
circle.setAttribute('stroke', 'currentColor');
|
|
circle.setAttribute('stroke-width', '4');
|
|
svg.appendChild(circle);
|
|
|
|
var path = document.createElementNS(SVG_NS, 'path');
|
|
path.setAttribute('class', 'opacity-75');
|
|
path.setAttribute('fill', 'currentColor');
|
|
path.setAttribute('d', 'M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z');
|
|
svg.appendChild(path);
|
|
|
|
return svg;
|
|
}
|
|
|
|
/**
|
|
* Create a spinner wrapper element without inserting it.
|
|
* @param {object} [opts]
|
|
* @returns {HTMLElement}
|
|
*/
|
|
function create(opts) {
|
|
opts = opts || {};
|
|
var size = opts.size || 'md';
|
|
var color = opts.color || 'text-slate-400';
|
|
var label = opts.label || 'Loading\u2026';
|
|
var text = opts.text || '';
|
|
var extraCls = opts.wrapClass || '';
|
|
|
|
var sizeClass = SIZES[size] || size;
|
|
|
|
var wrap = document.createElement('div');
|
|
var flexDir = text ? 'flex-col gap-3 ' : '';
|
|
wrap.className = (
|
|
'pointer-events-none flex ' +
|
|
flexDir +
|
|
'items-center justify-center ' +
|
|
extraCls
|
|
).trim();
|
|
wrap.setAttribute('role', 'status');
|
|
wrap.setAttribute('aria-label', label);
|
|
wrap.appendChild(makeSvg(sizeClass, color));
|
|
|
|
if (text) {
|
|
var textEl = document.createElement('div');
|
|
textEl.className =
|
|
'text-xs font-semibold uppercase tracking-[0.5px] text-[var(--color-text-dim)]';
|
|
textEl.textContent = text;
|
|
wrap.appendChild(textEl);
|
|
}
|
|
|
|
return wrap;
|
|
}
|
|
|
|
/**
|
|
* Insert an overlay spinner as a child of `container` (defaults to document.body).
|
|
* @param {Element|null} container
|
|
* @param {object} [opts]
|
|
* @returns {HTMLElement} the inserted element
|
|
*/
|
|
function show(container, opts) {
|
|
opts = opts || {};
|
|
var overlay = opts.overlay !== false;
|
|
var wrapClass = overlay ? 'absolute inset-0 z-10' : '';
|
|
|
|
var el = create({
|
|
size: opts.size || 'lg',
|
|
color: opts.color || 'text-slate-400',
|
|
label: opts.label || 'Loading\u2026',
|
|
text: opts.text || '',
|
|
wrapClass: wrapClass,
|
|
});
|
|
|
|
if (opts.id) el.id = opts.id;
|
|
(container || document.body).appendChild(el);
|
|
return el;
|
|
}
|
|
|
|
/**
|
|
* Remove a spinner element previously returned by show().
|
|
* @param {Element|null} el
|
|
*/
|
|
function hide(el) {
|
|
try {
|
|
if (el && el.parentNode) el.parentNode.removeChild(el);
|
|
// eslint-disable-next-line no-empty
|
|
} catch {}
|
|
}
|
|
|
|
global.NCSpinner = { create: create, show: show, hide: hide };
|
|
})(window);
|