Skip to content

Commit

Permalink
feat: update employee record list filters ui
Browse files Browse the repository at this point in the history
  • Loading branch information
hellodeloo committed May 15, 2024
1 parent e871d52 commit 641cbb5
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% load str_filters %}

<div class="ms-md-auto" id="employee-record-filter-counter"{% if request.htmx %} hx-swap-oob="true"{% endif %}>
{% if filters_counter > 0 %}
<a href="{% url 'employee_record_views:list' %}"
class="btn btn-ico btn-dropdown-filter"
aria-label="Réinitialiser le{{ filters_counter|pluralizefr }} filtre{{ filters_counter|pluralizefr }} actif{{ filters_counter|pluralizefr }}">
<i class="ri-eraser-line font-weight-bold" aria-hidden="true"></i>
<span>Effacer tout</span>
</a>
{% endif %}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% load list_filters %}

<div id="employee-records-list-filters" {% if request.htmx %}hx-swap-oob="true"{% endif %}>
<div class="dropdown">
<button type="button" class="btn btn-dropdown-filter dropdown-toggle" data-bs-toggle="dropdown" data-bs-auto-close="outside" aria-expanded="false">
Statut
</button>
<ul class="dropdown-menu">
{% for choice, badge in form.status|zip:badges %}
<li>
<div class="dropdown-item">
<div class="form-check">
<input class="form-check-input" type="radio" name="{{ choice.data.name }}" id="{{ choice.id_for_label }}" value="{{ choice.data.value }}"{% if choice.data.selected %} checked="checked"{% endif %}>
<label class="form-check-label" for="{{ choice.id_for_label }}">
{{ choice.data.label }}
{% if badge.0 > 0 %}<span class="badge rounded-pill badge-xs {{ badge.1 }}">{{ badge.0 }}</span>{% endif %}
</label>
</div>
</div>
</li>
{% endfor %}
</ul>
</div>
</div>
7 changes: 7 additions & 0 deletions itou/templates/employee_record/includes/list_counter.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% load str_filters %}

{% with navigation_pages.paginator.count as counter %}
<h3 class="h4 m-0 me-auto" id="employee-record-list-count"{% if request.htmx %} hx-swap-oob="true"{% endif %}>
{{ counter }} résultat{{ counter|pluralizefr }}
</h3>
{% endwith %}
21 changes: 0 additions & 21 deletions itou/templates/employee_record/includes/list_form_fields.html

This file was deleted.

26 changes: 5 additions & 21 deletions itou/templates/employee_record/includes/list_results.html
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
{% load django_bootstrap5 %}
{% load str_filters %}

<div id="employee-records-container">
<div class="d-flex align-items-center">
<div class="flex-grow-1">
{% with navigation_pages.paginator.count as counter %}
<h3 class="h4 m-0">{{ counter }} résultat{{ counter|pluralizefr }}</h3>
{% endwith %}
</div>
<div>
<span class="fs-sm">Trier par :</span>
<button type="button" class="btn btn-sm btn-link dropdown-toggle p-0" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ ordered_by_label }}
</button>
<div class="dropdown-menu dropdown-menu-end" id="order-form-group">
{% for order_value, order_label in form.order.field.choices %}
<button class="dropdown-item {% if order_value == form.order.value %}active{% endif %}" type="button" value="{{ order_value }}">
{{ order_label }}
</button>
{% endfor %}
</div>
</div>
</div>
{# "Real" employee records objects #}
<div class="employee-records-list">
{% if employee_records_list %}
Expand All @@ -42,7 +24,9 @@ <h3 class="h4 m-0">{{ counter }} résultat{{ counter|pluralizefr }}</h3>
{% endif %}
{% include "includes/pagination.html" with page=navigation_pages boost=True boost_target="#employee-records-container" boost_indicator="#employee-records-container" %}
</div>

{% if request.htmx %}
{% include "employee_record/includes/list_status_help.html" with request=request status=form.status.value only %}
{% include "employee_record/includes/list_form_fields.html" %}
{% include "employee_record/includes/list_counter.html" %}
{% include "employee_record/includes/employee_record_filters/reset.html" %}
{% endif %}
13 changes: 13 additions & 0 deletions itou/templates/employee_record/includes/list_sort.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div>
<span class="fs-sm">Trier par :</span>
<button type="button" class="btn btn-sm btn-link dropdown-toggle p-0" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ ordered_by_label }}
</button>
<div class="dropdown-menu dropdown-menu-end" id="order-form-group">
{% for order_value, order_label in form.order.field.choices %}
<button class="dropdown-item {% if order_value == form.order.value %}active{% endif %}" type="button" value="{{ order_value }}">
{{ order_label }}
</button>
{% endfor %}
</div>
</div>
42 changes: 28 additions & 14 deletions itou/templates/employee_record/list.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% extends "layout/base.html" %}
{% load django_bootstrap5 %}
{% load static %}

