SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 0992ff6c authored by George Katsikas's avatar George Katsikas :goat:
Browse files

add clear filters button on prod stream search

parent 299b0e67
No related branches found
No related tags found
1 merge request!52New Production page fixes and oversights
......@@ -3,6 +3,7 @@ __license__ = "AGPL v3"
import datetime
from typing import Dict
from django import forms
from django.contrib.auth import get_user_model
......@@ -407,6 +408,17 @@ class ProductionStreamSearchForm(forms.Form):
),
)
def apply_filter_set(self, filters: Dict, none_on_empty: bool = False):
# Apply the filter set to the form
for key in self.fields:
if key in filters:
self.fields[key].initial = filters[key]
elif none_on_empty:
if isinstance(self.fields[key], forms.MultipleChoiceField):
self.fields[key].initial = []
else:
self.fields[key].initial = None
def search_results(self):
# Save the form data to the session
if self.session_key is not None:
......
{% load crispy_forms_tags %}
<form hx-post="{% url 'production:_hx_productionstream_list' %}"
hx-trigger="load, keyup delay:500ms, change delay:500ms, click from:#refresh-button"
hx-sync="#search-productionstreams-form:replace"
hx-target="#search-productionstreams-results"
hx-indicator="#indicator-search-productionstreams">
<div id="search-productionstreams-form">{% crispy form %}</div>
</form>
......@@ -28,8 +28,8 @@
<summary class="card-header fs-6 d-inline-flex align-items-center">
Search / Filter / Bulk Actions
<div class="d-none d-sm-inline-flex ms-auto align-items-center">
<div id="indicator-search-productionstreams" class="htmx-indicator">
<button class="btn btn-warning text-white d-none d-md-block me-2"
type="button"
disabled>
......@@ -38,10 +38,14 @@
<div class="spinner-grow spinner-grow-sm ms-2"
role="status"
aria-hidden="true"></div>
</button>
</div>
<button class="btn btn-outline-secondary me-2"
type="button"
hx-get="{% url 'production:_hx_productionstream_search_form' filter_set="empty" %}"
hx-target="#productionstream-search-form-container">Clear Filters</button>
<a id="refresh-button" class="m-2 btn btn-primary">
{% include "bi/arrow-clockwise.html" %}
&nbsp;Refresh</a>
......@@ -49,13 +53,9 @@
</summary>
<div class="card-body">
<form hx-post="{% url 'production:_hx_productionstream_list' %}"
hx-trigger="load, keyup delay:500ms, change, click from:#refresh-button"
hx-target="#search-productionstreams-results"
hx-indicator="#indicator-search-productionstreams">
<div id="search-productionstreams-form">{% crispy search_productionstreams_form %}</div>
</form>
<div id="productionstream-search-form-container">
{% include 'production/_hx_productionstream_search_form.html' with form=search_productionstreams_form %}
</div>
{% comment %} Bulk Action buttons {% endcomment %}
......
......@@ -47,6 +47,11 @@ urlpatterns = [
production_views._hx_productionstream_list,
name="_hx_productionstream_list",
),
path(
"_hx_productionstream_search_form/<str:filter_set>",
production_views._hx_productionstream_search_form,
name="_hx_productionstream_search_form",
),
path(
"_hx_productionstream_actions_bulk_assign_officers",
production_views._hx_productionstream_actions_bulk_assign_officers,
......
......@@ -1481,6 +1481,22 @@ def _hx_productionstream_summary_assignees_status(request, productionstream_id):
)
def _hx_productionstream_search_form(request, filter_set: str):
productionstream_search_form = ProductionStreamSearchForm(
user=request.user,
session_key=request.session.session_key,
)
if filter_set == "empty":
productionstream_search_form.apply_filter_set({}, none_on_empty=True)
# TODO: add more filter sets saved in the session of the user
context = {
"form": productionstream_search_form,
}
return render(request, "production/_hx_productionstream_search_form.html", context)
def _hx_event_list(request, productionstream_id):
productionstream = get_object_or_404(ProductionStream, pk=productionstream_id)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment