{#- Every filter at once, in a drawer the Filters button opens over the list. It is one form that applies as you pick and reloads only the table, so the list stays in view and changes as you go. On a phone it covers the screen, with a button at its foot that shows the list again. -#} {% import "adminsite/_icons.html" as icons %} {% import "adminsite/_option_count.html" as counts %} {%- set names = panels|map(attribute="filter.name")|list -%} {%- set kept = request.query_params.multi_items()|list -%} {%- set counted = panels|selectattr("counted")|list -%} {#- The counts beside the options follow the search, and come in a request of their own as the drawer opens: again only once the search has changed, so a list nobody filters never counts them. -#}
{% if counted %}{% endif %} {#- A box ticked, a shortcut picked or an end of a range typed applies the form; each of those is marked `data-applies`. The box that narrows a long list is not, nor is picking "between", which waits for its ends. A choice or a shortcut picked again lets its filter go and applies the form, a range through its hidden value, which is marked too. A record picked or let go applies it as well, and a text filter applies itself once the typing stops. -#}
{% for key, value in kept if key not in names and key not in ("page", "after", "before") %} {% endfor %}

{{ _('Filters') }}

{% for panel in panels %} {% set name = panel.filter.name %} {% set one_choice = panel.filter.template == "choice" and not panel.filter.multiple %}
{{ panel.filter.label }} {% if panel.filter.template == "choice" %} {% set kind = "radio" if one_choice else "checkbox" %} {#- A long list gets a box above it that narrows it as you type. The box has no name, so the filter never sends what was typed. -#}
{% if panel.searchable %} {% endif %}
{% for option in panel.options %} {% endfor %}
{% if panel.searchable %}

{{ _('Nothing found.') }}

{% endif %}
{% elif panel.filter.template == "range" %} {#- A shortcut, or a value at each end. What is sent is one value, the shortcut's name or the two ends joined by a comma. The shortcuts carry the filter's name, as Alpine would otherwise name every range's shortcuts alike, making them one group. -#} {% set current = panel.chosen[0] if panel.chosen else "" %} {% set presets = panel.options|map(attribute="value")|list %} {% set custom = current and current not in presets %} {% set ends = (current.split(",") if custom else []) + ["", ""] %} {% set kind = panel.filter.input_type|default("text") %}
{% if panel.options %}
{% for option in panel.options %} {% endfor %}
{% endif %}
{% elif panel.picker %} {#- The records a relation filter matches, picked by name as on a form: a box that searches them as you type, holding the ones picked as chips. -#} {%- set row = panel.picker -%} {%- set target = admin.views.for_relation(row.field) -%} {%- set things = (target.label_plural if target else row.label)|in_sentence -%} {%- set picker_multiple = panel.filter.multiple -%} {%- set picker_ordered = false -%} {%- set picker_options = none -%} {%- set picker_hint = _("Search {things}", things=things) -%} {%- set picker_search = picker_hint -%} {%- set field_attrs %}aria-label="{{ panel.filter.label }}"{% endset -%} {% include "adminsite/widgets/_picker.html" %} {% else %} {% endif %}
{% endfor %}
{% include "adminsite/_filters_footer.html" %}