From d4dfee52a67d2e2b9a52f7e7b18b3b3cc185fac4 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 12 Oct 2026 15:56:07 -0300 Subject: 9web: integrate sites and services into the file browser views Replace the standalone dark dashboard with Files, Sites and Services navigation in the existing application shell. Reuse the shared stylesheet, tables and controls; open site files and logs in the normal file browser and send build commands through the existing HTTP-to-9P mapping. Support direct tab URLs, browser history, preserved unsaved edits and focused controls, and pause catalogue polling in hidden views. Keep catalogue tabs hidden for ordinary upstream gateways. Remove the standalone page, script and log dialog. Document the integrated views and add a real Chromium regression suite with desktop/mobile screenshots. Validation: catalogue and HTTP filesystem suites, integrated UI suite, and all 32 original browser E2E scenarios. --- web/static/app.mjs | 70 +++++++++++++++++++++++++++----- web/static/catalog.html | 14 ------- web/static/catalog.js | 56 -------------------------- web/static/catalog.mjs | 103 ++++++++++++++++++++++++++++++++++++++++++++++++ web/static/index.html | 44 ++++++++++++++++++++- web/static/style.css | 18 +++++++++ 6 files changed, 224 insertions(+), 81 deletions(-) delete mode 100644 web/static/catalog.html delete mode 100644 web/static/catalog.js create mode 100644 web/static/catalog.mjs (limited to 'web/static') diff --git a/web/static/app.mjs b/web/static/app.mjs index 429bef7..b31177a 100644 --- a/web/static/app.mjs +++ b/web/static/app.mjs @@ -1,8 +1,40 @@ import { Client } from './client.mjs'; +import { catalogViews } from './catalog.mjs'; const $ = id => document.getElementById(id); const text = new TextDecoder('utf-8', { fatal: true }); let client = null, current = null, currentPath = '/', busy = false, dirty = false; let configuration = null; +let activeView = 'files'; +const catalog = catalogViews(pathLink); + +async function loadConfiguration() { + if (!configuration) { + const response = await fetch('/_cloud9/config.json'); + if (!response.ok) throw new Error('Unable to load server settings. Reload to try again.'); + configuration = await response.json(); + for (const view of ['sites', 'services']) $(`view-${view}`).hidden = !configuration.catalog; + } + return configuration; +} +function locationView() { + const view = new URLSearchParams(location.search).get('view'); + return configuration?.catalog && ['sites', 'services'].includes(view) ? view : 'files'; +} +function viewURL(view, path = currentPath) { + return pathURL(path) + (view === 'files' ? '' : `?view=${view}`); +} +function showView(view) { + activeView = view; + for (const name of ['files', 'sites', 'services']) { + $(`${name}-view`).hidden = view !== name; + const link = $(`view-${name}`); + link.classList.toggle('selected', view === name); + if (view === name) link.setAttribute('aria-current', 'page'); else link.removeAttribute('aria-current'); + link.href = viewURL(name); + } + document.title = `${view === 'files' ? currentPath : view} — cloud9`; + catalog.show(view); +} function status(message, error = false) { $('status').textContent = message; @@ -17,7 +49,7 @@ function controls() { $('delete').disabled = busy || currentPath === '/'; $('editor').readOnly = busy; $('edit-status').textContent = dirty ? 'Unsaved changes.' : 'No unsaved changes.'; - document.querySelector('main').setAttribute('aria-busy', String(busy)); + document.querySelector('#files-view main').setAttribute('aria-busy', String(busy)); } async function action(operation) { if (busy) return; @@ -29,11 +61,7 @@ async function action(operation) { } async function connectedClient() { if (client && !client.closed) return client; - if (!configuration) { - const response = await fetch('/_cloud9/config.json'); - if (!response.ok) throw new Error('Unable to load server settings. Reload to try again.'); - configuration = await response.json(); - } + await loadConfiguration(); try { client = await Client.connect('/_cloud9/9p', configuration.user, configuration.tree); } catch { throw new Error('Unable to reach the file server. Reload to try again.'); } return client; @@ -105,10 +133,12 @@ function breadcrumbs(path) { } async function navigate(path, historyMode = 'push') { path = normalizePath(path); + showView('files'); stopFollow(); status('Loading…'); const result = await readPath(path); current = result; currentPath = path; dirty = false; + for (const view of ['files', 'sites', 'services']) $(`view-${view}`).href = viewURL(view); $('path').value = path; const url = pathURL(path); if (historyMode === 'push' && location.pathname + location.search + location.hash !== url) history.pushState(null, '', url); @@ -149,6 +179,17 @@ async function navigate(path, historyMode = 'push') { } function mayLeave() { return !dirty || window.confirm('Discard unsaved changes?'); } document.addEventListener('click', event => { + const tab = event.target.closest('a[data-view]'); + if (tab && event.button === 0 && !event.ctrlKey && !event.metaKey && !event.shiftKey && !event.altKey) { + event.preventDefault(); + if (busy || tab.hidden) return; + const view = tab.dataset.view; + if (view === activeView) return; + history.pushState(null, '', viewURL(view)); + showView(view); + if (view === 'files' && !current) action(() => navigate(currentPath, 'none')).then(loadTree); + return; + } const link = event.target.closest('a[data-path]'); if (!link || event.button !== 0 || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) return; event.preventDefault(); @@ -180,8 +221,10 @@ $('download').onclick = () => { setTimeout(() => URL.revokeObjectURL(url), 1000); }; window.addEventListener('popstate', () => { - if (busy || !mayLeave()) { history.pushState(null, '', pathURL(currentPath)); return; } - action(() => navigate(locationPath(), 'none')); + const view = locationView(), path = locationPath(); + if (busy || (view === 'files' && path !== currentPath && !mayLeave())) { history.pushState(null, '', viewURL(activeView)); return; } + showView(view); + if (view === 'files' && (!current || path !== currentPath)) action(() => navigate(path, 'none')).then(loadTree); }); window.addEventListener('beforeunload', event => { if (dirty) { event.preventDefault(); event.returnValue = ''; } @@ -357,4 +400,13 @@ $('upload-input').onchange = () => { $('upload-input').value = ''; }; -action(() => navigate(locationPath(), 'none')).then(loadTree); +async function start() { + try { + await loadConfiguration(); + currentPath = locationPath(); + const view = locationView(); + showView(view); + if (view === 'files') await action(() => navigate(currentPath, 'none')).then(loadTree); + } catch (error) { status(error.message, true); } +} +start(); diff --git a/web/static/catalog.html b/web/static/catalog.html deleted file mode 100644 index 2160612..0000000 --- a/web/static/catalog.html +++ /dev/null @@ -1,14 +0,0 @@ - - -9web · local sites - -

9web

Local sites, builds, and listening services.

-

-

HTTP services

9P tree
-

Identified from socket ownership and process arguments. No endpoint probing. Loopback links work only on this computer.

-
ServiceAddressProcessEvidence
-
Other listeners
-

- diff --git a/web/static/catalog.js b/web/static/catalog.js deleted file mode 100644 index f868a16..0000000 --- a/web/static/catalog.js +++ /dev/null @@ -1,56 +0,0 @@ -const $ = id => document.getElementById(id); -let activeLog = null; -const element = (tag, text) => { const e = document.createElement(tag); e.textContent = text; return e; }; -function url(address, port, protocol = 'http') { - let host = address; - if (!host || host === '0.0.0.0' || host === '::') host = location.hostname; - host = host.replace(/^\[|\]$/g, ''); - return `${protocol}://${host.includes(':') ? `[${host}]` : host}:${port}/`; -} -async function control(name, command) { - try { - const r = await fetch(`/_cloud9/sites/${encodeURIComponent(name)}/ctl`, { method:'POST', headers:{'Content-Type':'text/plain'}, body:command }); - if (!r.ok) throw new Error(await r.text()); - $('message').textContent = `${name}: ${command} requested`; - await refresh(); - } catch (e) { $('message').textContent = e.message; } -} -function button(text, action, disabled = false) { const b = element('button', text); b.disabled = disabled; b.onclick = action; return b; } -function listenerRow(item) { - const tr = element('tr', ''); - const name = element('td', ''); - if (item.protocol !== 'unknown') { - const a = element('a', item.service); a.href = url(item.address, item.port, item.protocol); name.append(a); - } else name.textContent = item.process || 'Unknown'; - tr.append(name, element('td', `${item.address}:${item.port}${item.local ? ' · local only' : ''}`)); - const process = element('td', item.pid ? `PID ${item.pid}` : 'Unavailable'); process.className = 'process'; tr.append(process, element('td', item.evidence)); - return tr; -} -async function refresh() { - try { - const r = await fetch('/_cloud9/catalog.json'); if (!r.ok) throw new Error(`Dashboard: ${r.status}`); - const data = await r.json(); - $('sites').replaceChildren(); - for (const site of data.sites) { - const card = element('article', ''); const h = element('h2', ''); const a = element('a', site.title); a.href = url('', site.port); h.append(a); - const s = site.status; - card.append(h, element('code', site.root), element('p', `${s.phase}${s.watching ? ' · watch on' : ''}${s.queued ? ' · build queued' : ''}${s.exit_code !== null ? ` · exit ${s.exit_code}` : ''}`)); - if (s.finished) card.append(element('small', `Last finished ${new Date(s.finished * 1000).toLocaleString()}`), element('br', '')); - card.append(button('Build', () => control(site.name, 'build'), !site.build), button(s.watching ? 'Stop watching' : 'Watch', () => control(site.name, s.watching ? 'watch off' : 'watch on'), !site.watch), button('Cancel', () => control(site.name, 'cancel'), !s.pid && !s.queued), button('Log', () => { activeLog = site.name; $('log-title').textContent = site.title; $('logs').showModal(); refreshLog(); })); - $('sites').append(card); - } - const known = data.listeners.filter(x => x.protocol !== 'unknown'); - const unknown = data.listeners.filter(x => x.protocol === 'unknown'); - $('services').replaceChildren(...known.map(listenerRow)); - $('unknown').replaceChildren(...unknown.map(listenerRow)); - $('unknown-title').textContent = `Other listeners (${unknown.length})`; - if (data.discovery_error) $('message').textContent = data.discovery_error; - } catch (e) { $('message').textContent = e.message; } -} -async function refreshLog() { - if (!activeLog) return; - try { const r = await fetch(`/fs/sites/${encodeURIComponent(activeLog)}/log`); $('log-text').textContent = await r.text(); } catch (e) { $('log-text').textContent = e.message; } -} -$('close-log').onclick = () => { activeLog = null; $('logs').close(); }; -$('logs').onclose = () => { activeLog = null; }; -refresh(); setInterval(refresh, 5000); setInterval(refreshLog, 1500); diff --git a/web/static/catalog.mjs b/web/static/catalog.mjs new file mode 100644 index 0000000..d1d3444 --- /dev/null +++ b/web/static/catalog.mjs @@ -0,0 +1,103 @@ +// Sites and services are views of the same 9web application. File/log links +// use app.mjs navigation; control writes use the normal HTTP-to-9P mapping. +const $ = id => document.getElementById(id); +const element = (tag, text = '') => { const e = document.createElement(tag); e.textContent = text; return e; }; +function url(address, port, protocol = 'http') { + let host = address; + if (!host || host === '0.0.0.0' || host === '::') host = location.hostname; + host = host.replace(/^\[|\]$/g, ''); + return `${protocol}://${host.includes(':') ? `[${host}]` : host}:${port}/`; +} + +export function catalogViews(pathLink) { + let active = 'files', timer = null, request = null, revision = 0, pending = new Set(); + const rows = new Map(); + function status(view, text, error = false) { + const p = $(`${view}-status`); p.textContent = text; p.classList.toggle('error', error); + } + async function control(site, command) { + if (pending.has(site.name)) return; + pending.add(site.name); updateSite(site); + try { + const r = await fetch(`/fs/sites/${encodeURIComponent(site.name)}/ctl`, { method: 'PUT', body: command }); + if (!r.ok) throw new Error(await r.text()); + status('sites', `${site.title}: ${command} requested.`); + } catch (error) { status('sites', error.message, true); } + finally { pending.delete(site.name); updateSite(site); if (active === 'sites') await refresh(false); } + } + function updateSite(site) { + let row = rows.get(site.name); + if (!row) { + const tr = element('tr'); tr.dataset.site = site.name; + const name = element('td'), phase = element('td'), finished = element('td'), actions = element('td'); + const link = element('a'); link.className = 'site-name'; + const root = element('span'); root.className = 'site-root'; name.append(link, root); + const tools = element('div'); tools.className = 'site-actions'; + const build = element('button', 'build'), watch = element('button', 'watch'), cancel = element('button', 'cancel'); + for (const b of [build, watch, cancel]) b.type = 'button'; + tools.append(build, watch, cancel, pathLink('files', `/sites/${site.name}/public`), pathLink('log', `/sites/${site.name}/log`)); + actions.append(tools); tr.append(name, phase, finished, actions); + row = { tr, link, root, phase, finished, build, watch, cancel }; rows.set(site.name, row); + $('sites-entries').append(tr); + } + const s = site.status; + row.link.textContent = site.title; row.link.href = url('', site.port); row.root.textContent = site.root; + row.phase.textContent = `${s.phase}${s.watching ? ' · watch on' : ''}${s.queued ? ' · queued' : ''}${s.exit_code !== null ? ` · exit ${s.exit_code}` : ''}`; + row.phase.className = `site-phase${s.phase === 'failed' ? ' failed' : ''}`; + row.finished.textContent = s.finished ? new Date(s.finished * 1000).toLocaleString() : '—'; + row.build.disabled = pending.has(site.name) || !site.build; + row.watch.disabled = pending.has(site.name) || !site.watch; + row.watch.textContent = s.watching ? 'stop watching' : 'watch'; + row.cancel.disabled = pending.has(site.name) || (!s.pid && !s.queued && !s.watching); + row.build.onclick = () => control(site, 'build'); + row.watch.onclick = () => control(site, s.watching ? 'watch off' : 'watch on'); + row.cancel.onclick = () => control(site, 'cancel'); + } + function listenerRow(item, sites) { + const tr = element('tr'), name = element('td'); + if (item.protocol !== 'unknown') { + const site = item.service === '9web' && sites.find(s => s.port === item.port); + const a = element('a', site ? site.title : item.service); a.href = url(item.address, item.port, item.protocol); name.append(a); + } else name.textContent = item.process || 'Unknown'; + const address = element('td', `${item.address.includes(':') ? `[${item.address}]` : item.address}:${item.port}${item.local ? ' · local only' : ''}`); + address.className = 'listener-address'; + tr.append(name, address, element('td', item.pid ? `${item.process || ''} (${item.pid})` : 'Unavailable'), element('td', item.evidence)); + return tr; + } + async function refresh(showCount = true) { + if (active === 'files' || document.hidden) return; + request?.abort(); request = new AbortController(); + const ticket = ++revision, view = active; + $(`${view}-reload`).disabled = true; + try { + const r = await fetch('/_cloud9/catalog.json', { signal: request.signal }); + if (!r.ok) throw new Error(`Unable to load ${view}: HTTP ${r.status}`); + const data = await r.json(); + if (ticket !== revision || active !== view) return; + if (view === 'sites') { + const names = new Set(data.sites.map(s => s.name)); + for (const [name, row] of rows) if (!names.has(name)) { row.tr.remove(); rows.delete(name); } + for (const site of data.sites) updateSite(site); + $('sites-empty').hidden = data.sites.length !== 0; + if (showCount) status(view, `${data.sites.length} ${data.sites.length === 1 ? 'site' : 'sites'} · generated files are served continuously`); + } else { + const known = data.listeners.filter(x => x.protocol !== 'unknown'), unknown = data.listeners.filter(x => x.protocol === 'unknown'); + $('services-entries').replaceChildren(...known.map(x => listenerRow(x, data.sites))); + $('other-listeners-entries').replaceChildren(...unknown.map(x => listenerRow(x, data.sites))); + $('services-empty').hidden = known.length !== 0; + $('other-listeners-title').textContent = `Other listeners (${unknown.length})`; + status(view, data.discovery_error || `${known.length} HTTP services · refreshed every 5 seconds`, Boolean(data.discovery_error)); + } + } catch (error) { if (error.name !== 'AbortError' && ticket === revision) status(view, error.message, true); } + finally { if (ticket === revision) $(`${view}-reload`).disabled = false; } + } + function show(view) { + clearInterval(timer); request?.abort(); revision++; + active = view; + for (const name of ['sites', 'services']) $(`${name}-reload`).disabled = false; + if (view !== 'files') { refresh(); timer = setInterval(refresh, 5000); } + } + for (const name of ['sites', 'services']) $(`${name}-reload`).onclick = () => refresh(); + document.addEventListener('visibilitychange', () => { if (!document.hidden) refresh(); }); + return { show }; +} diff --git a/web/static/index.html b/web/static/index.html index b012b3c..8e2b5cc 100644 --- a/web/static/index.html +++ b/web/static/index.html @@ -12,8 +12,13 @@ cloud9
A web interface to your file server.
-