diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-12 15:56:07 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-17 12:15:16 -0300 |
| commit | d4dfee52a67d2e2b9a52f7e7b18b3b3cc185fac4 (patch) | |
| tree | 3c1737d474bcebedb0783655ff74e7d850c06258 /web/static/catalog.mjs | |
| parent | fd7775b4e9c24b6bb8f664beb7d4fd2ccecd8d85 (diff) | |
| download | cloud9-d4dfee52a67d2e2b9a52f7e7b18b3b3cc185fac4.tar.gz cloud9-d4dfee52a67d2e2b9a52f7e7b18b3b3cc185fac4.zip | |
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.
Diffstat (limited to 'web/static/catalog.mjs')
| -rw-r--r-- | web/static/catalog.mjs | 103 |
1 files changed, 103 insertions, 0 deletions
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 }; +} |
