Interfaccia web, parte 1: ospite, sicurezza, API, modalità dimostrativa, libreria, visualizzatore e account

Febe.Web: AddFebeWeb/UseFebe/FebeWebHost per le due vesti, interfaccia incorporata con IFileProvider proprio, indirizzi italiani, API JSON con contesto generato, eventi SSE, controlli di Host/Origin, gettone del desktop e password con blocco (§13.1), INativeShell e capacità per veste. Modalità --demo con 38 account e circa 18.000 elementi finti e scene del motore. Pagine Libreria, Visualizzatore, Account, Aggiungi account e Scheda account (contenuti, impostazioni con piano, cronologia); schermate in docs/schermate con le differenze dai mockup; prove delle API, della sicurezza, dell'esportazione CSV e dei dati dimostrativi.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
This commit is contained in:
Claude committed 2026-10-13 19:14:35 +00:00
1 parent 6ff11ac8e3
commit e33540246e
76 files changed
+12503 -17

No files matched your search

+335
View File
@@ -0,0 +1,335 @@
// The frame of every page (spec §10.2): fixed 228 px sidebar with brand, Libreria, Account, Attività, Importa,
// separator, Impostazioni, and the status box always visible at the bottom; on the right the page: title row,
// optional tools row, scrolling content, fixed bar for the actions that save. The red strip (mockup 11) appears under
// the title of every page while the engine is stopped and needs Alberto. Also the router of the addresses.
import { api, withCarried } from './api.js';
import { caps } from './context.js';
import { h, icon, brand, fill } from './dom.js';
import { dotOf, onEngine, onLibrary, refreshEngine, engineState } from './engine.js';
import { t } from './text.js';
import { avatar, showError, toast, closeMenu } from './ui.js';
import { routes } from '../routes.js';
const NAV = [
{ key: 'libreria', href: '/libreria', icon: 'layout-grid' },
{ key: 'account', href: '/account', icon: 'users' },
{ key: 'attivita', href: '/attivita', icon: 'activity' },
{ key: 'importa', href: '/importa', icon: 'folder-input' },
'stacco',
{ key: 'impostazioni', href: '/impostazioni', icon: 'settings' },
];
let main;
let navLinks = {};
let statusBox;
let current = null;
let renderToken = 0;
/** Builds the sidebar and the page area inside root. */
export function buildShell(root) {
const links = NAV.map((item) => {
if (item === 'stacco') return h('div.stacco', { role: 'separator' });
const a = h('a', { href: withCarried(item.href), dataset: { nav: item.key } }, icon(item.icon), h('span', t(`nav.${item.key}`)));
navLinks[item.key] = a;
return a;
});
statusBox = h('a.stato', { href: withCarried('/attivita'), 'aria-label': t('stato.riquadro') });
main = h('main.pagina', { id: 'contenuto', tabindex: '-1' });
fill(root,
h('a.salta', { href: '#contenuto' }, t('app.salta')),
h('div.app',
h('aside.barra',
h('a.marchio', { href: withCarried('/libreria') }, brand(), h('b', t('app.nome'))),
h('nav.nav', { 'aria-label': t('nav.principale') }, links),
h('div.molla'),
statusBox),
main));
onEngine(renderStatus);
renderStatus(null);
}
// ------------------------------------------------------------------------------------------------- status box
function renderStatus(state) {
if (!statusBox) return;
if (!state) {
fill(statusBox, h('div.riga', h('span.spia'), h('span', t('comune.caricamento'))));
return;
}
const s = state.snapshot;
const meter = s.profilesOpenedToday;
const connection = state.connection;
const who = connection.state === 'notConnected'
? h('div.chi', h('span.av.segnaposto', icon('user', 's')),
h('div', h('b', t('stato.nessunAccount')), h('span', t('stato.daCollegare'))))
: h('div.chi', avatar(connection.username || ''),
h('div', h('b', `@${connection.username}`), h('span', t(connection.state === 'verification' ? 'stato.verifica' : connection.state === 'disconnected' ? 'stato.scollegato' : 'stato.collegato'))));
const ratio = Math.max(0, Math.min(1, meter.ratio || 0));
fill(statusBox,
h('div.riga', h(`span.spia${dotOf(s.mode) ? '.' + dotOf(s.mode) : ''}`, { 'aria-hidden': 'true' }), h('span', s.headline)),
h('div.sotto', s.sidebarLine),
h(`div.misura${meter.amber ? '.ambra' : ''}`, { role: 'meter', 'aria-valuemin': '0', 'aria-valuemax': String(meter.limitToday), 'aria-valuenow': String(meter.usedToday), 'aria-label': t('stato.profiliOggi') },
h('i', { style: { width: `${ratio * 100}%` } })),
h('div.conto', h('span', t('stato.profiliOggi')), h('span', `${meter.usedText} ${meter.limitText}`)),
who);
statusBox.title = s.details && s.details.length ? s.details.join(' ') : s.headline;
const attention = navLinks.attivita;
if (attention) {
const dot = attention.querySelector('.punto');
if (s.banner && !dot) attention.append(h('span.punto', { role: 'img', 'aria-label': t('nav.fermo') }));
if (!s.banner && dot) dot.remove();
}
}
// ------------------------------------------------------------------------------------------------- page frame
/** What a page module receives to draw itself (see LEGGIMI.md). */
class PageFrame {
constructor(route) {
this.route = route;
this.controller = new AbortController();
this.cleanups = [];
this.guards = [];
this.backSlot = h('div', { hidden: true });
this.head = h('header.testa');
this.bannerSlot = h('div', { hidden: true });
this.tabsSlot = h('div', { hidden: true });
this.toolsSlot = h('div.strumenti', { hidden: true });
this.body = h('div.corpo');
this.saveSlot = h('div.salva', { hidden: true });
this.root = h('div', { style: { display: 'contents' } }, this.backSlot, this.head, this.bannerSlot, this.tabsSlot, this.toolsSlot, this.body, this.saveSlot);
}
/** Aborted when the page is left: pass it to fetch calls. */
get signal() {
return this.controller.signal;
}
/** Title row: «Libreria» with «48.212 elementi di 38 account» beside it. */
title(text, count = null) {
this.titleText = text;
document.title = t('app.titoloPagina', { pagina: text });
const h1 = h('h1', text);
this.countEl = count == null ? null : h('span.quanti', count);
this.actionsEl = h('div.destra');
fill(this.head, h1, this.countEl, this.actionsEl);
this.head.hidden = false;
return this;
}
/** Updates the text beside the title. */
count(text) {
if (this.countEl) this.countEl.textContent = text;
return this;
}
/** Buttons and fields at the right of the title row. */
actions(...nodes) {
if (!this.actionsEl) this.title(this.titleText || '');
fill(this.actionsEl, ...nodes);
return this;
}
/** Replaces the whole title row with a custom header (the account card); keeps the document title. */
header(node, documentTitle) {
if (documentTitle) document.title = t('app.titoloPagina', { pagina: documentTitle });
this.head.replaceWith(node);
this.head = node;
return this;
}
/** «← Account» above the title. */
back(text, href) {
this.backSlot.replaceWith(this.backSlot = h('a.indietro', { href: withCarried(href) }, icon('arrow-left', 's'), text));
return this;
}
/** A row of tabs (.linguette) under the header. */
tabs(node) {
this.tabsSlot.replaceWith(node);
this.tabsSlot = node;
return this;
}
/** The tools row (filters, menus); null hides it. */
tools(node) {
fill(this.toolsSlot, node);
this.toolsSlot.hidden = !node;
return this;
}
/** The fixed bar at the bottom (save, selection); null hides it. */
saveBar(node) {
fill(this.saveSlot, node);
this.saveSlot.hidden = !node;
return this;
}
/** Engine changes while the page is open. */
onEngine(fn) {
this.cleanups.push(onEngine(fn));
}
/** Library changes while the page is open. */
onLibrary(fn) {
this.cleanups.push(onLibrary(fn));
}
/** Runs fn when the page is left. */
onLeave(fn) {
this.cleanups.push(fn);
}
/** guard() → Promise<boolean>: asked before leaving (unsaved changes). */
guard(fn) {
this.guards.push(fn);
}
async mayLeave() {
for (const g of this.guards) {
if (!(await g())) return false;
}
return true;
}
destroy() {
this.controller.abort();
for (const fn of this.cleanups) {
try {
fn();
} catch (error) {
console.error(error);
}
}
}
}
function renderBanner(frame, state) {
const banner = state && state.snapshot.banner;
if (!banner) {
frame.bannerSlot.hidden = true;
frame.bannerSlot.replaceChildren();
return;
}
const isError = banner.level === 'Error';
const resume = h('button.btn', {
type: 'button',
disabled: !state.canResume,
title: state.canResume ? null : t('arresto.riprendiSpento'),
onclick: async () => {
try {
const result = await api('/api/engine/resume', { method: 'POST' });
toast(result.message);
refreshEngine();
} catch (error) {
showError(error);
}
},
}, icon('rotate-cw'), t('arresto.riprendi'));
const open = h('button.btn.primo', { type: 'button', onclick: openBrowser }, icon('app-window'), t('arresto.apriBrowser'));
const box = h(`div.arresto${isError ? '' : '.ambra'}`, { role: 'alert' },
icon(isError ? 'octagon-alert' : 'triangle-alert', 'l'),
h('div.testo', h('b', banner.title), h('span', banner.message)),
h('div.azioni', banner.needsResume ? resume : null, isError ? open : null));
frame.bannerSlot.hidden = false;
fill(frame.bannerSlot, box);
}
/** «Apri il browser»: on Windows the window comes to the front; in Docker the Browser page with the remote view. */
export async function openBrowser() {
if (caps().browserWindow) {
try {
const result = await api('/api/browser/show', { method: 'POST' });
toast(result.message);
refreshEngine();
} catch (error) {
showError(error);
}
} else {
navigate('/browser');
}
}
// ------------------------------------------------------------------------------------------------- router
/** Goes to an internal address (carried demo parameters kept). */
export async function navigate(path, { replace = false } = {}) {
if (current && !(await current.frame.mayLeave())) return;
const target = withCarried(path);
if (replace) history.replaceState(null, '', target);
else history.pushState(null, '', target);
await render();
}
/** Changes the query of the current address without reloading the page (filters, tabs). */
export function setQuery(params, { replace = true } = {}) {
const url = new URL(location.href);
for (const [key, value] of Object.entries(params)) {
if (value == null || value === '') url.searchParams.delete(key);
else url.searchParams.set(key, value);
}
const target = url.pathname + url.search + url.hash;
if (replace) history.replaceState(null, '', target);
else history.pushState(null, '', target);
}
/** Starts the router: link clicks, back and forward buttons. */
export function startRouter() {
document.addEventListener('click', (e) => {
const a = e.target.closest && e.target.closest('a[href]');
if (!a || e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
if (a.target && a.target !== '_self') return;
if (a.hasAttribute('download')) return;
const url = new URL(a.href, location.href);
if (url.origin !== location.origin || url.pathname.startsWith('/api/') || /\.\w+$/.test(url.pathname)) return;
if (a.getAttribute('href').startsWith('#')) return;
e.preventDefault();
navigate(url.pathname + url.search);
});
window.addEventListener('popstate', () => render());
render();
}
async function render() {
closeMenu();
const token = ++renderToken;
const path = location.pathname;
const route = routes.find((r) => r.pattern.test(path));
if (route && route.redirect) {
history.replaceState(null, '', withCarried(route.redirect));
return render();
}
if (current) {
current.frame.destroy();
current = null;
}
for (const [key, link] of Object.entries(navLinks)) {
const here = route && route.nav === key;
link.classList.toggle('qui', here);
if (here) link.setAttribute('aria-current', 'page');
else link.removeAttribute('aria-current');
}
const match = route ? path.match(route.pattern) : null;
const params = { ...(route && route.data), ...(match && match.groups) };
const query = new URLSearchParams(location.search);
const frame = new PageFrame({ path, params, query });
fill(main, frame.root);
current = { frame };
frame.onEngine((state) => renderBanner(frame, state));
try {
const module = route ? await route.page() : await import('../pages/placeholder.js');
if (token !== renderToken) return;
const page = module.default;
const cleanup = await page.mount(frame, route ? { path, params, query } : { path, params: { key: 'nonTrovata' }, query });
if (typeof cleanup === 'function') frame.onLeave(cleanup);
} catch (error) {
if (error && error.name === 'AbortError') return;
console.error(error);
frame.title(t('comune.erroreTitolo'));
fill(frame.body, h('div.vuoto-pagina', icon('octagon-alert'), h('p', error && error.message ? error.message : t('comune.errore'))));
}
}
/** The engine state now (for pages that need it once). */
export { engineState };