From 4a8b926111d261627cfce5aa5f5cfe796af20006 Mon Sep 17 00:00:00 2001 From: Harenome Ranaivoarivony-Razanajato Date: Thu, 19 Nov 2026 13:51:25 +0100 Subject: [PATCH 1/7] feat(web): show the Workspaces page as cards or a table A Table/Cards toggle at the end of the controls row (the controls macro's `layout`, a link to ?view=cards that keeps the rest of the query). The server renders only the view chosen. The cards are the card toolkit's over the table's own fields, each in its slot; their Roots and Delete open the same dialogs. Sort by now works on cards too, for a collection that asks. --- app/static/tables.js | 19 +++++++++-- app/templates/_cards.html | 25 +++++++------- app/templates/_tables.html | 22 ++++++++----- app/templates/base.html | 1 + app/templates/workspaces/workspaces.html | 42 ++++++++++++++++++------ app/ui_tests/test_run_routes.py | 24 ++++++++++++++ app/ui_tests/test_tables.py | 2 +- 7 files changed, 103 insertions(+), 32 deletions(-) diff --git a/app/static/tables.js b/app/static/tables.js index ad394d5c..d966c587 100644 --- a/app/static/tables.js +++ b/app/static/tables.js @@ -229,7 +229,8 @@ window.NulliusTable = { how many show once the changes pause, counted in the live region's data-noun. A click anywhere on a card but on a control of its own follows the card's link, in a new tab or window with the keys or the - button a link takes; a click that ends a text selection does not. */ + button a link takes; a click that ends a text selection does not. Sort by, + when it has one, sorts the cards within their grids as a table's rows. */ cards(root) { const items = [...root.querySelectorAll('[data-card]')], empty = document.querySelector(`[data-empty="${CSS.escape(root.id)}"]`); const live = document.querySelector(`[data-live="${CSS.escape(root.id)}"]`), say = this.voice(live); @@ -252,7 +253,21 @@ window.NulliusTable = { empty.hidden = n > 0; say(n ? `${n} of ${items.length} ${live.dataset.noun}` : empty.textContent); }; - const passes = this.narrow(document.getElementById(root.id + '-tools'), draw); + const tools = document.getElementById(root.id + '-tools'), passes = this.narrow(tools, draw); + const [sbtn, smenu] = [tools.querySelector('[data-tools-btn="sort"]'), tools.querySelector('[data-tools="sort"]')]; + if (smenu) { // the table's Sort by, over each card's data-s- + const dirs = [...smenu.querySelectorAll('[data-sort-dir]')]; + const sort = e => { + const c = smenu.querySelector('[data-sort-col]:checked'), on = c.value, num = c.dataset.type === 'num'; + const dir = e?.target.matches('[data-sort-dir]') ? (e.target.value === 'asc' ? 1 : -1) : (num ? -1 : 1); + dirs.forEach(r => { r.checked = Boolean(on) && r.value === (dir > 0 ? 'asc' : 'desc'); r.disabled = !on; }); + const key = card => { const raw = card.getAttribute('data-s-' + on) ?? ''; return num ? parseFloat(raw) || 0 : raw.toLowerCase(); }; + (on ? [...items].sort((a, b) => { const x = key(a), y = key(b); return (x < y ? -1 : x > y ? 1 : 0) * dir; }) : items).forEach(c => c.parentNode.appendChild(c)); + }; + smenu.addEventListener('change', sort); + sort(); + this.menu(sbtn, smenu); + } draw(); }, diff --git a/app/templates/_cards.html b/app/templates/_cards.html index bb2970f4..0b957e0a 100644 --- a/app/templates/_cards.html +++ b/app/templates/_cards.html @@ -3,8 +3,9 @@ fills; a field without one is not on the card, and `table` false keeps a card-only field off a table. Slots, in order: `status`, `tag`*, `meta`, `check` (the top row); `icon`, `title` (exactly one); `text`; `badge`*, `note`*; `stat` (up to 3, below a line); `alert`; `action`* (* any number, the others at most one). - An item is a dict of display values by field key: a string, a dict {text, class, title, label, href, value} or a - list of them, empty for none; a filter reads a value's `value`, else its text. Plus `href` (its title's link), + An item is a dict of display values by field key: a string, a dict {text, class, title, label, href, value, attrs} + or a list of them, empty for none; a filter and Sort by read a value's `value`, else its text; an action's + `attrs` are its button's own attributes, its `class` added to the button's. Plus `href` (its title's link), `id`, `search` (what the search reads) and `keys`. A field's `class` goes on each of its values; `card_label` names a stat when its column header does not, and a value's `label` names it for that item; `style` 'code' sets the text as code; `icon` puts #i- before a @@ -19,19 +20,20 @@ {% macro pill(f, v) %}{% set cls = [f.class, v.class]|select|join(' ') %}{{ v.text }}{% endmacro %} {# A collection of cards (NulliusTable.cards): its controls row, its cards, the note when none passes. `id` names it; - `search`, `choices`, `only` and each field's `filter` as the table's controls; `noun` what the live region counts. + `search`, `choices`, `only`, `layout` and each field's `filter` as the table's controls; `sort` the Sort by menu, over + the fields that are not blank; `noun` what the live region counts. The call block, when given, writes the cards instead (grid for each group, such as the Benchmarks' shelves); a section in it marked data-group hides when none of its cards shows, and its data-group-n counts them. #} -{% macro cards(id, cols, items, search='', choices={}, only={}, empty='No items match.', noun='items') %} -{{ controls(id, cols, search, choices=choices, only=only, sort=false) }} -
{% if caller is defined %}{{ caller() }}{% else %}{{ grid(cols, items, choices=choices) }}{% endif %}
+{% macro cards(id, cols, items, search='', choices={}, only={}, empty='No items match.', noun='items', sort=false, layout=none) %} +{{ controls(id, cols, search, choices=choices, only=only, sort=sort, layout=layout) }} +
{% if caller is defined %}{{ caller() }}{% else %}{{ grid(cols, items, choices=choices, sort=sort) }}{% endif %}
{{ empty_note(id, empty) }} {% endmacro %} {# The cards of `items`. `every`: the collection the icon rule reads, when `items` is a part of it; `choices`: the - filtered fields, each written on the card for the filter. #} -{% macro grid(cols, items, every=none, choices={}) %} + filtered fields, each written on the card for the filter; `sort`: the fields Sort by reads, each written too. #} +{% macro grid(cols, items, every=none, choices={}, sort=false) %} {%- set fields = cols|selectattr('card')|list %} {%- set by = {} %}{% for slot in ['status', 'tag', 'meta', 'check', 'icon', 'title', 'text', 'badge', 'note', 'stat', 'alert', 'action'] %}{% set _ = by.update({slot: fields|selectattr('card', 'equalto', slot)|list}) %}{% endfor %} {#- the limits, each failing the page: one title, at most three stats, at most one of each other single slot #} @@ -42,7 +44,8 @@
{%- for item in items %}
+ {%- for f in cols if f.key in choices %} data-f-{{ f.key }}="{% call(f, v) each(item, [f]) %}{{ v.get('value', v.text) }} {% endcall %}"{% endfor %} + {%- for f in fields if sort and not f.blank %} data-s-{{ f.key }}="{% call(f, v) each(item, [f]) %}{{ v.get('value', v.text) }}{% endcall %}"{% endfor %}> {%- set top %}{% call(f, v) each(item, by.status) %}{{ pill(f, v) }}{% endcall %} {%- set tags %}{% call(f, v) each(item, by.tag) %}{{ pill(f, v) }}{% endcall %}{% endset %}{% if tags %}{{ tags }}{% endif %} {%- call(f, v) each(item, by.meta) %}{{ v.text }}{% endcall %} @@ -54,7 +57,7 @@ {%- if not src %} {%- elif '#' in src %} {%- else %}{% endif %}{% endif -%} - {{ name }}
+ {{ name }} {%- call(f, v) each(item, by.text) %}
{% if f.style == 'code' %}{{ v.text }}{% else %}{{ v.text }}{% endif %}
{% endcall %} {%- set badges %}{% call(f, v) each(item, by.badge) %}{{ pill(f, v) }}{% endcall %}{% endset %}{% if badges %} @@ -65,7 +68,7 @@
{{ stats }}
{% endif %} {%- call(f, v) each(item, by.alert) %}
{{ v.text }}
{% endcall %} - {%- set actions %}{% call(f, v) each(item, by.action) %}{% if v.href %}{{ v.text }}{% else %}{% endif %}{% endcall %}{% endset %}{% if actions %} + {%- set actions %}{% call(f, v) each(item, by.action) %}{% if v.href %}{{ v.text }}{% else %}{% endif %}{% endcall %}{% endset %}{% if actions %}
{{ actions }}
{% endif %} {%- endfor %} diff --git a/app/templates/_tables.html b/app/templates/_tables.html index f69afa77..7fbea968 100644 --- a/app/templates/_tables.html +++ b/app/templates/_tables.html @@ -31,13 +31,13 @@ {# 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; `sticky_head`: its header row pinned while it scrolls down, and `tr`'s + writes that cell with the cell macro. Opt-ins: `search`, `columns`, `choices`, `only`, `views`, `actions`, `layout` + as controls'; `empty` and `noun` as pager's; `sticky_head`: its header row pinned while it scrolls down, and `tr`'s rows with data-sticky under it (tables.js `sticky`), the controls row with them up to the table's end. #} -{% macro table(id, cols, rows, tr, class='', search='', columns=false, choices={}, only={}, empty='No rows match.', noun='rows', views=none, actions=none, sticky_head=false) %} +{% macro table(id, cols, rows, tr, class='', search='', columns=false, choices={}, only={}, empty='No rows match.', noun='rows', views=none, actions=none, layout=none, sticky_head=false) %} {%- if sticky_head %}
{% endif %} {%- set cols = cols|rejectattr('table', 'sameas', false)|list %} -{{ controls(id, cols, search, columns, choices, only, views, actions) }} +{{ controls(id, cols, search, columns, choices, only, views, actions, layout=layout) }} {%- for c in cols if c.width == 'expand' %} {%- endfor %} @@ -69,15 +69,16 @@ Columns menu; `choices`: column -> its (value, label) pairs to filter by; `only`: column -> the one value chosen at load; then the Sort by menu, unless `sort` is false. `views` and `actions`: macros writing a page's own buttons, each any number of them, run by the page: views (how the table looks) before Columns, actions (on the - rows or the selection) last. The search goes left, the buttons right. A column's + rows or the selection) after Sort by. `layout` 'table' or 'cards', the one shown: a toggle of links to the + page's other one (?view=cards), its other query kept, at the end. The search goes left, the buttons right. A column's `filter` says where its choices go, one form or a list of them: 'button' (the default), in the Filter menu; 'dropdown', a menu of its own; 'pills', a row of toggles under the controls. A column's `filter_icon`, a sprite id without its `i-`, leads its dropdown's button and its pills. `id`: the table's. #} -{% macro controls(id, cols, search='', columns=false, choices={}, only={}, views=none, actions=none, sort=true) %} +{% macro controls(id, cols, search='', columns=false, choices={}, only={}, views=none, actions=none, sort=true, layout=none) %} {%- set by = {'button': [], 'dropdown': [], 'pills': []} %}{% for c in cols if c.key in choices %}{% for f in ([c.filter] if c.filter is string else c.filter or ['button']) %}{% set _ = by[f].append(c) %}{% endfor %}{% endfor %}
{% if search %}{% endif %} - {% if columns or by.dropdown or by.button or sort or views or actions %}
+ {% if columns or by.dropdown or by.button or sort or views or actions or layout %}
{{ slot('views', views) }} {% if columns %}{% endif %} {% for c in by.dropdown %}
{% endif %} {{ slot('actions', actions) }} + {% if layout %}{% set q = dict(request.view_args, **request.args.to_dict(flat=false)) %}{% endif %}
{% endif %} {% for c in by.pills %}
diff --git a/app/templates/base.html b/app/templates/base.html index 0e2964f2..bfa53bfc 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -73,6 +73,7 @@ + diff --git a/app/templates/workspaces/workspaces.html b/app/templates/workspaces/workspaces.html index b95e9c63..a78e10e3 100644 --- a/app/templates/workspaces/workspaces.html +++ b/app/templates/workspaces/workspaces.html @@ -1,4 +1,5 @@ {% from '_tables.html' import table, cell, greyed %} +{% from '_cards.html' import cards %} {% extends "base.html" %} {% from '_page.html' import page_head %} {% block title %}Workspaces — Nullius{% endblock %} @@ -9,17 +10,39 @@ {% endblock %} {#- A workspace's row: the open one marked, what its search reads. #} {% macro ws_tr(ws) %} class="{{ 'ws-current' if workspace and ws.name == workspace.name }}" data-ws="{{ ws.name }}" data-search="{{ ws.label }} {{ ws.name }}"{% endmacro %} +{#- A workspace's launches, a link to them when it has any; when it was last opened, as digits to sort by (UTC, as every + workspace records it; never opened sorts last, newest first). #} +{% macro launches(ws) %}{% set n = n_launches[ws.name] %}{% if n %}{{ n }} + {%- else %}{{ greyed('Launches of ' ~ ws.label ~ ': 0', '', 'No launches in ' ~ ws.label, 'none-' ~ ws.name, icon='launches', class='btn ghost sm count-btn', text='0') }}{% endif %}{% endmacro %} +{% macro opened(ws) %}{{ ws.opened[:19]|replace('-', '')|replace(':', '')|replace('T', '') or 0 }}{% endmacro %} {% block body %} {% set actions %}New workspace{% endset %} {{ page_head('Workspaces', actions=actions) }} {% if workspaces %} -{% set labels = workspaces|map(attribute='label')|list %} -{% set cols = [dict(key='open', label='Open', blank=true), dict(key='name', label='Name', width='expand'), dict(key='runs', label='Runs', type='num'), - dict(key='checks', label='Checks', type='num'), dict(key='opened', label='Last opened', type='num', align='left'), - dict(key='launches', label='Launches', type='num', align='right'), dict(key='roots', label='Roots', type='num', align='right'), dict(key='actions', label='Actions', blank=true)] %} -{% call(ws, c) table('workspaces', cols, workspaces, ws_tr, class='ws-table', search='Search by name', noun='workspaces') %} +{% set labels = workspaces|map(attribute='label')|list %}{% set trash %}{% endset %} +{% set cols = [dict(key='open', label='Open', blank=true, card='status'), dict(key='name', label='Name', width='expand', card='title'), + dict(key='disk', label='Folder', blank=true, table=false, card='text', class='mono faint'), + dict(key='runs', label='Runs', type='num', card='stat'), dict(key='checks', label='Checks', type='num', card='stat'), + dict(key='opened', label='Last opened', type='num', align='left', card='meta'), + dict(key='launches', label='Launches', type='num', align='right', card='stat'), dict(key='roots', label='Roots', type='num', align='right', card='action'), + dict(key='actions', label='Actions', blank=true, card='action')] %} +{% if request.args.get('view') == 'cards' %} +{#- the same fields as the table's columns, each in its card slot; a rename only in the table #} +{% set items = [] %} +{% for ws in workspaces %}{% set current = workspace and ws.name == workspace.name %} + {%- set open %}{% if current %}●{% endif %}{% endset %} + {%- set roots %}{{ ws.roots|length }}{% endset %} + {%- set _ = items.append(dict(open=open, name=ws.label, disk=ws.name if labels.count(ws.label) > 1 else '', runs=counts[ws.name].runs, checks=counts[ws.name].checks, + opened=dict(text=ws.opened[:16]|replace('T', ' '), value=opened(ws)), launches=dict(text=launches(ws), value=n_launches[ws.name]), + roots=dict(text=roots, value=ws.roots|length, class='count-btn ws-roots-btn', title='Roots', attrs={'data-ask': url_for('workspace_roots', name=ws.name), 'aria-haspopup': 'dialog', 'aria-label': 'Roots of ' ~ ws.label ~ ': ' ~ ws.roots|length}), + actions=dict(text=trash, class='danger', title='Delete workspace', attrs={'data-ask': 'ws-ask-delete', 'data-label': ws.label, 'data-action': url_for('workspace_delete', name=ws.name), 'data-judged': n_judged[ws.name], 'aria-haspopup': 'dialog', 'aria-label': 'Delete workspace ' ~ ws.label}), + search=ws.label ~ ' ' ~ ws.name)) %} +{%- endfor %} +{{ cards('workspaces', cols, items, search='Search by name', empty='No workspace matches.', noun='workspaces', sort=true, layout='cards') }} +{% else %} +{% call(ws, c) table('workspaces', cols, workspaces, ws_tr, class='ws-table', search='Search by name', noun='workspaces', layout='table') %} {%- set current = workspace and ws.name == workspace.name %}{% set clash = labels.count(ws.label) > 1 %} {%- if c.key == 'open' %}{% call cell(c) %}{% if current %}●{% endif %}{% endcall %} {%- elif c.key == 'name' %}{% call cell(c, sort=ws.label, class='ws-name') %} @@ -35,18 +58,17 @@ {% endcall %} {%- elif c.key == 'runs' %}{% call cell(c) %}{{ counts[ws.name].runs }}{% endcall %} {%- elif c.key == 'checks' %}{% call cell(c) %}{{ counts[ws.name].checks }}{% endcall %} - {#- the time as digits, UTC as every workspace records it; never opened sorts last, newest first #} - {%- elif c.key == 'opened' %}{% call cell(c, sort=ws.opened[:19]|replace('-', '')|replace(':', '')|replace('T', '') or 0, class='mono faint nowrap') %}{{ ws.opened[:16]|replace('T', ' ') }}{% endcall %} - {%- elif c.key == 'launches' %}{% call cell(c) %}{% set n = n_launches[ws.name] %}{% if n %}{{ n }} - {%- else %}{{ greyed('Launches of ' ~ ws.label ~ ': 0', '', 'No launches in ' ~ ws.label, 'none-' ~ ws.name, icon='launches', class='btn ghost sm count-btn', text='0') }}{% endif %}{% endcall %} + {%- elif c.key == 'opened' %}{% call cell(c, sort=opened(ws), class='mono faint nowrap') %}{{ ws.opened[:16]|replace('T', ' ') }}{% endcall %} + {%- elif c.key == 'launches' %}{% call cell(c) %}{{ launches(ws) }}{% endcall %} {%- elif c.key == 'roots' %}{% call cell(c, sort=ws.roots|length) %} {% endcall %} {%- elif c.key == 'actions' %}{% call cell(c, class='acts-col') %} - + {% endcall %} {%- endif %} {% endcall %} +{% endif %} {#- every row's Delete, filled from its button #}