{# Pivot table region — multi-dimension cross-tab. v0.59.3 (cycle 25). Consumes pivot_buckets (one row per (dim_0, dim_1, ...) combination) and pivot_dim_specs (column-header metadata: name, label, is_fk). Each row renders one combination of dimension values + measures. Strategy C aggregate primitive — Repository.aggregate runs ONE GROUP BY query, scope evaluated once, no N+1. v0.62 CSS refactor: inline Tailwind → semantic .dz-pivot-* classes. Measure cells get the .is-measure modifier so right-alignment + monospace come from the CSS rule, not duplicated utility strings. #} {% from 'macros/region_wrapper.html' import region_card %} {% from 'macros/status_badge.html' import render_status_badge %} {% call region_card(title) %}
{% if pivot_buckets %}
{% for spec in pivot_dim_specs %} {% endfor %} {% if pivot_buckets[0] %} {% for k in pivot_buckets[0].keys() %} {%- set is_dim_field = false -%} {%- for spec in pivot_dim_specs -%} {%- if k == spec.name or k == spec.name ~ '_label' -%}{%- set is_dim_field = true -%}{%- endif -%} {%- endfor -%} {%- if not is_dim_field -%} {%- endif -%} {% endfor %} {% endif %} {% for row in pivot_buckets %} {% for spec in pivot_dim_specs %} {% endfor %} {% for k, v in row.items() %} {%- set is_dim_field = false -%} {%- for spec in pivot_dim_specs -%} {%- if k == spec.name or k == spec.name ~ '_label' -%}{%- set is_dim_field = true -%}{%- endif -%} {%- endfor -%} {%- if not is_dim_field -%} {%- endif -%} {% endfor %} {% endfor %}
{{ spec.label }}{{ k.replace('_', ' ').title() }}
{% if spec.is_fk %} {%- set fk_label = row[spec.name ~ '_label'] -%} {%- if fk_label is none -%}{{ row[spec.name] or '—' }}{%- else -%}{{ fk_label }}{%- endif -%} {% else %} {%- set sval = row[spec.name] -%} {%- if sval is none -%}{%- else -%}{{ render_status_badge(value=sval, size='sm') }}{%- endif -%} {% endif %} {{ v }}

{{ pivot_buckets | length }} row{{ '' if pivot_buckets|length == 1 else 's' }}

{% else %}

{{ empty_message | default("No data to pivot.") }}

{% endif %}
{% endcall %}