Refactor filter section in question table view for improved layout, usability, and dark mode support
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
|
||||
{% extends app_name|add:'/base.html' %}
|
||||
|
||||
{% load crispy_forms_tags %}
|
||||
{% load render_table from django_tables2 %}
|
||||
{% block css %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
@@ -39,45 +36,34 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Floating filter bar (fixed at bottom) -->
|
||||
<style>
|
||||
.floating-filter {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
z-index: 1030;
|
||||
background: var(--bs-body-bg);
|
||||
border-top: 1px solid rgba(0,0,0,0.12);
|
||||
padding: 0.5rem 0.75rem;
|
||||
}
|
||||
.floating-filter .filter-body {
|
||||
max-height: 50vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
.floating-filter .filter-toggle {
|
||||
position: fixed;
|
||||
right: 1rem;
|
||||
bottom: 1rem;
|
||||
z-index: 1040;
|
||||
}
|
||||
/* minibar/tab styling - small visible handle so panel isn't fully hidden */
|
||||
.bottom-filter-minibar {
|
||||
position: fixed;
|
||||
right: 1rem;
|
||||
bottom: 1rem;
|
||||
z-index: 1045;
|
||||
background: transparent;
|
||||
}
|
||||
.bottom-filter-minibar .btn { box-shadow: 0 2px 8px rgba(0,0,0,0.15); }
|
||||
</style>
|
||||
|
||||
<!-- Minibar: small visible strip when panel is collapsed -->
|
||||
|
||||
<!-- Minibar: small visible strip when panel is collapsed -->
|
||||
<div id="bottom-filter-minibar" class="bottom-filter-minibar">
|
||||
<button class="btn btn-sm btn-outline-primary" type="button" data-bs-toggle="collapse" data-bs-target="#bottom-filter-body" aria-controls="bottom-filter-body">Filters</button>
|
||||
<div class="position-relative">
|
||||
<button class="btn btn-sm btn-outline-primary" type="button" data-bs-toggle="collapse" data-bs-target="#bottom-filter-body" aria-controls="#bottom-filter-body">
|
||||
<i class="bi bi-funnel-fill"></i> Filters
|
||||
</button>
|
||||
{# show active filters count if available via GET params #}
|
||||
{% comment %} Compute active filters count (excluding 'page') using supported template tags {% endcomment %}
|
||||
{% with request.GET|length as param_count %}
|
||||
{% if param_count > 0 %}
|
||||
{% if request.GET.page %}
|
||||
{% with param_count|add:"-1" as active_count %}
|
||||
{# active_count may be a string; only show badge when not zero #}
|
||||
{% if active_count != "0" %}
|
||||
<span class="badge bg-primary filter-count-badge">{{ active_count }}</span>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
{% else %}
|
||||
<span class="badge bg-primary filter-count-badge">{{ param_count }}</span>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button class="btn btn-primary filter-toggle d-md-none" type="button" data-bs-toggle="collapse" data-bs-target="#bottom-filter-body" aria-expanded="false" aria-controls="bottom-filter-body">Filters</button>
|
||||
<button class="btn btn-primary filter-toggle d-md-none" type="button" data-bs-toggle="collapse" data-bs-target="#bottom-filter-body" aria-expanded="false" aria-controls="#bottom-filter-body">Filters</button>
|
||||
|
||||
<div class="floating-filter shadow-lg">
|
||||
<div id="bottom-filter-body" class="collapse">
|
||||
@@ -89,28 +75,33 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- filter body collapsible so minibar stays visible -->
|
||||
<!-- filter body collapsible so minibar stays visible -->
|
||||
<div class="filter-body mt-2">
|
||||
<form action="" method="get">
|
||||
<div class="row g-2">
|
||||
<div class="row g-3">
|
||||
{% for field in filter.form.visible_fields %}
|
||||
<div class="col-12 col-sm-6 col-md-4 col-lg-3">
|
||||
<div class="form-group">
|
||||
{{ field.label_tag }}
|
||||
{{ field }}
|
||||
<div class="filter-card">
|
||||
<div class="form-group mb-1">
|
||||
{{ field.label_tag }}
|
||||
</div>
|
||||
<div class="form-group mb-1">
|
||||
{{ field }}
|
||||
</div>
|
||||
{% if field.errors %}
|
||||
<div class="invalid-feedback d-block">{{ field.errors|striptags }}</div>
|
||||
{% endif %}
|
||||
{% if field.help_text %}
|
||||
<small class="form-text text-muted">{{ field.help_text }}</small>
|
||||
<div class="filter-help">{{ field.help_text }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="mt-2 d-flex gap-2">
|
||||
<button class="btn btn-primary btn-sm" type="submit">Apply</button>
|
||||
<a class="btn btn-secondary btn-sm" href="?">Reset</a>
|
||||
<div class="mt-3 d-flex gap-2 filter-actions">
|
||||
<button class="btn btn-primary btn-sm" type="submit"><i class="bi bi-search"></i> Apply</button>
|
||||
<a class="btn btn-outline-secondary btn-sm" href="?"><i class="bi bi-arrow-counterclockwise"></i> Reset</a>
|
||||
<button class="btn btn-light btn-sm" type="button" data-bs-toggle="collapse" data-bs-target="#bottom-filter-body">Close</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@@ -118,4 +109,101 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
<!-- Floating filter bar (fixed at bottom) -->
|
||||
<style>
|
||||
.floating-filter {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
z-index: 1030;
|
||||
background: var(--bs-body-bg);
|
||||
border-top: 1px solid rgba(0,0,0,0.08);
|
||||
padding: 0.5rem 0.75rem 1rem 0.75rem;
|
||||
}
|
||||
.floating-filter .filter-body {
|
||||
max-height: 50vh;
|
||||
overflow-y: auto;
|
||||
padding-top: .5rem;
|
||||
}
|
||||
.floating-filter .filter-toggle {
|
||||
position: fixed;
|
||||
right: 1rem;
|
||||
bottom: 1rem;
|
||||
z-index: 1040;
|
||||
}
|
||||
/* minibar/tab styling - small visible handle so panel isn't fully hidden */
|
||||
.bottom-filter-minibar {
|
||||
position: fixed;
|
||||
right: 1rem;
|
||||
bottom: 1rem;
|
||||
z-index: 1045;
|
||||
background: transparent;
|
||||
}
|
||||
.bottom-filter-minibar .btn { box-shadow: 0 2px 10px rgba(0,0,0,0.12); }
|
||||
|
||||
/* pretty filter cards */
|
||||
.filter-card {
|
||||
background: var(--bs-white);
|
||||
border: 1px solid rgba(0,0,0,0.04);
|
||||
border-radius: .5rem;
|
||||
padding: .5rem;
|
||||
height: 100%;
|
||||
}
|
||||
.filter-card .form-group { margin-bottom: 0; }
|
||||
.filter-card label { font-weight: 600; font-size: .9rem; }
|
||||
.filter-help { font-size: .8rem; color: #6c757d; }
|
||||
.filter-actions { padding-top: .5rem; }
|
||||
|
||||
/* active filter count badge on minibar */
|
||||
.filter-count-badge {
|
||||
position: absolute;
|
||||
top: -6px;
|
||||
right: -6px;
|
||||
}
|
||||
|
||||
/* Dark mode overrides */
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.floating-filter {
|
||||
background: #0f1720; /* near-black */
|
||||
color: #e6eef6;
|
||||
border-top-color: rgba(255,255,255,0.06);
|
||||
}
|
||||
.bottom-filter-minibar .btn {
|
||||
background: rgba(255,255,255,0.02);
|
||||
color: #e6eef6;
|
||||
border-color: rgba(255,255,255,0.06);
|
||||
}
|
||||
.filter-card {
|
||||
background: #0b1220;
|
||||
border-color: rgba(255,255,255,0.04);
|
||||
color: #e6eef6;
|
||||
}
|
||||
/* target common form-control/form-select/select/textarea so native selects and bootstrap styles
|
||||
are overridden for dark theme inside filter cards */
|
||||
.filter-card .form-control,
|
||||
.filter-card .form-select,
|
||||
.filter-card input,
|
||||
.filter-card select,
|
||||
.filter-card textarea {
|
||||
background: #07101a !important;
|
||||
color: #f1f5f9 !important;
|
||||
border-color: rgba(255,255,255,0.06) !important;
|
||||
}
|
||||
/* options in native multi-selects */
|
||||
.filter-card select option,
|
||||
.filter-card .form-select option {
|
||||
background: #07101a !important;
|
||||
color: #f1f5f9 !important;
|
||||
}
|
||||
/* placeholder color */
|
||||
.filter-card .form-control::placeholder { color: rgba(255,255,255,0.5) !important; }
|
||||
.filter-help { color: #9fb0c7; }
|
||||
.badge.bg-primary.filter-count-badge { background: #0d6efd; color: #fff; }
|
||||
.btn-outline-secondary { color: #e6eef6; border-color: rgba(255,255,255,0.06); }
|
||||
.btn-light { background: #111827; color: #e6eef6; border-color: rgba(255,255,255,0.04); }
|
||||
.filter-card label { color: #e6eef6; }
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user