{% block title %}Fiches salarié ASP - {{ request.current_organization.display_name }} {{ block.super }}{% endblock %}
Expand Down Expand Up @@ -56,22 +57,34 @@ <h2 class="h3">Nous transférons vos fiches salarié à l'ASP afin de vous faire
</div>
</div>
<div class="row">
<div class="col-12 col-md-4 mb-3 mb-md-5">
<aside class="c-aside-filters">
<button class="c-aside-filters__btn__collapse" data-bs-toggle="collapse" data-bs-target="#asideFiltersCollapse" aria-expanded="true" aria-controls="asideFiltersCollapse">
<i class="ri-filter-line" aria-hidden="true"></i>
<span>Filtres des fiches salarié</span>
</button>
<div class="c-aside-filters__card collapse show" id="asideFiltersCollapse">
<form hx-get="{% url 'employee_record_views:list' %}" hx-trigger="change delay:.5s" hx-indicator="#employee-records-container" hx-target="#employee-records-container" hx-swap="outerHTML" hx-push-url="true">
{% include "employee_record/includes/list_form_fields.html" %}
{# Filled via jQuery. Does not need reloading with HTMX, its content is static. #}
{{ form.order.as_hidden }}
</form>
<div class="col-12">
<form hx-get="{% url 'employee_record_views:list' %}"
hx-trigger="change delay:.5s, change from:#id_job_seekers"
hx-indicator="#employee-records-container"
hx-target="#employee-records-container"
hx-swap="outerHTML"
hx-push-url="true"
hx-include="#id_job_seekers">
<div class="btn-dropdown-filter-group mb-3 mb-md-4">
{% include "employee_record/includes/employee_record_filters/status.html" %}
{% include "employee_record/includes/employee_record_filters/reset.html" %}
</div>
</aside>
{# Filled via jQuery. Does not need reloading with HTMX, its content is static. #}
{{ form.order.as_hidden }}
</form>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="d-flex flex-column flex-md-row align-items-md-center mb-3 mb-md-4">
{% include "employee_record/includes/list_counter.html" %}
{% include "employee_record/includes/list_sort.html" %}
<div class="flex-column flex-md-row mt-3 mt-md-0 ms-md-3">
{% bootstrap_field filters_form.job_seekers layout="inline" %}
</div>
</div>
{% include "employee_record/includes/list_results.html" %}
</div>
<div class="col-12 col-md-8">{% include "employee_record/includes/list_results.html" %}</div>
</div>
</div>
</section>
Expand All @@ -80,6 +93,7 @@ <h2 class="h3">Nous transférons vos fiches salarié à l'ASP afin de vous faire
{% block script %}
{{ block.super }}
<script src='{% static "js/htmx_compat.js" %}'></script>
<script src='{% static "js/htmx_dropdown_filter.js" %}'></script>
<!-- Needed to use Select2MultipleWidget. -->
{{ filters_form.media.js }}
<script nonce="{{ CSP_NONCE }}">
Expand Down
6 changes: 3 additions & 3 deletions itou/utils/staticfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,11 @@
},
"theme-inclusion": {
"download": {
"url": "https://github.com/gip-inclusion/itou-theme/archive/refs/tags/v1.6.2.zip",
"sha256": "cd7b3bb1d9d2d517be5a40b386ea1a05c96be2e5558de716e7629289b7a8c443",
"url": "https://github.com/gip-inclusion/itou-theme/archive/refs/tags/v1.6.4.zip",
"sha256": "8124863139ebb3646a59235bb1e0b171fec1af9b26d15108b03511c4b73df1b7",
},
"extract": {
"origin": "itou-theme-1.6.2/dist",
"origin": "itou-theme-1.6.4/dist",
"destination": "vendor/theme-inclusion/",
"files": [
"javascripts/app.js",
Expand Down
11 changes: 9 additions & 2 deletions itou/www/employee_record_views/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,19 @@ class SelectEmployeeRecordStatusForm(forms.Form):
required=False,
)

def get_filters_counter(self):
return len(self.data)


class EmployeeRecordFilterForm(forms.Form):
job_seekers = forms.MultipleChoiceField(
required=False,
label="Nom du candidat",
widget=Select2MultipleWidget,
label="Nom du salarié",
widget=Select2MultipleWidget(
attrs={
"data-placeholder": "Nom du salarié",
}
),
)

def __init__(self, job_seekers, *args, **kwargs):
Expand Down
11 changes: 6 additions & 5 deletions itou/www/employee_record_views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,11 @@ def list_employee_records(request, template_name="employee_record/list.html"):
len(eligible_job_applications) if status == Status.NEW else eligible_job_applications.count(),
"bg-info",
),
(employee_record_badges.get(Status.READY, 0), "bg-secondary"),
(employee_record_badges.get(Status.SENT, 0), "bg-warning"),
(employee_record_badges.get(Status.REJECTED, 0), "bg-danger"),
(employee_record_badges.get(Status.PROCESSED, 0), "bg-success"),
(employee_record_badges.get(Status.DISABLED, 0), "bg-emploi-lightest text-primary"),
(employee_record_badges.get(Status.READY, 0), "bg-emploi-lightest text-info"),
(employee_record_badges.get(Status.SENT, 0), "bg-emploi-lightest text-info"),
(employee_record_badges.get(Status.REJECTED, 0), "bg-warning"),
(employee_record_badges.get(Status.PROCESSED, 0), "bg-emploi-lightest text-info"),
(employee_record_badges.get(Status.DISABLED, 0), "bg-emploi-lightest text-info"),
]

# Employee records are created with a job application object.
Expand Down Expand Up @@ -251,6 +251,7 @@ def list_employee_records(request, template_name="employee_record/list.html"):
"need_manual_regularization": need_manual_regularization,
"ordered_by_label": order_by.label,
"matomo_custom_title": "Fiches salarié ASP",
"filters_counter": form.get_filters_counter(),
"back_url": reverse("dashboard:index"),
}

Expand Down
4 changes: 2 additions & 2 deletions tests/www/employee_record_views/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ def test_htmx(self):
[new_status] = simulated_page.find_all("input", attrs={"name": "status", "value": "NEW"})
del new_status["checked"]
[ready_status] = simulated_page.find_all("input", attrs={"name": "status", "value": "READY"})
ready_status["checked"] = ""
ready_status["checked"] = "checked"

response = self.client.get(self.URL, {"status": "READY"}, headers={"HX-Request": "true"})
update_page_with_htmx(simulated_page, f"form[hx-get='{self.URL}']", response)
Expand All @@ -516,7 +516,7 @@ def test_htmx_new_employee_record_updates_badge_count(self):
[new_status] = simulated_page.find_all("input", attrs={"name": "status", "value": "NEW"})
del new_status["checked"]
[ready_status] = simulated_page.find_all("input", attrs={"name": "status", "value": "READY"})
ready_status["checked"] = ""
ready_status["checked"] = "checked"

response = self.client.get(self.URL, {"status": "READY"}, headers={"HX-Request": "true"})
update_page_with_htmx(simulated_page, f"form[hx-get='{self.URL}']", response)
Expand Down

0 comments on commit 641cbb5

Please sign in to comment.