diff --git a/app/nullius/execution.py b/app/nullius/execution.py index aad62bf5..1236d793 100644 --- a/app/nullius/execution.py +++ b/app/nullius/execution.py @@ -1676,19 +1676,45 @@ def run_folder(name: str, root: Optional[str] = None) -> str: return path -def _run_deletion(name: str, home: str, root: Optional[str]) -> dict: +def size_of(path: str) -> int: + """The bytes of every file under *path*, links not followed; a file gone + since the walk listed it (a run still writing replaces its own) counts 0.""" + total = 0 + for d, _, names in os.walk(path): + for n in names: + try: + total += os.lstat(os.path.join(d, n)).st_size + except FileNotFoundError: + pass + return total + + +def _deletable(name: str, root: Optional[str]) -> tuple: + """A run's folder and record, when it is a run that has ended; ValueError + (alive, or not a run) or OSError (its record unreadable) otherwise.""" path = run_folder(name, root) with open(os.path.join(path, RECORD), encoding="utf-8") as fh: rec = json.load(fh) - ex = next((e for e in EXECUTIONS.values() if os.path.realpath(e.dir) == path), None) + ex = next((e for e in EXECUTIONS.values() if e.plan.name == name and os.path.realpath(e.dir) == path), None) state = ex.state if ex is not None else rec.get("state") if state in ALIVE: raise ValueError(f"{name} is {state}: stop it before you delete it") + return path, rec + + +def deletable(names: List[str], root: Optional[str] = None) -> None: + """Raise as ``deletion`` would for the runs *names*, without working out what goes.""" + for n in dict.fromkeys(names): + _deletable(n, root) + + +def _run_deletion(name: str, home: str, root: Optional[str], holding: Callable) -> dict: + path, rec = _deletable(name, root) plan = rec.get("plan") or {} # a run refused at the name check never made the host folder: one of that name there is not its own host = hosts.parse(plan["host"]) if plan.get("host") and (rec.get("launched") or rec.get("step") not in ("connect", "name")) else None held = [] - for ws, roots in workspace.holding(home, path): + for ws, roots in holding(path): dirs = parse.find_job_dirs(roots) ids = [j.job_id for j in workspace.load_jobs(ws, roots)] # a job of the same id from another root shares these judgements: they stay @@ -1696,18 +1722,19 @@ def _run_deletion(name: str, home: str, root: Optional[str]) -> dict: judged = judgements.job_dirs(ws.dir, [i for i in ids if i.split("~")[0] not in others]) held.append({"ws": ws, "roots": roots, "jobs": dirs, "judged": judged, "judgements": sum(len(os.listdir(d)) for d in judged)}) - size = sum(os.lstat(os.path.join(d, n)).st_size for d, _, names in os.walk(path) for n in names) - return {"name": name, "dir": path, "bytes": size, "host": host, "workspaces": held, + return {"name": name, "dir": path, "bytes": size_of(path), "host": host, "workspaces": held, "judgements": sum(w["judgements"] for w in held)} -def deletion(names: List[str], home: str, root: Optional[str] = None) -> dict: +def deletion(names: List[str], home: str, root: Optional[str] = None, holding: Optional[Callable] = None) -> dict: """What deleting the runs *names* of one launch removes: per run (``runs``) its folder and size, the host copy that is its own, and per workspace that holds it its roots, parsed jobs and judgement folders; the totals, and the number of copies per host. ValueError when any of them is alive or is not - a run: nothing goes then.""" - runs = [_run_deletion(n, home, root) for n in dict.fromkeys(names)] + a run: nothing goes then. ``holding``: a run folder's ``workspace.holding``, + when the caller has it already.""" + holding = holding or (lambda path: workspace.holding(home, path)) + runs = [_run_deletion(n, home, root, holding) for n in dict.fromkeys(names)] copies: Dict[str, int] = {} for r in runs: if r["host"]: diff --git a/app/nullius/runs/parse.py b/app/nullius/runs/parse.py index 364ef7cb..4d6e7290 100644 --- a/app/nullius/runs/parse.py +++ b/app/nullius/runs/parse.py @@ -852,10 +852,10 @@ def _budget(b) -> dict: "shards": num(b.get("shards")) or 0, "shards_stopped": num(b.get("shards_stopped")) or 0} -def parse_job(job_dir: str, reuse=None) -> Job: +def parse_job(job_dir: str, reuse=None, trials: bool = True) -> Job: """One job directory. ``reuse(trial_dir)``: a Trial already parsed from files that have not changed since (a workspace's cache, for a running - job), or None to parse it.""" + job), or None to parse it. ``trials=False``: the job's own records only.""" res = verifier._read_json(os.path.join(job_dir, "result.json")) or {} cfg = verifier._read_json(os.path.join(job_dir, "config.json")) or {} stats = res.get("stats") or {} @@ -909,7 +909,7 @@ def parse_job(job_dir: str, reuse=None) -> Job: dataset_path=redact(dataset_path), ) - for name in sorted(os.listdir(job_dir)): + for name in sorted(os.listdir(job_dir)) if trials else (): sub = os.path.join(job_dir, name) if os.path.isdir(sub) and os.path.isfile(os.path.join(sub, "result.json")): t = (reuse(sub) if reuse else None) or parse_trial(job.job_id, sub) diff --git a/app/nullius/workspace.py b/app/nullius/workspace.py index 5f982f57..2020aa5f 100644 --- a/app/nullius/workspace.py +++ b/app/nullius/workspace.py @@ -237,12 +237,19 @@ def delete(home_dir: str, name: str) -> bool: def holding(home_dir: str, folder: str) -> list: """Every workspace with a root in *folder*: [(workspace, those roots)].""" - inside = os.path.join(os.path.realpath(folder), "") - found = [] + return holding_all(home_dir, [folder])[folder] + + +def holding_all(home_dir: str, folders) -> dict: + """``holding`` of each of *folders*, each workspace and root read once.""" + inside = {f: os.path.join(os.path.realpath(f), "") for f in folders} + found = {f: [] for f in folders} for ws in list_all(home_dir): - roots = [r for r in ws.roots if os.path.join(os.path.realpath(r), "").startswith(inside)] - if roots: - found.append((ws, roots)) + real = [(r, os.path.join(os.path.realpath(r), "")) for r in ws.roots] + for f, prefix in inside.items(): + roots = [r for r, rr in real if rr.startswith(prefix)] + if roots: + found[f].append((ws, roots)) return found diff --git a/app/static/runs/launches.css b/app/static/runs/launches.css index 4450ab50..24c322f9 100644 --- a/app/static/runs/launches.css +++ b/app/static/runs/launches.css @@ -113,3 +113,41 @@ dialog.std-how.launch-delete { width: min(520px, calc(100vw - 32px)); } .launch-agents tr.la-shard .la-who a { font-weight: 400; color: var(--text-dim); } .la-note { color: var(--patch_failed_tests); } .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); } +.inventory .launch-delete-btn:hover, .inventory .launch-delete-btn:focus-visible { color: var(--bad); } +.inventory .icon-btn[aria-disabled="true"] { opacity: .4; background: none; border-color: transparent; cursor: default; } /* Delete it cannot: the slot kept, greyed, its reason reachable */ +/* 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); } +.inventory .sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; } +/* 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; } +.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/style.css b/app/static/style.css index cc8ddce9..3ecd015e 100644 --- a/app/static/style.css +++ b/app/static/style.css @@ -370,6 +370,7 @@ button.seg:hover { filter: brightness(1.25); } .menu label:hover { background: var(--surface-2); color: var(--text); } .menu input { accent-color: var(--accent); } .table-note { color: var(--text-faint); font-size: .8rem; } +.table-pager { margin-top: .6rem; } .empty-note { color: var(--text-dim); font-size: .88rem; padding: 1.5rem 0; text-align: center; } .grid.sortable thead th { cursor: pointer; user-select: none; white-space: nowrap; } @@ -405,19 +406,20 @@ button.seg:hover { filter: brightness(1.25); } does scroll horizontally. */ /* the checkbox and Run columns stay put while you scroll sideways, so a row - never loses its identity */ -.table-wrap .grid th.pick-col, .table-wrap .grid td.pick-col { - position: sticky; left: 0; z-index: 2; background: var(--bg); + 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 { + 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"] { z-index: 4; background: var(--bg); } +.table-wrap .grid thead th[data-col="run"], .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"] { background: var(--surface); } +.table-wrap .grid tbody tr:hover td[data-col="run"], .table-wrap .grid tbody tr:hover td.sticky-col { background: var(--surface); } /* compact density — same data, ~35% less width */ .grid.compact { font-size: .88rem; } @@ -441,6 +443,16 @@ button.seg:hover { filter: brightness(1.25); } 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; } +.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; } +.tools-menu legend { float: left; padding: .3rem .45rem; font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; color: var(--text-faint); } +.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; } +.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; } diff --git a/app/static/tables.js b/app/static/tables.js new file mode 100644 index 00000000..baab63f3 --- /dev/null +++ b/app/static/tables.js @@ -0,0 +1,217 @@ +/* A table.grid's sortable headers and per-column value filters, shared by the + tables that have them. */ +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 + carries data-sorted at load is the sort the rows came in. The sorted + header carries aria-sort. `after` runs after each sort. Returns resort(), + to sort rows put in since; resort.set(index, dir) sorts by that header + (dir 1 up, -1 down), set(null) puts the rows back in the order they came + in; resort.state() is {col, dir}. */ + sortable(table, after = () => {}) { + const heads = [...table.tHead.rows[0].cells], body = table.tBodies[0], order = [...body.rows]; + const first = heads.find(th => th.dataset.sorted); + let col = first ? heads.indexOf(first) : null, dir = first?.dataset.sorted === 'asc' ? 1 : -1; + const key = (row, type) => { + const cell = row.cells[col]; + const raw = cell.dataset.sort ?? cell.textContent.trim(); + return type === 'num' ? parseFloat(raw) || 0 : raw.toLowerCase(); + }; + const resort = () => { + if (col === null) return; + const type = heads[col].dataset.type || 'text'; + [...body.rows].sort((a, b) => { + const x = key(a, type), y = key(b, type); + return (x < y ? -1 : x > y ? 1 : 0) * dir; + }).forEach(r => body.appendChild(r)); + after(); + }; + const mark = () => heads.forEach((th, idx) => { + th.toggleAttribute('data-sorted', idx === col); + th.toggleAttribute('aria-sort', idx === col); + if (idx === col) { th.dataset.sorted = dir > 0 ? 'asc' : 'desc'; th.setAttribute('aria-sort', dir > 0 ? 'ascending' : 'descending'); } + }); + resort.set = (idx, d = 1) => { + col = idx; dir = d; mark(); + if (idx !== null) return resort(); + order.forEach(r => body.appendChild(r)); + after(); + }; + resort.state = () => ({col, dir}); + mark(); + heads.forEach((th, idx) => { + if (!th.dataset.type) return; + th.tabIndex = 0; + const sort = () => resort.set(idx, col === idx ? -dir : (th.dataset.type === 'num' ? -1 : 1)); + th.addEventListener('click', sort); + th.addEventListener('keydown', e => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); sort(); } }); + }); + 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. `changed` runs after each change. */ + 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 sync = () => { + 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])); + changed(); + }; + menu.addEventListener('change', sync); + menu.addEventListener('click', e => { + 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))); + const clear = () => { + scope.querySelectorAll('[data-filter-menu]').forEach(menu => { + 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 = []) { + 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.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`. */ + menu(btn, menu) { + const close = () => { menu.hidden = true; btn.setAttribute('aria-expanded', 'false'); }; + btn.addEventListener('click', () => { + const open = menu.hidden; + menu.hidden = !open; + btn.setAttribute('aria-expanded', String(open)); + if (open) menu.querySelector('input:not(:disabled), button')?.focus(); + }); + 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(); }; + 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. + 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 count = fbtn.querySelector('.tools-count'); + const narrowed = () => { + const n = Object.values(f.allowed).filter(Boolean).length; + count.textContent = n || ''; + count.hidden = !n; + changed(); + }; + const f = this.filters(fmenu, narrowed); + fmenu.querySelector('[data-clear]').addEventListener('click', () => { f.clear(); narrowed(); }); + const heads = [...table.tHead.rows[0].cells]; + const sync = () => { + 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); + }); + sync(); + this.menu(fbtn, fmenu); + this.menu(sbtn, smenu); + return {passes: f.passes, resort}; + }, + + /* 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; + 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; + page = Math.min(page, Math.max(0, Math.ceil(hit.length / n) - 1)); + rows.forEach(r => { r.hidden = true; }); + hit.slice(page * n, page * n + n).forEach(r => { r.hidden = false; }); + 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; + }; + const first = () => { page = 0; draw(); }; + per.addEventListener('change', () => { + try { localStorage.setItem(key, per.value); } catch {} + first(); + }); + prev.addEventListener('click', () => { page--; draw(); }); + next.addEventListener('click', () => { page++; draw(); }); + draw(); + return first; + }, +}; diff --git a/app/templates/_tables.html b/app/templates/_tables.html new file mode 100644 index 00000000..9791ac73 --- /dev/null +++ b/app/templates/_tables.html @@ -0,0 +1,62 @@ +{# 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) %} + + + + +{% 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. #} +{% macro tools(filters, sorts) %} + + +{% endmacro %} + +{# The pages of the table whose id is `table` (static/tables.js `pager`): how many rows a page shows, 25 at first, + and the page before and after. #} +{% macro pager(table) %} +
+ + + + + +
+{% endmacro %} diff --git a/app/templates/base.html b/app/templates/base.html index 08c97a7f..e86fd001 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -46,6 +46,7 @@ + @@ -53,6 +54,7 @@ + @@ -63,12 +65,21 @@ + + + + + + + + + @@ -235,6 +246,7 @@ + Launches Settings diff --git a/app/templates/runs/_launch_ask.html b/app/templates/runs/_launch_ask.html new file mode 100644 index 00000000..2a98fefe --- /dev/null +++ b/app/templates/runs/_launch_ask.html @@ -0,0 +1,57 @@ +{#- What Delete asks of a launch: what goes, and the hosts' copies to take too. #} +{% macro ask(L, gone, back='') %}{% set n, wss, k = gone.judgements, gone.workspaces, gone.runs|length %} +

Delete launch {{ L.title }}

+
+ {% if back %}{% endif %} + +

{{ k }} folder{{ '' if k == 1 else 's' }} · {{ gone.bytes|filesizeformat }}{% if n %} · {{ n }} judgement{{ '' if n == 1 else 's' }}{% endif %}{% if wss %} · workspace{{ '' if wss|length == 1 else 's' }} {{ wss|join(', ') }}{% endif %}

+ {% for h, c in gone.hosts.items() %}{% endfor %} +
+
+{%- endmacro %} + +{#- Delete on a launch: the button, and what it asks in the dialog `dialogs()` draws. The caller lists the launch's runs, + as
  • . `back`: where the route returns to; `icon`: the button a trash icon; no `gone`: the question is asked of + the server when the dialog opens (`launch_ask`). The element that holds both carries data-launch. #} +{% macro delete_ask(L, gone, back='', icon=false) %} + {% if icon %} + {%- else %}{% endif %} + {%- if gone %} + {%- set items = caller() %} + {% endif %} +{%- endmacro %} + +{#- One dialog for every launch: a button fills it from its launch's template (`asks`: button class -> template class), + or from the server (the button's data-ask); + ?delete= opens the Delete question on load. #} +{% macro dialogs(asks={'launch-delete-btn': 'launch-ask'}) %} + + +{%- endmacro %} diff --git a/app/templates/runs/index.html b/app/templates/runs/index.html index 4f9f8357..81dbd698 100644 --- a/app/templates/runs/index.html +++ b/app/templates/runs/index.html @@ -1,26 +1,12 @@ {% from 'runs/_runtime.html' import what_ran %} +{% from '_tables.html' import filter_button %} +{% from 'runs/_launch_ask.html' import delete_ask, dialogs %} {% extends "base.html" %} {% block title %}Runs — Nullius{% endblock %} {% block head %} + {% endblock %} -{# Value filter for one column: a caret in the header opening a checkbox list. - Values start all-checked; unchecking hides the matching rows. #} -{% macro filter_button(col) %} - - - - -{% endmacro %} {#- A row's name as the launch's table shows it: the control, the agent, else its job id past the launch's prefix. #} {% macro row_name(r, L) %}{% set j = r.job %}{{ r.control or (j.agent_label if j and j.agent_label else r.job_id[L.prefix|length - 1:] if L.prefix.endswith('*') and r.job_id.startswith(L.prefix[:-1]) else r.job_id) }}{% endmacro %} @@ -168,50 +154,17 @@

    {{ g.dataset_title if L.dataset else (L.name or g.dataset_title) }}{% if g.n {% if g.compare|length >= 2 %}Compare these {{ g.compare|length }} {% elif g.agents %}Compare needs two finished agents{% endif %} {#- every row is of runs Nullius made: the launch goes as one, its shards with it, asked first in the dialog below #} - {% if g.gone %}{% set gone, rows = g.gone, g.controls + g.agents %}{% set n, wss, k = gone.judgements, gone.workspaces, gone.runs|length %} - - {% endif %} + {% if g.gone %}{% call delete_ask(L, g.gone) %}{% for r in g.controls + g.agents %}
  • {{ row_name(r, L) }}{% if r.shards %} ({{ r.shards|length }} shards){% endif %}
  • {% endfor %}{% endcall %}{% endif %} {% endfor %} - {#- one dialog for every launch: its Delete fills it from the launch's template; ?delete= opens it on load #} - + {{ dialogs() }} -

  • ", self.get(f"/launch/{key}/ask").get_data(as_text=True)) # Delete asks for the whole launch + + def test_shards_that_wrote_no_job_yet_are_one_launch(self): + from tests.test_standard_shard import write_shard + for i in (1, 2, 3): + d = self.tmp / "runs" / f"p{i}" + plan = execution.Plan(name=f"p{i}", script="true", jobs=[{"name": f"P-shard-{i}of3", "launch": "P"}]) + self._write_json(str(d / "run.json"), {"plan": plan.to_dict(), "state": "running", "step": "run"}) + if i == 1: + write_shard(str(d / "jobs"), "P-shard-1of3", ["u-1"], 1, 3, total=3, launch="P") + with patch.object(execution.Execution, "resume", lambda ex: ex): + execution.restore() + rows = self.rows() + (mine,) = [v for k, v in rows.items() if k != f"run:{self.ex.id}"] + self.assertEqual([self.cells(mine)[c] for c in ("launch", "shards")], ["P", "3"]) + + def test_a_sharded_launch_still_going_is_one_row_in_every_state(self): + for i, (state, host) in enumerate((("preparing", None), ("running", "ubuntu@10.0.0.6"), ("stopping", "gpu-box")), 1): + d = self.tmp / "runs" / f"q{i}" + plan = execution.Plan(name=f"q{i}", script="true", host=hosts.parse(host) if host else None, jobs=[{"name": f"Q-shard-{i}of3", "launch": "Q"}]) + self._write_json(str(d / "run.json"), {"plan": plan.to_dict(), "state": state, "step": "run"}) # no shard wrote its job yet + with patch.object(execution.Execution, "resume", lambda ex: ex): + execution.restore() + rows = self.rows() + (mine,) = [v for k, v in rows.items() if k != f"run:{self.ex.id}"] + self.assertEqual([self.cells(mine)[c] for c in ("state", "launch", "shards", "machines")], + ["running", "Q", "3", "this machine, ubuntu@10.0.0.6, gpu-box"]) # the most telling shard + self.assertIn('title="Delete launch: not while it runs"', mine) + + def test_filter_and_sort_by_are_menus_beside_columns(self): + self.record("r3") + html = self.get("/launches").get_data(as_text=True) + tools = re.search(r'
    (.*?)
    ', html, re.S).group(1) + self.assertEqual(re.findall(r'