Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/static/catalogue/catalogue.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
.bench-card-name { min-width: 0; }
.bench-card-name > .icon-btn { vertical-align: middle; }
.bench-mark { flex: none; width: 22px; height: 22px; color: var(--accent); }
/* a table row's name (_cards.html rows): its icon, then its link */
.row-name { display: inline-flex; align-items: center; gap: 8px; }
.bench-card-domain { margin-top: -6px; font-size: 14px; line-height: 1.5; color: var(--text-dim); }
/* the stats in columns of one width, a column each, each its label then its value; on a card too narrow for one
line (a phone), two balanced rows: 4 as 2+2, 5 as 3+2, 6 as 3+3 */
Expand Down
47 changes: 37 additions & 10 deletions app/templates/_cards.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
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-<icon> before a
note. `icon` values are image URLs: when one item has one, the others show initials; when none has, no icon. -#}
{% from '_tables.html' import controls, empty_note %}
{% from '_tables.html' import controls, empty_note, table, cell %}

{#- Each value of `fields` in `item`, as a dict, to the call block with its field. #}
{% macro each(item, fields) %}{% for f in fields %}{% set v = item.get(f.key) %}
Expand All @@ -25,14 +25,44 @@

{# A collection of cards (NulliusTable.cards): its controls row, its cards, the note when none passes. `id` names it;
`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 fields that are not blank, or a list of their keys; `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', sort=false, layout=none) %}
{{ controls(id, cols, search, choices=choices, only=only, sort=sort, layout=layout) }}
section in it marked data-group hides when none of its cards shows, and its data-group-n counts them.
`layout` 'table' shows the same items as a table instead (rows), `default` the page's view without ?view=. #}
{% macro cards(id, cols, items, search='', choices={}, only={}, empty='No items match.', noun='items', sort=false, layout=none, default='table') %}
{%- if layout == 'table' %}{{ rows(id, cols, items, search, choices, only, empty, noun, sort, default) }}{% else %}
{{ controls(id, cols, search, choices=choices, only=only, sort=sort, layout=layout, default=default) }}
<div id="{{ id }}" data-cards>{% if caller is defined %}{{ caller() }}{% else %}{{ grid(cols, items, choices=choices, sort=sort) }}{% endif %}</div>
{{ empty_note(id, empty) }}
<span class="sr" data-live="{{ id }}" data-noun="{{ noun }}" aria-live="polite"></span>
{%- endif %}
{% endmacro %}

{#- An item's icon: `src` an image URL or a sprite symbol, else the initials of `name`. #}
{% macro mark(icon, src, name) %}
{%- if not src %}<span class="ws-avatar {{ icon.class }}" aria-hidden="true">{{ name[:2]|upper }}</span>
{%- elif '#' in src %}<span class="{{ icon.class }}" aria-hidden="true"><svg class="agent-logo"><use href="{{ src }}"/></svg></span>
{%- else %}<span class="{{ icon.class }}" aria-hidden="true"><img class="agent-logo" src="{{ src }}" alt=""></span>{% endif %}{% endmacro %}

{#- A row's attributes, written once per item by rows. #}
{% macro attrs(r) %}{{ r.attrs }}{% endmacro %}

{# The items of a cards collection as a table (the table toolkit's, with its Columns menu): a column per field the
table takes that some item fills (a filtered or 'num' one always), in the order of `cols`; the title pinned, its
icon before it and a link to `href`, the others as on the card. A field `off` starts hidden. #}
{% macro rows(id, cols, items, search, choices, only, empty, noun, sort, default) %}
{%- set icon = (cols|selectattr('card', 'equalto', 'icon')|list + [none])[0] %}
{%- set icons = icon and items|selectattr(icon.key)|list|length > 0 %}
{%- set shown = [] %}{% for c in cols if c.table is not sameas false and (c.key in choices or c.type == 'num' or items|selectattr(c.key)|list) %}{% set _ = shown.append(dict(c, sticky=c.card == 'title')) %}{% endfor %}
{%- set rs = [] %}{% for item in items %}{% set a %}{% if item.get('id') %} id="{{ item.id }}"{% endif %} data-search="{{ item.get('search', '') }}"
{%- for f in cols if f.key in choices %} data-f-{{ f.key }}="{% call(f, v) each(item, [f]) %}{{ v.get('value', v.text) }}&#10;{% endcall %}"{% endfor %}{% endset %}
{%- set _ = rs.append({'item': item, 'attrs': a}) %}{% endfor %}
{% call(r, c) table(id, shown, rs, attrs, search=search, columns=true, choices=choices, only=only, empty=empty, noun=noun, sort=sort, layout='table', default=default) %}
{%- set v = r.item.get(c.key) %}{% set by %}{% call(f, x) each(r.item, [c]) %}{{ x.get('value', x.text) }} {% endcall %}{% endset %}
{%- call cell(c, sort=by|trim) %}{% if c.card == 'title' %}{% set name = v.text if v is mapping else v %}<span class="row-name">{% if icons %}{{ mark(icon, r.item.get(icon.key), name) }}{% endif %}<a href="{{ r.item.href }}">{{ name }}</a></span>
{%- elif c.style == 'code' %}<code>{{ v }}</code>
{%- else %}{% call(f, x) each(r.item, [c]) %}{{ pill(f, x) }} {% endcall %}{% endif %}{% endcall %}
{%- endcall %}
{% endmacro %}

{# The cards of `items`. `every`: the collection the icon rule reads, when `items` is a part of it; `choices`: the
Expand All @@ -49,13 +79,10 @@
{%- for item in items %}
<article class="bench-card" data-card{% if item.get('id') %} id="{{ item.get('id') }}"{% endif %}{% if item.get('search') %} data-search="{{ item.get('search') }}"{% endif %}{% if item.get('keys') %} data-keys="{{ item.get('keys') }}"{% endif %}
{%- for f in cols if f.key in choices %} data-f-{{ f.key }}="{% call(f, v) each(item, [f]) %}{{ v.get('value', v.text) }}&#10;{% 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 %}>
{%- for f in fields if sort and not f.blank and (sort is sameas true or f.key in sort) %} data-s-{{ f.key }}="{% call(f, v) each(item, [f]) %}{{ v.get('value', v.text) }}{% endcall %}"{% endfor %}>
{%- set title = by.title[0] %}{% set v = item.get(title.key) %}{% set v = v if v is mapping else {'text': v} %}{% set name = v.text %}
{%- set cls = [title.class, v.class]|select|join(' ') %}
<div class="bench-card-title{{ ' ' ~ cls if cls }}">{% if icons %}{% set src = item.get(icon.key) %}
{%- if not src %}<span class="ws-avatar {{ icon.class }}" aria-hidden="true">{{ name[:2]|upper }}</span>
{%- elif '#' in src %}<span class="{{ icon.class }}" aria-hidden="true"><svg class="agent-logo"><use href="{{ src }}"/></svg></span>
{%- else %}<span class="{{ icon.class }}" aria-hidden="true"><img class="agent-logo" src="{{ src }}" alt=""></span>{% endif %}{% endif -%}
<div class="bench-card-title{{ ' ' ~ cls if cls }}">{% if icons %}{{ mark(icon, item.get(icon.key), name) }}{% endif -%}
{%- set link %}<a class="card-link"{% if item.get('href') %} href="{{ item.get('href') }}"{% endif %}>{{ name }}</a>{% endset %}
{%- if v.after %}<span class="bench-card-name">{{ link }} {{ v.after }}</span>{% else %}{{ link }}{% endif %}
{%- set corner %}{% call(f, v) each(item, by.check) %}<input type="checkbox" data-check value="{{ v.value }}" aria-label="{{ v.text }}">{% endcall %}
Expand Down
20 changes: 11 additions & 9 deletions app/templates/_tables.html
Original file line number Diff line number Diff line change
Expand Up @@ -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`, `layout`
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`, `sort`,
`layout`, `default` 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, layout=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, sort=true, default='table') %}
{%- if sticky_head %}<div>{% endif %}
{%- set cols = cols|rejectattr('table', 'sameas', false)|list %}
{{ controls(id, cols, search, columns, choices, only, views, actions, layout=layout) }}
{{ controls(id, cols, search, columns, choices, only, views, actions, sort=sort, layout=layout, default=default) }}
{%- for c in cols if c.width == 'expand' %}
<style>#{{ id }} > * > tr > :nth-child({{ cols.index(c) + 1 }}) { width: auto; min-width: var(--expand-min); white-space: normal; overflow-wrap: anywhere; }</style>
{%- endfor %}
Expand Down Expand Up @@ -67,14 +67,16 @@
{# A table's controls row (static/tables.js `toolbar`) over the columns `cols`; each feature on only
when asked. `search`: the search box's name and placeholder, over each row's data-search text; `columns`: the
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
at load; then the Sort by menu, unless `sort` is false; a list of keys
offers those columns only. `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) 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
page's other one, its other query kept, at the end; `default` the view a page shows without ?view=, the other
one's link carrying ?view=<it>. 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, layout=none) %}
{% macro controls(id, cols, search='', columns=false, choices={}, only={}, views=none, actions=none, sort=true, layout=none, default='table') %}
{%- 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 %}
<div class="table-tools table-controls" id="{{ id }}-tools">
{% if search %}<label class="st-search"><svg class="ic" aria-hidden="true"><use href="#i-search"/></svg><input type="search" data-search placeholder="{{ search }}" aria-label="{{ search }}" autocomplete="off" spellcheck="false"></label>{% endif %}
Expand All @@ -100,7 +102,7 @@
<fieldset>
<legend>Column</legend>
<label><input type="radio" name="{{ id }}-sort-col" data-sort-col value="" checked> Default</label>
{% for c in cols if not (c.blank or c.check) %}<label><input type="radio" name="{{ id }}-sort-col" data-sort-col value="{{ c.key }}" data-type="{{ c.type or 'text' }}"> {{ c.label }}</label>{% endfor %}
{% for c in cols if not (c.blank or c.check) and (sort is sameas true or c.key in sort) %}<label><input type="radio" name="{{ id }}-sort-col" data-sort-col value="{{ c.key }}" data-type="{{ c.type or 'text' }}"> {{ c.label }}</label>{% endfor %}
</fieldset>
<fieldset>
<legend>Order</legend>
Expand All @@ -111,7 +113,7 @@
</div>{% endif %}
{{ slot('actions', actions) }}
{% if layout %}{% set q = dict(request.view_args, **request.args.to_dict(flat=false)) %}<nav class="seg-toggle icons" aria-label="View">
{%- for key, name in (('table', 'Table'), ('cards', 'Cards')) %}{% set _ = q.update(view=none if key == 'table' else key) %}
{%- for key, name in (('table', 'Table'), ('cards', 'Cards')) %}{% set _ = q.update(view=none if key == default else key) %}
<a href="{{ url_for(request.endpoint, **q) }}" aria-label="{{ name }}" title="{{ name }}" aria-current="{{ 'true' if layout == key else 'false' }}"><svg class="ic" aria-hidden="true"><use href="#i-{{ key }}"/></svg></a>
{%- endfor %}
</nav>{% endif %}
Expand Down
8 changes: 4 additions & 4 deletions app/templates/agents/kits.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ <h2 id="kit-checks-title">Checks</h2>
<div class="bench-index">
{{ page_head('Kits', sub=items|length ~ ' conformance kits') }}
{#- A card's fields (web/agents.py `_kit_card`); the family's pills filter them. #}
{% set cols = [dict(key='family', label='Family', card='tag', class='std-tag', filter='pills'), dict(key='version', label='Version', card='meta'),
dict(key='title', label='Name', card='title'), dict(key='port', label='Port', card='text', style='code'),
dict(key='checks', label='Checks', card='stat')] %}
{{ cards('kits', cols, items, search='Name, port, check', choices={'family': [('agent', 'Agents'), ('capability', 'Capabilities')]}, empty='No kits match.', noun='kits') }}
{% set cols = [dict(key='title', label='Name', card='title'), dict(key='family', label='Family', card='tag', class='std-tag', filter='pills'),
dict(key='port', label='Port', card='text', style='code'), dict(key='checks', label='Checks', card='stat', type='num'),
dict(key='version', label='Version', card='meta')] %}
{{ cards('kits', cols, items, search='Name, port, check', choices={'family': [('agent', 'Agents'), ('capability', 'Capabilities')]}, sort=['title', 'port', 'checks'], empty='No kits match.', noun='kits', layout='table' if request.args.get('view') == 'table' else 'cards', default='cards') }}
</div>
{% endif %}
{% endblock %}
Expand Down
15 changes: 8 additions & 7 deletions app/templates/agents/standard.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@
{% if problems %}<div class="std-problems"><strong>Not offered: a definition with problems</strong><ul>{% for p in problems %}<li>{{ p }}</li>{% endfor %}</ul></div>{% endif %}
{% if not items %}<p class="bench-none">No {{ kind }} yet.</p>{% endif %}

{#- A card's fields (web/agents.py `_card`). #}
{% set cols = [dict(key='kind', label='Kind', card='tag', class='cat-tag'), dict(key='protocol', label='Protocol', card='tag', class='std-tag'),
dict(key='example', label='Example', card='tag', class='std-tag'), dict(key='version', label='Version', card='meta'),
dict(key='icon', label='Logo', card='icon', table=false, class='std-mark small'), dict(key='title', label='Name', card='title'),
dict(key='summary', label='Summary', card='text', class='std-clamp'), dict(key='ports', label='Ports proven', card='stat'),
dict(key='runs', label='Benchmarks it runs', card='stat'), dict(key='installs', label='Installs', card='stat', class='word')] %}
{% if items %}{{ cards(plural|lower, cols, items, search='Name, protocol, summary', empty='No ' ~ kind ~ ' matches.', noun=plural|lower) }}{% endif %}
{#- A card's fields (web/agents.py `_card`); an agent's protocol and the ports it proves as dropdowns. #}
{% set cols = [dict(key='icon', label='Logo', card='icon', table=false, class='std-mark small'), dict(key='title', label='Name', card='title'),
dict(key='kind', label='Kind', card='tag', class='cat-tag'), dict(key='protocol', label='Protocol', card='tag', class='std-tag'),
dict(key='proves', label='Proves', class='std-tag', off=true), dict(key='example', label='Example', card='tag', class='std-tag', off=true),
dict(key='summary', label='Summary', card='text', class='std-clamp', width='expand', off=true), dict(key='ports', label='Ports proven', card='stat', type='num'),
dict(key='runs', label='Benchmarks it runs', card='stat', type='num'), dict(key='installs', label='Installs', card='stat', class='word'),
dict(key='version', label='Version', card='meta')] %}
{% if items %}{{ cards(plural|lower, cols, items, search='Name, protocol, summary', choices=choices, sort=['title', 'ports', 'runs'], empty='No ' ~ kind ~ ' matches.', noun=plural|lower, layout='table' if request.args.get('view') == 'table' else 'cards', default='cards') }}{% endif %}
</div>
{% endblock %}
{% block scripts %}<script src="{{ url_for('static', filename='catalogue/add.js') }}"></script>{% endblock %}
Loading
Loading