{# Shared shadcn-style pagination bar. Usage: {% import "_pagination.html" as pagination %} {{ pagination::bar(base_path=base_path, path="failed-jobs", page=current_page_num, total_pages=total_pages, filter_args=filter_args) }} `total_pages=0` (the default) means the total is unknown (unbounded set): pass `has_next` from a peek-one-extra-row query instead, and a trailing ellipsis stands in for the unknown tail. #} {% macro num(base_path, path, p, page, filter_args="") %} {%- if p == page -%} {{ p }} {%- else -%} {{ p }} {%- endif -%} {% endmacro num %} {% macro gap() %} {% endmacro gap %} {% macro bar(base_path, path, page, total_pages=0, has_next=false, filter_args="") %} {% set win_lo = page - 1 %} {% if win_lo < 2 %}{% set win_lo = 2 %}{% endif %} {% set win_hi = page %} {% set tail_gap = false %} {% set next_ok = false %} {% if total_pages > 0 %} {% set win_hi = page + 1 %} {% if win_hi > total_pages - 1 %}{% set win_hi = total_pages - 1 %}{% endif %} {% if win_hi < total_pages - 1 %}{% set tail_gap = true %}{% endif %} {% if page < total_pages %}{% set next_ok = true %}{% endif %} {% elif has_next %} {% set win_hi = page + 1 %} {% set tail_gap = true %} {% set next_ok = true %} {% endif %}
{% if page > 1 %} Previous {% else %} Previous {% endif %} {% if next_ok %} Next {% else %} Next {% endif %}
{% endmacro bar %}