feat: admin list filtering and search

This commit is contained in:
Björn Fromme
2026-08-06 10:57:36 +02:00
parent aa8fa5c1b2
commit dd658bf9d6
41 changed files with 1977 additions and 44 deletions
@@ -0,0 +1,70 @@
{#
Generic filter bar for admin list views.
Expects:
- filter: the AbstractListFilterDto the list was actually built from
- form: FormView of the entity's filter form (only `q` is rendered here)
- route: route name of the list itself
- modal_route: route name of the filter modal
#}
{% import '_partials/_query_passthrough.html.twig' as passthrough %}
{% set chips = filter.activeFilters %}
<div class="pb-4">
<div class="flex flex-wrap items-center gap-3">
{# Everything except the search term itself rides along, so searching narrows the current
filter instead of replacing it. The page is dropped on purpose: a new search starts at 1. #}
<form hx-get="{{ path(route) }}"
hx-target="body"
hx-push-url="true"
action="{{ path(route) }}"
method="get"
class="flex items-center gap-2">
{{ passthrough.render(app.request.query.all|filter((value, key) => key not in ['q', 'page', 'f'])) }}
<input type="hidden" name="f" value="1">
<div class="relative">
<input type="search"
name="q"
value="{{ filter.q }}"
placeholder="{{ form.q.vars.attr.placeholder|default('Suchen…') }}"
class="block w-64 rounded-md border-0 py-1.5 pl-9 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-inset focus:ring-primary text-sm">
<div class="absolute inset-y-0 left-0 flex items-center pl-2.5 pointer-events-none">
{{ icon('search', 'w-4 h-4 text-gray-500') }}
</div>
</div>
</form>
<button type="button"
hx-get="{{ path(modal_route, app.request.query.all) }}"
hx-target="body"
hx-swap="beforeend"
class="button button--secondary button--small inline-flex items-center gap-1.5">
{{ icon('filter', 'w-4 h-4') }}
Filter{% if filter.activeCount > 0 %} ({{ filter.activeCount }}){% endif %}
</button>
{% if filter.isActive %}
<a href="{{ path(route) }}" class="text-sm text-gray-600 underline hover:text-gray-900">
zurücksetzen
</a>
{% endif %}
</div>
{% if chips|length > 0 %}
<div class="flex flex-wrap items-center gap-2 pt-3">
{% for chip in chips %}
<span class="inline-flex items-center gap-1.5 rounded-full bg-gray-100 border border-gray-300 pl-3 {{ chip.isRemovable ? 'pr-1' : 'pr-3' }} py-1 text-xs text-gray-700">
<span><span class="font-bold">{{ chip.label }}:</span> {{ chip.value }}</span>
{% if chip.isRemovable %}
<a href="{{ path(route, filter_query_without(chip.removeKeys)) }}"
class="inline-flex items-center justify-center w-4 h-4 rounded-full hover:bg-gray-300"
aria-label="Filter „{{ chip.label }}“ entfernen">
{{ icon('close', 'w-3 h-3') }}
</a>
{% endif %}
</span>
{% endfor %}
</div>
{% endif %}
</div>
@@ -0,0 +1,17 @@
{#
Renders query parameters as hidden inputs so they survive a filter submit.
A filter form only submits its own fields, so anything else that describes the current list —
the sorting, the page size, the return URL — has to be carried along explicitly or it is lost
the moment somebody searches.
#}
{% macro render(values, prefix) %}
{%- for key, value in values -%}
{%- set name = prefix ? prefix ~ '[' ~ key ~ ']' : key -%}
{%- if value is iterable -%}
{{ _self.render(value, name) }}
{%- else -%}
<input type="hidden" name="{{ name }}" value="{{ value }}">
{%- endif -%}
{%- endfor -%}
{% endmacro %}
+45
View File
@@ -0,0 +1,45 @@
{#
Shared filter modal for admin list views.
Expects:
- form: FormView of the entity's filter form (a GET form pointing at the list route)
- route: route name of the list, used by the reset link
Entity templates extend this and override `fields` when their filters need more layout than
a plain form_rest gives them.
#}
{% extends 'htmx_modal_admin.html.twig' %}
{% form_theme form 'forms_admin.html.twig' %}
{% import '_partials/_query_passthrough.html.twig' as passthrough %}
{% block title %}Filter{% endblock %}
{% block content %}
{{ form_start(form) }}
{# Sorting, page size and the return URL are not filters, but they describe the same list. #}
{{ passthrough.render(app.request.query.all|filter((value, key) => key in ['sort', 'direction', 'limit', 'r'])) }}
{# The filter marker is a field of the form, so render it here rather than leaving it to a
form_rest() call an entity template might not make. #}
{{ form_widget(form.f) }}
<div class="grid lg:grid-cols-2 gap-y-4 lg:gap-x-8">
{% block fields %}
<div class="lg:col-span-2">
{{ form_row(form.q) }}
</div>
{{ form_row(form.dateFrom) }}
{{ form_row(form.dateTo) }}
{{ form_rest(form) }}
{% endblock %}
</div>
<div class="flex justify-between items-center pt-8">
<a href="{{ path(route) }}" class="text-sm text-gray-600 underline hover:text-gray-900">
auf Standard zurücksetzen
</a>
<button type="submit" class="button button--primary button--small">
anwenden
</button>
</div>
{{ form_end(form) }}
{% endblock %}
@@ -2,6 +2,12 @@
{% block content %}
<twig:page:heading>Buchungen & Anfragen</twig:page:heading>
{{ include('_partials/_list_filter_bar.html.twig', {
'filter': filter,
'form': filter_form,
'route': 'app_admin_accommodationbooking',
'modal_route': 'app_admin_accommodationbooking_filter',
}) }}
<div class="data-table-wrapper">
<div class="data-table-wrapper__inner text-sm">
<table class="data-table">
@@ -88,8 +94,8 @@
</tr>
{% else %}
<tr>
<td colspan="8">
Keine Daten...
<td colspan="9">
{{ filter.isActive ? 'Keine Treffer für diesen Filter.' : 'Keine Daten...' }}
</td>
</tr>
{% endfor %}
@@ -0,0 +1,27 @@
{% extends 'admin/_modal_filter.html.twig' %}
{% block fields %}
<div class="lg:col-span-2">
{{ form_row(form.q) }}
</div>
{{ form_row(form.dateFrom) }}
{{ form_row(form.dateTo) }}
{{ form_row(form.status) }}
{{ form_row(form.type) }}
<div class="lg:col-span-2">
{{ form_row(form.accommodation) }}
</div>
{# Both are group-admin only, but they appear independently: triage by "no assignment" works
even before anybody holds a groups role and there is a manager to pick. #}
{% if form.managedBy is defined %}
<div>
{{ form_row(form.managedBy) }}
</div>
{% endif %}
{% if form.unassigned is defined %}
<div class="flex items-end pb-1">
{{ form_row(form.unassigned) }}
</div>
{% endif %}
{{ form_rest(form) }}
{% endblock %}
@@ -2,6 +2,12 @@
{% block content %}
<twig:page:heading>Buchungsentwürfe</twig:page:heading>
{{ include('_partials/_list_filter_bar.html.twig', {
'filter': filter,
'form': filter_form,
'route': 'app_admin_bookingeditdraft',
'modal_route': 'app_admin_bookingeditdraft_filter',
}) }}
<div class="data-table-wrapper">
<div class="data-table-wrapper__inner text-sm">
<table class="data-table">
@@ -58,7 +64,7 @@
{% else %}
<tr>
<td colspan="5">
Keine Daten...
{{ filter.isActive ? 'Keine Treffer für diesen Filter.' : 'Keine Daten...' }}
</td>
</tr>
{% endfor %}
+8 -2
View File
@@ -2,13 +2,19 @@
{% block content %}
<twig:page:heading>Logs</twig:page:heading>
{{ include('_partials/_list_filter_bar.html.twig', {
'filter': filter,
'form': filter_form,
'route': 'app_admin_log',
'modal_route': 'app_admin_log_filter',
}) }}
<div class="data-table-wrapper">
<div class="data-table-wrapper__inner text-sm">
<table class="data-table">
<thead>
<tr>
<th>
{{ knp_pagination_sortable(pagination, 'Datum', 'log.timestamp') }}
{{ knp_pagination_sortable(pagination, 'Datum', 'log_entry.createdAt') }}
</th>
<th>
Fehlercode
@@ -62,7 +68,7 @@
{% else %}
<tr>
<td colspan="7">
Keine Daten...
{{ filter.isActive ? 'Keine Treffer für diesen Filter.' : 'Keine Daten...' }}
</td>
</tr>
{% endfor %}
+8 -2
View File
@@ -2,6 +2,12 @@
{% block content %}
<twig:page:heading>Benutzeraccounts</twig:page:heading>
{{ include('_partials/_list_filter_bar.html.twig', {
'filter': filter,
'form': filter_form,
'route': 'app_admin_user',
'modal_route': 'app_admin_user_filter',
}) }}
<div class="data-table-wrapper">
<div class="data-table-wrapper__inner text-sm">
<table class="data-table">
@@ -39,8 +45,8 @@
</tr>
{% else %}
<tr>
<td colspan="2">
Keine Daten...
<td colspan="4">
{{ filter.isActive ? 'Keine Treffer für diesen Filter.' : 'Keine Daten...' }}
</td>
</tr>
{% endfor %}