diff --git a/AGENTS.md b/AGENTS.md index afee95de..400ed71a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -77,7 +77,8 @@ and its resources. The source layout stays under `app/`. by `git ls-remote`), `secrets` (a benchmark's licences, kept per benchmark outside the repository, and the Hugging Face token of Data providers), `sandbox` (Docker's state, and the Docker Hub login Data providers uses) and `redact` at the top. - `app/templates/`, `app/static/` — the interface, grouped by the same capability names (`runs/`, `traces/`, `builder/`, …; `base.html`, `style.css` and the fonts at the top), including the command - builder's JavaScript, which owns the generated recipes. + builder's JavaScript, which owns the generated recipes. `app/templates/_tables.html` and + `app/static/tables.js` are the table toolkit: one column list builds a table's headers, cells and controls. - `app/tests/`, `app/ui_tests/` — the backend suite and the route suite. Beside the backend tests sit scripts run by hand: `app/tests/field_contract.py`, which refreshes the `field_contract.json` the diff --git a/app/static/runs/launches.css b/app/static/runs/launches.css index e6ab049e..05f31fd9 100644 --- a/app/static/runs/launches.css +++ b/app/static/runs/launches.css @@ -115,36 +115,21 @@ dialog.std-how.launch-delete { width: min(520px, calc(100vw - 32px)); } .la-gap { display: block; margin-top: 2px; font: 11.5px var(--sans); color: var(--patch_failed_tests); } /* the Launches page: one row per launch */ -.inventory .inv-open { display: inline; } -.inventory .inv-open .linkish { padding: 0; text-align: left; } -/* as the Runs page's table: text columns keep a floor and short values stay on one line, so past the box's width the table scrolls instead of squeezing */ -.inventory td[data-col="launch"] { min-width: 12rem; overflow-wrap: anywhere; } -.inventory td[data-col="bench"], .inventory td[data-col="ws"] { min-width: 8rem; } -.inventory td[data-col="machines"] { min-width: 10rem; } -.inventory td[data-col="started"], .inventory td.num { white-space: nowrap; } -@media (max-width: 640px) { .inventory td[data-col="launch"] { min-width: 9rem; } } /* a phone keeps room beside the pinned title */ -.grid.sortable.inventory thead th:not([data-type]) { cursor: default; } -.grid.sortable.inventory thead th:not([data-type])::after { content: none; } -.inventory td.inv-acts { position: relative; white-space: nowrap; } /* holds its hidden reason, inside the table's scroll */ /* Add, then Delete, side by side on every row */ -.inventory .launch-add-btn:focus-visible { color: var(--text); } +#launches .launch-open { display: inline; } +#launches .launch-open .linkish { padding: 0; text-align: left; } +#launches .launch-add-btn:focus-visible { color: var(--text); } /* State and Launch stay put while the table scrolls sideways; State's header is its name for a screen reader only */ -.inventory { --inv-state-w: 2.2rem; } -.inventory [data-col="state"] { width: var(--inv-state-w); min-width: var(--inv-state-w); padding-left: 0; padding-right: 0; text-align: center; } -.inventory [data-col="launch"] { --sticky-left: var(--inv-state-w); } +#launches :is(th, td)[data-col="state"] { width: 2.2rem; min-width: 2.2rem; padding-left: 0; padding-right: 0; text-align: center; } /* a run's state: its icon, coloured as the Runs page's state dots */ -.inventory td[data-col="state"] .ic { vertical-align: middle; } -.inventory .st-finished, .inventory .st-running, .inventory .st-preparing { color: var(--resolved); } -.inventory .st-failed, .inventory .st-refused, .inventory .st-stopped { color: var(--bad); } -.inventory .st-paused, .inventory .st-stopping { color: var(--patch_failed_tests); } -.inventory .st-running { animation: inv-beat 2s ease-in-out infinite; } -@keyframes inv-beat { 50% { opacity: .45; } } -@media (prefers-reduced-motion: reduce) { .inventory .st-running { animation: none; } } -.inv-cols { margin-top: 1rem; } +#launches td[data-col="state"] .ic { vertical-align: middle; } +#launches .st-finished, #launches .st-running, #launches .st-preparing { color: var(--resolved); } +#launches .st-failed, #launches .st-refused, #launches .st-stopped { color: var(--bad); } +#launches .st-paused, #launches .st-stopping { color: var(--patch_failed_tests); } +#launches .st-running { animation: state-beat 2s ease-in-out infinite; } +@keyframes state-beat { 50% { opacity: .45; } } +@media (prefers-reduced-motion: reduce) { #launches .st-running { animation: none; } } .launch-delete select { margin-left: 8px; } /* Add to workspace: the name field only for a new workspace, under its label as the select is */ .launch-delete .launch-add-new { display: none; } .launch-delete .launch-add-new input { display: block; width: 100%; margin-top: 4px; } .launch-delete form:has(option[value=""]:checked) .launch-add-new { display: block; } -/* ten columns fit at 1280 px: narrower gutters, and a count takes only its width */ -.inventory th, .inventory td { padding-left: .4rem; padding-right: .4rem; } -.inventory th.num, .inventory td.num { width: 1%; } diff --git a/app/static/settings/settings.css b/app/static/settings/settings.css index ee07cdfb..b1977e79 100644 --- a/app/static/settings/settings.css +++ b/app/static/settings/settings.css @@ -233,11 +233,6 @@ .st-index a span { color: inherit; font-size: 15px; } .st-index a .ic { flex: none; width: 17px; height: 17px; } .st-index [hidden] { display: none; } -.st-search { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; padding: 8px 10px; border: 1px solid transparent; border-radius: 8px; background: var(--surface-2); color: var(--text-dim); } -.st-search .ic { flex: none; width: 17px; height: 17px; } -.st-search input { min-width: 0; width: 100%; padding: 0; border: 0; background: transparent; color: var(--text); font: 13px var(--sans); } -.st-search input:focus-visible { outline: none; } -.st-search:focus-within { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); } .st-search-empty { padding: 8px 12px; font-size: 13px; color: var(--text-dim); } .st-theme-options { display: flex; flex-wrap: wrap; gap: 8px; } .st-theme-options .btn[aria-pressed="true"] { border-color: transparent; background: var(--accent-soft); color: var(--text); } diff --git a/app/static/style.css b/app/static/style.css index cc25d710..12331dc0 100644 --- a/app/static/style.css +++ b/app/static/style.css @@ -352,10 +352,22 @@ button.seg:hover { filter: brightness(1.25); } overflow: hidden; background: var(--surface-2); } -/* table toolbar + column menu */ +/* the table toolkit (templates/_tables.html, static/tables.js): controls, menus, sorting, sticky columns, pages */ .table-tools { display: flex; align-items: center; gap: .75rem; margin: 0 0 .6rem; } .artifact-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .35rem; } .artifact-tools { flex-wrap: wrap; } +/* the controls row: the search takes what the buttons leave, else a line of its own; the buttons go right */ +.table-controls { flex-wrap: wrap; margin-top: 1rem; } +.table-controls .st-search { flex: 1 1 14rem; margin: 0; } +.table-buttons, .table-slot { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: .75rem; } +.table-buttons { margin-left: auto; } +.table-buttons .menu { left: auto; right: 0; } /* opens leftwards, inside the page */ +/* a search box, its icon first (the Settings page's too) */ +.st-search { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; padding: 8px 10px; border: 1px solid transparent; border-radius: 8px; background: var(--surface-2); color: var(--text-dim); } +.st-search .ic { flex: none; width: 17px; height: 17px; } +.st-search input { min-width: 0; width: 100%; padding: 0; border: 0; background: transparent; color: var(--text); font: 13px var(--sans); } +.st-search input:focus-visible { outline: none; } +.st-search:focus-within { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); } .menu-wrap { position: relative; } .btn.sm { font-size: .8rem; padding: .42rem .75rem; } .menu { @@ -376,22 +388,20 @@ button.seg:hover { filter: brightness(1.25); } .grid.sortable thead th { cursor: pointer; user-select: none; white-space: nowrap; } .grid.sortable thead th:hover { color: var(--text); } -/* Arrows are set in a size independent of the small uppercase header text — - at .76rem uppercase they were rendering near-invisible. */ -.grid.sortable thead th::after { - content: "↕"; margin-left: .4rem; font-size: 1.05rem; line-height: 0; - vertical-align: -.1em; opacity: .4; color: var(--text-faint); -} -.grid.sortable thead th:hover::after { opacity: .8; color: var(--text-dim); } -.grid.sortable thead th[data-sorted]::after { opacity: 1; color: var(--accent); font-weight: 500; } +/* an arrow on the sorted column only, in a size independent of the small uppercase header text */ +.grid.sortable thead th[data-sorted]::after { + margin-left: .4rem; font-size: 1.05rem; line-height: 0; vertical-align: -.1em; color: var(--accent); font-weight: 500; +} .grid.sortable thead th[data-sorted="asc"]::after { content: "↑"; } .grid.sortable thead th[data-sorted="desc"]::after { content: "↓"; } .grid.sortable thead th:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--accent-soft); } +/* a header without data-type (a checkbox, a state, the actions) does not sort */ +.grid.sortable thead th:not([data-type]) { cursor: default; } .nowrap { white-space: nowrap; } /* give the two text-heavy columns room; the rest stay compact */ .grid th[data-col="run"], .grid td[data-col="run"] { min-width: 14rem; } -.grid th[data-col="dataset"], .grid td[data-col="dataset"] { min-width: 10.5rem; } +.grid:not(.snug) th[data-col="dataset"], .grid:not(.snug) td[data-col="dataset"] { min-width: 10.5rem; } /* a .snug table fits its columns */ .grid td[data-col="dataset"] { color: var(--text-dim); } /* ---- wide-table handling: scroll the table, not the page ---- */ @@ -406,21 +416,15 @@ button.seg:hover { filter: brightness(1.25); } The left-pinned columns below work correctly, because the wrapper really does scroll horizontally. */ -/* the checkbox and Run columns stay put while you scroll sideways, so a row - never loses its identity; so do a table's .sticky-col cells, at --sticky-left */ -.table-wrap .grid th.pick-col, .table-wrap .grid td.pick-col, .table-wrap .grid .sticky-col { +/* a table's .sticky-col cells stay put while it scrolls sideways, at --sticky-left (tables.js `sticky`), so a + row never loses its identity; .sticky-edge draws the line after the last one */ +.table-wrap .grid .sticky-col { position: sticky; left: var(--sticky-left, 0); z-index: 2; background: var(--bg); } .table-wrap .grid .sticky-col.sticky-edge { box-shadow: 1px 0 0 var(--border-soft); } -.table-wrap .grid th[data-col="run"], .table-wrap .grid td[data-col="run"] { - position: sticky; left: 2.2rem; z-index: 2; background: var(--bg); - box-shadow: 1px 0 0 var(--border-soft); -} -.table-wrap .grid thead th.pick-col, -.table-wrap .grid thead th[data-col="run"], .table-wrap .grid thead th.sticky-col { z-index: 4; background: var(--bg); } +.table-wrap .grid thead th.sticky-col { z-index: 4; background: var(--bg); } /* opaque sticky cells would hide the row hover, so repaint them to match */ -.table-wrap .grid tbody tr:hover td.pick-col, -.table-wrap .grid tbody tr:hover td[data-col="run"], .table-wrap .grid tbody tr:hover td.sticky-col { background: var(--surface); } +.table-wrap .grid tbody tr:hover td.sticky-col { background: var(--surface); } /* compact density — same data, ~35% less width */ .grid.compact { font-size: .88rem; } @@ -429,23 +433,7 @@ button.seg:hover { filter: brightness(1.25); } .grid.compact th[data-col="dataset"], .grid.compact td[data-col="dataset"] { min-width: 8rem; } .grid.compact .minibar { width: 56px; } -/* per-column value filter */ -.th-filter { position: relative; display: inline-block; } -.filter-btn { - font: inherit; font-size: .8rem; line-height: 1; cursor: pointer; - background: none; border: none; padding: 0 .15rem; margin-left: .3rem; - color: var(--text-faint); border-radius: 4px; -} -.filter-btn:hover { color: var(--text); } -.filter-btn.on { color: var(--accent); } -.filter-btn.on::after { content: "•"; margin-left: .1rem; } -.filter-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; box-shadow: none; } -.filter-menu { - right: 0; left: auto; text-transform: none; letter-spacing: 0; - font-weight: 400; max-height: 18rem; overflow-y: auto; min-width: 200px; -} -/* a table's Filter and Sort by menus (the tools macro): no header carets, an arrow on the sorted column only */ -.grid.sortable.tools thead th:not([data-sorted])::after { content: none; } +/* a table's Filter and Sort by menus (the controls macro) */ .tools-menu { min-width: 220px; max-height: min(70vh, 34rem); overflow-y: auto; } .tools-menu fieldset { margin: 0; padding: .3rem 0; border: 0; border-top: 1px solid var(--border-soft); min-width: 0; } .tools-menu fieldset:first-of-type { border-top: 0; } @@ -453,14 +441,28 @@ button.seg:hover { filter: brightness(1.25); } .tools-menu .tools-all { display: flex; justify-content: flex-end; gap: .75rem; padding: .3rem .45rem; font-size: .8rem; } .tools-menu label { clear: both; } .tools-menu .tools-clear { align-self: flex-start; padding: .2rem .45rem .4rem; font-size: .8rem; } +/* a list in a .tools table: rows top-aligned; in a .snug one (the table macro's), narrow gutters and each column + as wide as its widest cell on one line, but the one that expands (its rule beside the table: the rest of the + width, no less than --expand-min, wrapping); a header or cell positioned holds a hidden name or reason inside + the table's scroll */ +.grid.tools td { vertical-align: top; } +.grid.snug { --expand-min: 12rem; } +@media (max-width: 640px) { .grid.snug { --expand-min: 9rem; } } /* a phone keeps room beside a pinned column */ +.grid.snug th, .grid.snug td { width: 1%; white-space: nowrap; padding-left: .4rem; padding-right: .4rem; } +.grid.snug th { position: relative; } +.grid td.acts-col { position: relative; white-space: nowrap; } +.count-btn { font-variant-numeric: tabular-nums; } /* an icon and a count, as one button */ +.btn[aria-disabled="true"] { opacity: .45; cursor: default; } /* greyed: it cannot act here */ +.btn.ghost[aria-disabled="true"]:hover { color: var(--text-dim); border-color: var(--border); background: transparent; } +.btn:not(.ghost)[aria-disabled="true"]:hover { background: var(--accent); } +/* a column's alignment (its `align`), header and cells */ +.grid .align-right { text-align: right; } +.grid .align-center { text-align: center; } .tools-count { margin-left: .4rem; padding: 0 .4em; border-radius: 99px; background: var(--accent-soft); color: var(--text); font-size: .72rem; font-variant-numeric: tabular-nums; } -.menu-head { display: flex; gap: .75rem; padding: .15rem .45rem .4rem; border-bottom: 1px solid var(--border-soft); margin-bottom: .25rem; } .chip.clear { border-style: dashed; } .pick-col { width: 2.2rem; } .pick-col input { accent-color: var(--accent); cursor: pointer; } -.grid.sortable thead th.pick-col { cursor: default; } -.grid.sortable thead th.pick-col::after { content: none; } .compare-bar { display: flex; align-items: center; gap: .7rem; margin: 0; } .btn:disabled { opacity: .4; cursor: not-allowed; filter: none; } @@ -928,8 +930,6 @@ button.seg:hover { filter: brightness(1.25); } .legend .chip:hover { cursor: help; } .cat-tag { display: inline-flex; align-items: center; gap: .4rem; font-size: .82rem; color: var(--text-dim); } -.grid.tools td { vertical-align: top; } -.grid.tools tr.row-failed td { background: color-mix(in srgb, var(--agent_error) 7%, transparent); } .files { margin: 0; padding-left: 1.1rem; color: var(--text-dim); font-size: .88rem; } .files li { margin: .2rem 0; } diff --git a/app/static/tables.js b/app/static/tables.js index 0f497379..9e71a5f1 100644 --- a/app/static/tables.js +++ b/app/static/tables.js @@ -1,5 +1,6 @@ -/* A table.grid's sortable headers and per-column value filters, shared by the - tables that have them. */ +/* The table toolkit's script: each function is a feature a table.grid opts + into (the macros of templates/_tables.html; their styles in style.css, + "the table toolkit"). */ window.NulliusTable = { /* A header with data-type sorts its column on a click or Enter; num sorts descending first. A cell's data-sort wins over its text. A header that @@ -49,23 +50,20 @@ window.NulliusTable = { return resort; }, - /* The value lists (data-filter-menu) under `scope`: the filter_button - macro's, each opened by its caret, or the tools macro's. `allowed`: - column -> the Set of values ticked, or null when all are. A row passes - when, for each column, one of its values (data-f-, one per line) is - ticked; a box unticked at load filters from the start. `changed` runs - after each change. */ + /* The value lists (data-filter-menu) under `scope`, the controls macro's + Filter menu. `allowed`: column -> the Set of values ticked, or null when + all are. A row passes when, for each column, one of its values + (data-f-, one per line) is ticked; a box unticked at load filters + from the start. `changed` runs after each change, a list's change event + included. */ filters(scope, changed) { const allowed = {}; scope.querySelectorAll('[data-filter-menu]').forEach(menu => { const col = menu.dataset.filterMenu; const boxes = () => [...menu.querySelectorAll('input[data-value]')]; - const btn = scope.querySelector(`.filter-btn[data-filter="${col}"]`); const read = () => { const on = boxes().filter(b => b.checked).map(b => b.dataset.value); - // All checked means "no filter": keeps the active marker honest. - allowed[col] = on.length === boxes().length ? null : new Set(on); - btn?.classList.toggle('on', Boolean(allowed[col])); + allowed[col] = on.length === boxes().length ? null : new Set(on); // all ticked: no filter }; const sync = () => { read(); changed(); }; read(); @@ -74,19 +72,6 @@ window.NulliusTable = { if (e.target.closest('[data-all]')) { boxes().forEach(b => b.checked = true); sync(); } if (e.target.closest('[data-none]')) { boxes().forEach(b => b.checked = false); sync(); } }); - if (!btn) return; - btn.addEventListener('click', e => { - e.stopPropagation(); // the th itself sorts; don't sort on filter - const open = menu.hidden; - scope.querySelectorAll('.filter-menu').forEach(m => m.hidden = true); - menu.hidden = !open; - btn.setAttribute('aria-expanded', String(open)); - }); - menu.addEventListener('click', e => e.stopPropagation()); - document.addEventListener('click', () => { - menu.hidden = true; - btn.setAttribute('aria-expanded', 'false'); - }); }); const passes = row => Object.entries(allowed).every(([col, set]) => !set || (row.getAttribute('data-f-' + col) ?? '').split('\n').some(v => set.has(v))); @@ -95,48 +80,35 @@ window.NulliusTable = { menu.querySelectorAll('input[data-value]').forEach(b => b.checked = true); allowed[menu.dataset.filterMenu] = null; }); - scope.querySelectorAll('.filter-btn').forEach(b => b.classList.remove('on')); }; return {allowed, passes, clear}; }, - /* A Columns menu: `btn` opens `menu` (none: the caller opens it), whose - checkboxes (data-col) show or hide the table's cells of that data-col, - remembered per viewer under `key`; a disabled one stays on. `hidden`: the - columns off until the viewer chooses. Returns show(), to apply the choice - to rows put in since. */ - columns(table, btn, menu, key, hidden = []) { + /* A Columns menu (opened by `menu`): its checkboxes (data-col) show or + hide the table's cells of that data-col, remembered per viewer under + `key`; a disabled one stays on, a data-off one is off until the viewer + chooses. Returns show(), to apply the choice to rows put in since. */ + columns(table, menu, key) { const boxes = [...menu.querySelectorAll('input[data-col]')]; let stored = null; try { stored = JSON.parse(localStorage.getItem(key) || 'null'); } catch {} const show = () => boxes.forEach(cb => table.querySelectorAll(`[data-col="${cb.dataset.col}"]`).forEach(el => { el.style.display = cb.checked ? '' : 'none'; })); boxes.forEach(cb => { - cb.checked = cb.disabled || (stored ? stored.includes(cb.dataset.col) : !hidden.includes(cb.dataset.col)); + cb.checked = cb.disabled || (stored ? stored.includes(cb.dataset.col) : !cb.hasAttribute('data-off')); cb.addEventListener('change', () => { show(); try { localStorage.setItem(key, JSON.stringify(boxes.filter(b => b.checked).map(b => b.dataset.col))); } catch {} }); }); show(); - if (!btn) return show; - btn.addEventListener('click', () => { - const open = menu.hidden; - menu.hidden = !open; - btn.setAttribute('aria-expanded', String(open)); - }); - document.addEventListener('click', e => { - if (!menu.hidden && !menu.contains(e.target) && !btn.contains(e.target)) { - menu.hidden = true; - btn.setAttribute('aria-expanded', 'false'); - } - }); return show; }, /* A toolbar's popover: `btn` opens `menu` and puts the focus in it; a click elsewhere or Tab out of it closes it, and Escape too, giving the focus - back to `btn`. */ + back to `btn`. A click on a label's text moves the focus to a focusable + ancestor (the page's
): that is not leaving. */ menu(btn, menu) { const close = () => { menu.hidden = true; btn.setAttribute('aria-expanded', 'false'); }; btn.addEventListener('click', () => { @@ -147,19 +119,29 @@ window.NulliusTable = { }); document.addEventListener('click', e => { if (!menu.hidden && !menu.contains(e.target) && !btn.contains(e.target)) close(); }); document.addEventListener('keydown', e => { if (e.key === 'Escape' && !menu.hidden) { close(); btn.focus(); } }); - const left = e => { if (e.relatedTarget && !menu.contains(e.relatedTarget) && !btn.contains(e.relatedTarget)) close(); }; + const left = e => { const to = e.relatedTarget; if (to && !menu.contains(to) && !btn.contains(to) && !to.contains(menu)) close(); }; menu.addEventListener('focusout', left); btn.addEventListener('focusout', left); }, - /* A table's Filter and Sort by menus (the tools macro), under `tools`, in - place of header carets. Filter counts the columns it narrows; Sort by - sets the sort, and follows a header click. `changed` runs after either. - A toolbar without Filter (the macro given no filters) only sorts. - Returns {passes, resort}, as filters and sortable do. */ + /* A table's search box, Filter and Sort by menus (the controls macro), + under `tools`; each optional. Search keeps the rows whose data-search + holds every word of the query, in any order and case; Escape clears it. Filter counts the columns it + narrows; Sort by sets the sort, and follows a header click. `changed` + runs after any of them. Returns {passes, resort}, as filters and sortable + do. */ toolbar(table, tools, changed) { const [fbtn, fmenu, sbtn, smenu] = ['filter', 'sort'].flatMap(k => [tools.querySelector(`[data-tools-btn="${k}"]`), tools.querySelector(`[data-tools="${k}"]`)]); + const q = tools.querySelector('[data-search]'); + if (q) { + q.addEventListener('input', changed); + q.addEventListener('keydown', e => { if (e.key === 'Escape' && q.value) { e.preventDefault(); q.value = ''; changed(); } }); + } + const found = row => { + const text = (row.dataset.search ?? '').toLowerCase(); + return !q || q.value.toLowerCase().split(/\s+/).every(w => text.includes(w)); + }; const count = fbtn?.querySelector('.tools-count'); const mark = () => { const n = Object.values(f.allowed).filter(Boolean).length; @@ -175,30 +157,98 @@ window.NulliusTable = { } const heads = [...table.tHead.rows[0].cells]; const sync = () => { + if (!smenu) return; const {col, dir} = resort.state(), on = col === null ? '' : heads[col].dataset.col; smenu.querySelectorAll('[data-sort-col]').forEach(r => { r.checked = r.value === on; }); smenu.querySelectorAll('[data-sort-dir]').forEach(r => { r.checked = Boolean(on) && r.value === (dir > 0 ? 'asc' : 'desc'); r.disabled = !on; }); }; const resort = this.sortable(table, () => { sync(); changed(); }); - smenu.addEventListener('change', e => { - const idx = heads.findIndex(h => h.dataset.col === smenu.querySelector('[data-sort-col]:checked').value); - if (idx < 0) return resort.set(null); - const dir = e.target.matches('[data-sort-dir]') ? (e.target.value === 'asc' ? 1 : -1) : (heads[idx].dataset.type === 'num' ? -1 : 1); - resort.set(idx, dir); + if (smenu) { + smenu.addEventListener('change', e => { + const idx = heads.findIndex(h => h.dataset.col === smenu.querySelector('[data-sort-col]:checked').value); + if (idx < 0) return resort.set(null); + const dir = e.target.matches('[data-sort-dir]') ? (e.target.value === 'asc' ? 1 : -1) : (heads[idx].dataset.type === 'num' ? -1 : 1); + resort.set(idx, dir); + }); + sync(); + this.menu(sbtn, smenu); + } + return {passes: row => f.passes(row) && found(row), resort}; + }, + + /* A table of the table macro (data-table): its controls row (id + -tools), its Columns menu and checkbox column when it has + them, and its pages; choices kept per viewer under
.cols and + .per. */ + wire(table) { + const tools = document.getElementById(table.id + '-tools'); + const cmenu = tools.querySelector('[data-tools="columns"]'); + if (cmenu) { + this.columns(table, cmenu, table.id + '.cols'); + this.menu(tools.querySelector('[data-tools-btn="columns"]'), cmenu); + } + const ticks = table.querySelector('[data-check-all]') ? this.checks(table) : () => {}; + let first = () => {}; + const t = this.toolbar(table, tools, () => first()); + first = this.pager(table, table.id + '.per', t.passes, ticks); + }, + + /* A checkbox column (a `check` column, check_cell in each row): the header + ticks or unticks every visible row, and shows all, none or some of them + ticked. Returns sync(), to run when rows show or hide. */ + checks(table) { + const all = table.querySelector('[data-check-all]'); + const shown = () => [...table.tBodies[0].rows].filter(r => !r.hidden).map(r => r.querySelector('[data-check]')).filter(Boolean); + const sync = () => { + const boxes = shown(), n = boxes.filter(b => b.checked).length; + all.checked = boxes.length > 0 && n === boxes.length; + all.indeterminate = n > 0 && n < boxes.length; + }; + table.addEventListener('change', e => { + if (e.target === all) shown().forEach(b => { b.checked = all.checked; }); + else if (!e.target.matches('[data-check]')) return; + sync(); }); sync(); - this.menu(sbtn, smenu); - return {passes: f.passes, resort}; + return sync; + }, + + /* Sticky columns, those whose header is a .sticky-col: each cell under it + pinned at the summed widths of the sticky columns before it, again as + they resize, hide or rows come in. A row without a cell under each + header (a colspan, an empty row) is left as it is. */ + sticky(table) { + const heads = [...table.tHead.rows[0].cells], pinned = heads.filter(th => th.classList.contains('sticky-col')); + const place = () => { + let left = 0; + pinned.forEach(th => { + for (const row of table.rows) { + if (row.cells.length !== heads.length) continue; + const cell = row.cells[th.cellIndex]; + cell.classList.add('sticky-col'); + cell.classList.toggle('sticky-edge', th.classList.contains('sticky-edge')); + cell.style.setProperty('--sticky-left', left + 'px'); + } + left += th.getBoundingClientRect().width; + }); + }; + const resized = new ResizeObserver(place); + pinned.forEach(th => resized.observe(th)); + new MutationObserver(place).observe(table, {childList: true, subtree: true}); + place(); }, /* A table's pages (the pager macro named after its id): the rows `passes` lets through, a page of them at a time, the page's size remembered per - viewer under `key`; `empty` shows when none passes. Returns first(), to - run after a filter or a sort: it shows the first page. */ - pager(table, key, passes = () => true, empty = null) { - const bar = document.querySelector(`[data-pager="${CSS.escape(table.id)}"]`); - const [per, note, prev, next] = ['[data-per]', '[data-note]', '[data-prev]', '[data-next]'].map(s => bar.querySelector(s)); - let page = 0; + viewer under `key`; its empty note shows when none passes. After a + change, not at load, a screen reader hears what shows once the changes + pause, counted in the live region's data-noun. `drawn` runs after each + page. Returns first(), to run after a filter or a sort: it + shows the first page. */ + pager(table, key, passes = () => true, drawn = () => {}) { + const bar = document.querySelector(`[data-pager="${CSS.escape(table.id)}"]`), empty = document.querySelector(`[data-empty="${CSS.escape(table.id)}"]`); + const [per, note, prev, next, live] = ['[data-per]', '[data-note]', '[data-prev]', '[data-next]', '[data-live]'].map(s => bar.querySelector(s)); + let page = 0, said, loaded = false; try { const n = localStorage.getItem(key); if (n !== null && [...per.options].some(o => o.value === n)) per.value = n; } catch {} const draw = () => { const rows = [...table.tBodies[0].rows], hit = rows.filter(passes), n = +per.value || hit.length || 1; @@ -208,7 +258,10 @@ window.NulliusTable = { note.textContent = hit.length ? `${page * n + 1}–${Math.min(hit.length, page * n + n)} of ${hit.length}` : ''; prev.disabled = page === 0; next.disabled = (page + 1) * n >= hit.length; - if (empty) empty.hidden = hit.length > 0; + empty.hidden = hit.length > 0; + clearTimeout(said); + if (loaded) said = setTimeout(() => { live.textContent = hit.length ? `${note.textContent} ${live.dataset.noun}` : empty.textContent; }, 300); + drawn(); }; const first = () => { page = 0; draw(); }; per.addEventListener('change', () => { @@ -218,6 +271,15 @@ window.NulliusTable = { prev.addEventListener('click', () => { page--; draw(); }); next.addEventListener('click', () => { page++; draw(); }); draw(); + loaded = true; return first; }, }; + +/* Every table with sticky columns, and every table of the table macro, set up once the page is read. */ +const nulliusTables = () => document.querySelectorAll('table.grid').forEach(t => { + if (t.querySelector('.sticky-col')) NulliusTable.sticky(t); + if (t.hasAttribute('data-table')) NulliusTable.wire(t); +}); +if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', nulliusTables); +else nulliusTables(); diff --git a/app/static/workspaces/workspaces.css b/app/static/workspaces/workspaces.css index cc531457..d1d7d456 100644 --- a/app/static/workspaces/workspaces.css +++ b/app/static/workspaces/workspaces.css @@ -1,14 +1,11 @@ /* The Workspaces page: one row per workspace; its roots in a dialog (the Launches page's, runs/launches.css). */ .ws-head { justify-content: space-between; align-items: center; } .ws-current td { background: var(--accent-soft); } -.ws-mark { width: 1.2rem; } -.ws-table th { position: relative; } /* holds a header named for a screen reader only, inside the scrolling box */ -.ws-name { min-width: 12rem; } +.ws-current .count-btn { border-color: var(--text-faint); } /* the plain border blends into the open row */ .ws-show { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 2px .4rem; } .ws-title { overflow-wrap: anywhere; } /* a name wraps, never cut */ .ws-rename { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; } .ws-rename input[type=text] { width: min(16rem, 100%); font-size: .9rem; padding: .3rem .5rem; } -.ws-roots-btn { font-variant-numeric: tabular-nums; } .launch-delete .ws-root-list { list-style: none; padding: 0; margin: 12px 0 0; } .ws-root-list li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--border-soft); } .ws-root-list li > .mono { flex: 1; min-width: 0; font-size: 13px; overflow-wrap: anywhere; } /* a path wraps, never cut */ @@ -17,3 +14,4 @@ dialog.std-how.launch-delete.wide { width: min(56rem, calc(100vw - 32px)); } /* the roots: room for a path */ .launch-delete .std-how-head h2 { min-width: 0; overflow-wrap: anywhere; } .grid.tools.ws-table td { vertical-align: middle; } /* a count beside a button: one line */ +.ws-table td[data-col="launches"] { position: relative; } /* holds a greyed count's hidden reason */ diff --git a/app/templates/_tables.html b/app/templates/_tables.html index fd9e1595..a8a68dc9 100644 --- a/app/templates/_tables.html +++ b/app/templates/_tables.html @@ -1,68 +1,145 @@ -{# Value filter for one column: a caret in the header opening a checkbox list of `choices`, (value, label) pairs. - Values start all-checked; unchecking hides the matching rows (static/tables.js). #} -{% macro filter_button(col, choices) %} - - - - +{#- The table toolkit: each macro is a feature a table opts into, run by static/tables.js (NulliusTable) and + styled in style.css ("the table toolkit"). #} + +{# A table's columns are one list of definitions, dicts that the headers, the cells, the Columns menu and Sort by + all read: `key` (the data-col), `label`; `type` 'text' (default) or 'num', how it sorts; `align` 'left', 'center' + or 'right' (a 'num' column's default), of its header and cells; `sticky`: pinned while the table scrolls, the last + one drawing the edge; `blank`: no visible name (a status, the actions), neither sorted nor in the Columns menu; + `check`: blank, a checkbox that ticks every visible row (check_cell in each row); `sr`: the label for a screen + reader only; `title`: its tooltip; `menu` false: not in the Columns menu; `fixed`: in it, always on; `off`: off + until the viewer chooses; `width` in a table macro's table: 'fit' (default), as wide as its widest cell on one + line, or 'expand', the rest of the width, wrapping. #} + +{#- The class attribute of a column's header or cell: its alignment, whether it is pinned, `edge` whether it is the + last pinned; `extra` adds to it. #} +{% macro classes(c, edge, extra='') %}{% set align = c.align or ('right' if c.type == 'num' else 'left') %} +{%- set cls = ([extra] if extra else []) + (['align-' ~ align] if align != 'left' else []) + (['sticky-col'] if c.sticky else []) + (['sticky-edge'] if c.sticky and edge else []) %} +{%- if cls %} class="{{ cls|join(' ') }}"{% endif %}{% endmacro %} + +{#- The last pinned column's key. #} +{% macro edge_of(cols) %}{{ (cols|selectattr('sticky')|map(attribute='key')|list)[-1:]|join }}{% endmacro %} + +{# The header cells of `cols`. #} +{% macro heads(cols) %}{% set edge = edge_of(cols) %} +{%- for c in cols %}{% set named = not (c.blank or c.check) %} + +{%- endfor %} +{%- endmacro %} + +{# A whole table (static/tables.js `wire`): its controls row, its headers from `cols`, a row of `rows` each, + and its pages. `id` names it, and keys what a viewer chooses; `class` adds to its classes; `tr`: a macro writing a + row's attributes. The call block writes a cell: it is called with a row and a column, in the order of `cols`, and + writes that cell with the cell macro. Opt-ins: `search`, `columns`, `choices`, `only`, `views`, `actions` as + controls'; `empty` and `noun` as pager's. #} +{% macro table(id, cols, rows, tr, class='', search='', columns=false, choices={}, only={}, empty='No rows match.', noun='rows', views=none, actions=none) %} +{{ controls(id, cols, search, columns, choices, only, views, actions) }} +{%- for c in cols if c.width == 'expand' %} + +{%- endfor %} +{%- set edge = edge_of(cols) %} +
+
+ {%- if c.check %}{% elif c.sr or c.blank %}{{ c.label }}{% else %}{{ c.label }}{% endif %}
+ + {{ heads(cols) }} + + + {%- for r in rows %} + + {%- for c in cols %}{{ caller(r, dict(c, edge=c.key == edge)) }}{% endfor %} + + {%- endfor %} + +
+ +{{ pager(id, empty, noun) }} {% endmacro %} -{# A table's Filter and Sort by menus, in place of header carets (static/tables.js `toolbar`). `filters`: a list of - (col, label, choices), choices as filter_button's; `sorts`: a list of (col, label), the sortable headers; - `only`: column -> the one value ticked at load, the others unticked. No filters: no Filter button. #} -{% macro tools(filters, sorts, only={}) %} -{% if filters %}