{# Pieces shared by every wiki template. Import with: {% import "macros.html" as ui %} #} {# Attributes of a link that opens a page inside the content panel (htmx) and updates the URL. #} {% macro nav_url(url) -%} href="{{ url }}" hx-get="{{ url }}" hx-target="#content" hx-push-url="true" {%- endmacro %} {# The same, for the wiki page of an entity. #} {% macro nav(path) -%} {{ nav_url("/wiki/" ~ path) }} {%- endmacro %} {# Icon of an entity role: folder/file emoji for packages and modules, colored symbol for the rest. #} {% macro icon(role, symbol="") -%} {{ symbol }} {%- endmacro %} {# The one field of the wiki that picks one of many (a diagram's Focus, the ER's Focus, the Diff's trails): its name shown, its path sent (a hidden field `name`); as wide as what it holds; typing lists, under it, the options holding that text in their name or path (each with its icon, its name and its whole path, the list as wide as it needs), ↑ ↓ and Enter or a click choose; the × empties it. A choice, or the ×, sends the form (the event `picked`, see static/live.js). `options`: rows with `path`, `name`, `role` (its icon) and `symbol`; with `list` (the id of another pick_field's), its options are that one's, `options` then only naming what is chosen. `all`: a first option "All" (empty); `icon`: the chosen one's icon inside the field. #} {% macro pick_field(label, name, id, options=none, value="", placeholder="", required=false, help="", all=false, icon=false, clearable=true, list="", extra="") -%} {% set chosen = (options or []) | selectattr("path", "equalto", value) | first if value else none %} {% set shown = chosen.name if chosen else value %} {% call form_field(label, help, required=required, wide=False, extra=("pick-field " ~ extra) | trim) %} {% if icon and chosen %}{{ chosen.symbol or "" }}{% endif %} {% if clearable %}{% endif %} {% if options is not none and not list %}{% if all %}{% endif %} {% endcall %} {%- endmacro %} {# Where two sides differ, as lines (DATABASES › Diff, and an object's Declared by / Found in): `-` what only A holds, `+` what only B holds, `~` a change of the table itself, the rest the same; each marked line ends with the name of its side. `lines`: `mark` and `text` (origins.compare). #} {% macro diff_lines(lines, name_a, name_b) -%}
{% for line in lines %}{{ line.mark or " " }} {{ line.text }}{% if line.mark %}{{ {'-': name_a, '+': name_b, '~': name_a ~ ' → ' ~ name_b}[line.mark] }}{% endif %}{% endfor %}
{%- endmacro %} {# The trigger of a form holding pick_fields: what a select or a box changes, and a pick_field's choice; not a pick_field's text being typed (it waits for a choice). #} {% set pick_trigger = "change[!event.target.matches('[data-value]')], picked" %} {# Header of a section's page: its title, then, under a dividing line, what the page is for. #} {% macro view_header(view, title, text) -%} {%- endmacro %} {# Drawing area of a graph view, with its bar on top (highlight, zoom, fit); static/graph.js draws data_url with the style of `view` and selects `focus` (an entity path) when given. #} {# The legend's relation kinds, each a button that turns its lines off or on (static/graph.js). #} {% set RELATION_TIPS = { "imports": ("imports", "What a file imports"), "uses": ("uses", "Templates included, CSS classes used"), "template": ("templates", "Templates included, extended or rendered"), "css-class": ("CSS classes", "CSS classes used"), "route": ("routes", "The route a URL reaches: its handler"), "calls": ("calls", "Functions, methods, macros called"), "refers": ("refers", "Named without being called: callbacks, routes, types, tables"), "inherits": ("inherits", "A class built on another; a table taking its parent's columns (PostgreSQL's INHERITS)"), "implements": ("implements", "A class that implements an interface, a trait or a protocol"), "has": ("has", "An attribute holding another class"), "foreign-key": ("foreign key", "A column declared to hold a value of another table's key: from the column's row to the column it refers to"), "implied": ("implied", "A _id column with no foreign key declared, linked by its name to the key of a table (s): a guess, nothing enforced"), "view-reads": ("view reads", "A view reading from a table or view"), "partition-of": ("partition of", "A partition of a partitioned table"), "foreign-table": ("foreign table", "A table standing for a table of another database (postgres_fdw)"), "contained-in": ("contained in", "A column whose sampled values are, almost all, among a key column's values: found through the data, nothing declared"), } %} {# Where the first reading of the code is (DocState.progress): a bar of the whole reading, then the step and, in a step reading one thing at a time, how many of how many. It asks /progress again every half second, which answers with the same block, or reloads the page once the reading is done. #} {% macro reading_progress(progress) -%} {% set steps = progress.steps or 6 %}{% set step = progress.step or 0 %} {% set share = ((step - 1 + (progress.done / progress.total if progress.total else 0)) / steps * 100) if step else 0 %}

{% if step %}Step {{ step }} of {{ steps }} · {{ progress.title }}{% if progress.total %} · {{ progress.done }} of {{ progress.total }} {{ progress.unit }}{% endif %}{% else %}Starting…{% endif %}

{%- endmacro %} {% macro relation_kinds(kinds, off=()) -%} {% for kind in kinds %} {% endfor %} {%- endmacro %} {# An entity's page: the entity and what it relates to, a few steps away, drawn as the diagrams are. #} {% macro local_graph(path, role) -%} {% call section(role, "Local graph", name="local-graph", divider=true) %}
{# Its filter (Depth) behind the bar's Filters button, as in the diagrams. #} {% set local_filters %}
{% endset %} {# Depth 1 at first: the page's own neighbours (the diagrams start at 3). #} {% call view_canvas("local", "/graph/local?focus=" ~ (path | urlencode) ~ "&depth=1", path, layouts=true, details=true, filters=local_filters) %} this page what it uses what uses it {{ relation_kinds(("imports", "inherits", "has", "calls", "refers", "template", "css-class", "route")) }} {% endcall %}
{% endcall %} {%- endmacro %} {% macro view_canvas(view, data_url, focus="", layouts=false, evolution=false, panel="", filters="", empty="", details=false, notation=false, diff="", actions="", filters_open=false, caption="") -%} {# The side panel: the page's own (the planner's), or, with `details`, the one static/graph.js fills with the box clicked and what it relates to. #} {% set panel = panel or (('

Click a box to see what it is and what it relates to.

') | safe if details else "") %}
{# Bar on top of the drawing: highlight, then icon buttons in groups, each named by a floating label (data-tip): what opens around the drawing (filters, evolution, details); the layout (layers or forces); the colours; hide unconnected and rearrange; export (SVG or PNG) and expand, last. #}
{# What opens around the drawing, closed at first: the rows under the bar (the page's filters, then the evolution) and the details panel beside it. #} {% if filters or evolution or panel or diff %} {% if filters %}{% endif %} {% if diff %}{% endif %} {% if evolution %}{% endif %} {% if panel %}{% endif %} {% endif %} {% if layouts %} {% for name, tip in (("kind", "Colour by kind"), ("language", "Colour by language: a chip per language shows or hides it"), ("project", "Colour by project: a chip per project shows or hides it")) %} {% endfor %} {% endif %} {% if actions %}{{ actions }}{% endif %} {% if notation %}{# The ER diagram's notation: crow's foot symbols or UML multiplicities at the ends of a key's line #} {% endif %} {% if layouts %} {% endif %} {# Export, and Expand: the whole area in a modal over the page, where the same button is the × that closes it. #} {% if layouts %} {% endif %}
{% if filters %}
{{ filters }}
{% endif %} {% if diff %}
{{ diff }}
{% endif %} {% if evolution %} {# Architecture evolution: a slider through the commits; each file appears at the commit that added it (from the git log), the relations when both their files are there. While the handle is held, the commit shows under it, in the same box as the commits of the GIT page. #} {% endif %} {# The drawing, with zoom, fit and Legend floating in its top right corner: the legend opens in a box under them, as the info panel (open or closed, kept per browser). A page may give a side panel (`panel`, e.g. the planner's details): a column beside the drawing, inside its area, that the bar's button opens and closes and ⇄ moves to the other side. #}
{# closed until live.js says otherwise #}
{% if caption %}

{{ caption }}

{% endif %}{# what the drawing is of, in its top left corner #}

{{ empty or "Loading…" }}

{% if caller is defined %}{# Legend, right of Fit: its legend opens under them #} {% endif %}
{% if caller is defined %} {# The legend opens in the info panel's own box (.graph-info), in the drawing's top right corner, under its button (right of Fit); static/graph.js puts these items in it, under the same head as the info panel's. #} {% endif %}
{% if panel %} {% endif %}
{%- endmacro %} {# Collapsible section: a badge sitting on the top border; clicking the badge folds the section. kind: color of the section (an entity role or a docstring section kind). name: identifies the section (data-section); defaults to kind. divider: only the top line (entity pages) instead of a box (module pages). attrs: extra attributes of the
element (e.g. htmx loading). #} {% macro section(kind, label, count=none, name=none, divider=false, open=true, attrs="") -%} {%- set kind = kind | replace(' ', '-') -%}
{{ label }}{% if count is not none %} {{ count }}{% endif %} {{ caller() }}
{%- endmacro %} {# The earlier names of a renamed or moved entity (from the rename registry), newest first. Each commit links to the git page and shows its message on hover, in the same tooltip as the git page. #} {% macro previous_names(earlier) -%} {% macro earlier_name(entry) -%} {{ entry.path }} — {{ entry.how }} in {{ entry.short }}, {{ entry.date_local }} {%- endmacro %} {% if earlier | length == 1 %}

Previously, {{ earlier_name(earlier[0]) }}

{% elif earlier %}

Previously:

    {% for entry in earlier %}
  • {{ earlier_name(entry) }}
  • {% endfor %}
{% endif %} {%- endmacro %} {# What uses an entity and what it uses (pages.relations), the same on every page of every language. #} {% macro relations(found, role) -%} {% for side, label, empty in (("used_by", "Used by", "Nothing in the project uses it."), ("uses", "Uses", "It uses nothing else of the project.")) %} {% call section(role, label, count=found[side] | length, name=side | replace("_", "-"), divider=true) %} {% if found[side] %} {% else %}

{{ empty }}

{% endif %} {% endcall %} {% endfor %} {%- endmacro %} {# The Source block of a page: open by default, its code fetched right after the page is shown, so the page itself stays light. Changing the theme saves it to doc/config/config.json. #} {% macro source(entity, code_theme, code_themes) -%} {% set source_attrs = 'hx-get="/source/%s" hx-trigger="load" hx-target="find .code"' | format(entity.path | e) %} {% call section("source", "Source", divider=true, attrs=source_attrs) %}

Loading…

{% endcall %} {%- endmacro %} {# The modal telling that grammars could not be fetched, so those languages were left out; the same head, text and buttons as the confirmation modal. static/live.js opens it once for each list of grammars (data-key), and again when the list changes; Try again reads the code again at once. #} {% macro missing_grammars(missing, folder) -%} {% if missing %}
Grammars not fetched

doctracker could not fetch the grammar of these languages, so their files are not read yet:

    {% for item in missing %}
  • {{ item.language }}: {{ item.files }} file{{ "s" if item.files != 1 }} left out
  • {% endfor %}

Grammars are fetched once, from the internet, into {{ folder }}. Check the connection and try again; the code is also read again each time it changes.

{{ missing[0].error }}

{% endif %} {%- endmacro %} {# The notification center of the topbar: a bell with a badge holding how many notifications there are, and the list of them under it (static/live.js opens and closes it, like the search's). Each row leads to what needs attention, its kind on the left and, on the right, the button that opens it: a review its task in the Planner, missing grammars their modal. It loads itself again on every change: `docs-changed`, and `notifications-changed`, which every answer to a change made in the Planner carries (a page's own changes send it no `docs-changed`). #} {% macro notifications(items) -%}
    {% for item in items %}
  • {{ item.kind }} {{ item.text }} {% if item.url %} {% else %}{% endif %}
  • {% else %}
  • No notifications
  • {% endfor %}
{%- endmacro %} {# Tabs of a page (CODE › Diagrams): `(name, label, url)` for each; the current one is marked. #} {# The ? before a field or a name: on hover (or focus), a box explaining it in detail. #} {% macro help_hover(name, text) -%} {{ text }} {%- endmacro %} {# A field of any form of the wiki (the one way every form shows its fields): the ? explaining it, then a Material-style outlined field whose name sits on the border, with * when it is required; the control (input, select, textarea, checkbox) is given by the caller; no `help`, no ?. `choice`: the control is a toggle group of buttons, shown as they are, without the outline around them (`named`: the outline and its name kept). #} {% macro form_field(label, help, required=False, wide=True, choice=False, extra="", named=False) -%}
{% if help %}{{ help_hover(label, help) }}{% endif %} {%- if choice and named %}
{{ label }}{% if required %} *{% endif %}{{ caller() }}
{%- elif choice %}
{{ caller() }}
{%- else %}{% endif %}
{%- endmacro %} {# A list of DATABASES (Navigate › By Level, Lint; an object's page): its filters in use and how many rows, then the table, whose head stays while the rows scroll, then its pages. `name` names its parts (`-rows`, `-count`, `-pages`); `form` is the form holding what goes with every request (the tab, the filters above); `listing` what `web.list_page` gives (rows, columns, values, sort, pages, filters in use); `label` the rows counted (`3 findings`). The caller draws a cell, `caller(row, key)`, and a value of a column's filter, `caller(none, key, value)`. Without `interactive`: the table alone, no sorting, filters nor pages (an object's page). Typing in a column's filter redraws only the rows, the count and the pages, so the field keeps the cursor. #} {% macro list_table(name, form, listing, label, url="", interactive=True) -%} {%- set cell = caller -%} {%- set include = form ~ ", ." ~ name ~ "-table thead" -%}
{% if interactive %}

Selected filters: {% for field, title, shown in listing.in_use %}{{ title }}: {{ shown }} {% else %}none{% endfor %} {{ label }}

{% endif %}
{% for c in listing.columns %}{% endfor %} {% if interactive %} {# Each title sorts by its column, up then down; × beside the arrow takes the order away (the list's own order again); its right edge, dragged, sets its width. Each column with a filter has its icon: a box listing every value of the column with how many rows hold it, "(empty)" first, to tick one or more and Apply (static/live.js opens it under the icon, one at a time, and fetches its counts again each time it opens); a filter in use lights its icon. #} {% for c in listing.columns %} {% set next = "desc" if listing.sort == c.key and listing.direction != "desc" else "asc" %} {% endfor %} {% else %} {% for c in listing.columns %}{% endfor %} {% endif %} {% for row in listing.rows %} {% for c in listing.columns %}{% endfor %} {% else %} {% endfor %}
{% if c.key == "page" %}{{ c.title }}{% else %} {% endif %} {% if c.filter %}{% set picked = listing.column_filters[c.key] %} {% if listing.kept and c.key in listing.kept %}{% endif %}
{{ listing["values"][c.key] | length }} value{% if listing["values"][c.key] | length != 1 %}s{% endif %}
    {% for value, count in listing["values"][c.key] %}
  • {% endfor %}
{% endif %}
{{ c.title }}
{{ cell(row, c.key, none) }}
{% if listing.in_use %}Nothing matches these filters.{% else %}Nothing here.{% endif %}
{% if interactive %}
{% if listing.pages %}{% set p = listing.pages %} {% endif %}
{% endif %}
{%- endmacro %} {# A page button of a list (see list_table). #} {% macro list_page_button(url, include, number, label, current=false, aria="") -%} {%- endmacro %} {% macro tabs(items, current) -%} {%- endmacro %} {# The language filter of the whole wiki (static/live.js keeps it in a cookie): in the search bar and in the bar of the diagrams, always showing the languages in use. #} {% macro language_select(found, shown, languages, id="") -%} {%- endmacro %} {# DATABASES › Navigate › By Graph: the drawing static/graph.js (drawUniverse) makes of the databases read, with its filters (Depth, Outside) and its legend (the kinds' colours, the relation kinds each with a ? saying what it is, the column symbols, the mouse). In the Universe tab, and in an object's page opened on it (`focus`); there `data_url` stays empty until its section opens (static/live.js sets it). #} {% set UNIVERSE_RELATIONS = { "foreign key": "A column declared to hold a value of another table's key (its primary key or a unique column): the database refuses a value that is not there. The line goes from the column to the column it refers to.", "implied": "A column named _id with no foreign key declared, linked by its name to the one-column primary key of a table , s or es in the same database. A guess from the names: the database enforces nothing.", "view reads": "A view or materialized view reads from this table or view, as the database's own catalog records it (for SQLite, read from the view's SQL).", "foreign table": "A table that stands for a table of another database (PostgreSQL's postgres_fdw): reading it reads the other one. Linked when that database is read too.", "contained in": "A column whose sampled values are, at least 80% of them, among the values of a key column (a one-column primary key or unique column, not sensitive): found through the data, in the same database or another one, with the share found; each column only to its best key (the highest share, then the same database, then the name matching, then the smallest key). Nothing declared or enforced; a table's own primary key and the columns with a foreign key are left out.", } %} {% macro universe_canvas(focus="", data_url="/graph/universe", empty="") -%} {% set bar_filters %}
{% call form_field("Depth", "How many steps of the chosen relations are followed from what is opened: 1 shows only what it links to directly.", wide=False) %} {% endcall %} {% call form_field("Outside", "Also show the nodes outside the one opened that its relations reach (only those, never the rest of their container), drawn lighter.", wide=False) %} other schemas{% endcall %}
{% endset %} {% call view_canvas("universe", data_url, focus, filters=bar_filters, details=true, empty=empty) %}

Nodes

{% for kind in ("server", "database", "schema", "table", "view", "column") %} {{ kind }} {% endfor %} outside the one opened

Relations (click to show)

{% for kind, text in UNIVERSE_RELATIONS.items() %} {{ help_hover(kind, text) }} {% endfor %}

Column symbols

{% for mark, text in (("pk", "primary key"), ("fk", "foreign key"), ("unique", "unique"), ("index", "indexed"), ("generated", "computed by the database"), ("notnull", "not null"), ("null", "null allowed")) %} {{ text }} {% endfor %}

Click: go into it · double click, or Details › on hover: its details · the path above or ←: back · drag: the others follow

{% endcall %} {%- endmacro %} {# DATABASES › Evolution: a moment clicked, in the drawing's Details panel — a step and what each of its statements did, or a commit and the files it changed. #} {% macro evolution_moment(moment, detail) -%} {% if not moment %}

This moment is no longer there.

{% else %}

{{ "migration step" if moment.source == "migration" else "commit" }}{% if moment.changed %} · step changed after it was created{% endif %}

{{ (moment.version ~ " " ~ moment.title) if moment.source == "migration" else moment.title }}

{{ moment.origin }}

{% if moment.commit %}

Commit {{ moment.commit.short }} · {{ moment.commit.at | local_time }}
{{ moment.commit.subject }}

{% else %}

Not committed yet.

{% endif %} {% if moment.changed %}

Steps it changed

    {% for v in moment.changed %}
  • {{ v }}
  • {% endfor %}
{% endif %} {% if detail and detail.statements is defined %}

What it does {{ detail.statements | length }}

    {% for s in detail.statements %}
  • {% if s.read %}{{ s.effects | join("; ") or "nothing to record" }}{% else %}not read{% endif %} line {{ s.line }}
  • {% else %}
  • no statement
  • {% endfor %}
{% elif moment.files %}

Files {{ moment.files | length }}

    {% for path, status in moment.files.items() %}
  • {{ path }} {{ {"A": "added", "M": "changed", "D": "deleted"}.get(status, status) }}
  • {% endfor %}
{% endif %} {% endif %} {%- endmacro %} {# DATABASES › Evolution: the diff of two moments, side by side (both schemas, aligned by name) or only what differs (as the Diff's differences). #} {% macro evolution_diff(diff, a, b, view, labels) -%} {% if not a or not b %}

Choose the moments A and B (in the fields, or by clicking two moments in the drawing).

{% elif not diff %}

One of the moments cannot be read (its commit or step is no longer there).

{% else %} {% set c = diff.counts %}

A {{ labels.get(a, a) }} {{ a.rpartition("@")[0] }} → B {{ labels.get(b, b) }} {{ b.rpartition("@")[0] }} · {{ c.added }} added · {{ c.removed }} removed · {{ c.changed }} changed · {{ c.same }} the same

{% if view == "side" %} {% for t in diff.tables %} {% for col in t.columns %}{% endfor %} {% endfor %}
ObjectColumnABWhat changed
{{ t.key }} {{ t.kind }} {% if t.a %}page{% else %}-{% endif %}{% if t.b %}page{% else %}-{% endif %} {{ t.changes | join("; ") if t.changes else ("-" if t.status in ("same", "changed") else t.status) }}
{{ col.name }} {% if col.a %}{{ col.a.type or "-" }}{% if not col.a.nullable %} not null{% endif %}{% if col.a.default %} = {{ col.a.default }}{% endif %}{% else %}-{% endif %} {% if col.b %}{{ col.b.type or "-" }}{% if not col.b.nullable %} not null{% endif %}{% if col.b.default %} = {{ col.b.default }}{% endif %}{% else %}-{% endif %} {{ col.changes | join("; ") if col.changes else (col.status if col.status != "same" else "-") }}
{% else %} {% set differing = diff.tables | rejectattr("status", "equalto", "same") | list %} {% if not differing %}

No differences: the two moments have the same schema.

{% endif %} {% for t in differing %}

{{ t.status }} {% if t.b or t.a %}{{ t.key }}{% else %}{{ t.key }}{% endif %}

{% if t.status == "changed" %}
    {% for col in t.columns if col.status != "same" %}
  • column {{ col.name }} {{ col.status }}{% if col.changes %}: {{ col.changes | join("; ") }}{% endif %}
  • {% endfor %} {% for change in t.changes %}
  • {{ change }}
  • {% endfor %}
{% endif %} {% endfor %} {% endif %} {% endif %} {%- endmacro %}