summaryrefslogtreecommitdiff
path: root/web/static/app.mjs
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-12 15:56:07 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:16 -0300
commitd4dfee52a67d2e2b9a52f7e7b18b3b3cc185fac4 (patch)
tree3c1737d474bcebedb0783655ff74e7d850c06258 /web/static/app.mjs
parentfd7775b4e9c24b6bb8f664beb7d4fd2ccecd8d85 (diff)
downloadcloud9-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/app.mjs')
-rw-r--r--web/static/app.mjs70
1 files changed, 61 insertions, 9 deletions
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();