Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] [BO - Tableaux] Ajout de la possibilité de trier les tableaux #3428

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Form/SearchUserType.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'label' => false,
]);
}

$builder->add('orderType', ChoiceType::class, [
'choices' => [
'Ordre alphabétique (A -> Z)' => 'u.nom-ASC',
'Ordre alphabétique inversé (Z -> A)' => 'u.nom-DESC',
'Partenaire (A -> Z)' => 'p.nom-ASC',
'Partenaire inversé (Z -> A)' => 'p.nom-DESC',
'Connexion la plus récente' => 'u.lastLoginAt-ASC',
'Connexion la plus ancienne' => 'u.lastLoginAt-DESC',
],
'required' => false,
'label' => 'Trier par',
'data' => 'u.nom-ASC',
]);

$builder->add('page', HiddenType::class);
}

Expand Down
11 changes: 9 additions & 2 deletions src/Repository/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,15 @@ public function findFiltered(SearchUser $searchUser, $execute = true): QueryBuil
$qb->select('u', 'up', 'p', 't')
->leftJoin('u.userPartners', 'up')
->leftJoin('up.partner', 'p')
->leftJoin('p.territory', 't')
->orderBy('u.nom', 'ASC');
->leftJoin('p.territory', 't');

if (!empty($searchUser->getOrderType())) {
[$orderField, $orderDirection] = explode('-', $searchUser->getOrderType());
$qb->orderBy($orderField, $orderDirection);
} else {
$qb->orderBy('u.nom', 'ASC');
}

$qb->andWhere('u.statut != :statutArchive')->setParameter('statutArchive', User::STATUS_ARCHIVE);

$qb->andWhere('JSON_CONTAINS(u.roles, :roleUsager) = 0')->setParameter('roleUsager', '"ROLE_USAGER"');
Expand Down
11 changes: 11 additions & 0 deletions src/Service/SearchUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class SearchUser
private ?int $statut = null;
private ?string $role = null;
private ?string $permissionAffectation = null;
private ?string $orderType = null;

public function __construct(User $user)
{
Expand Down Expand Up @@ -125,6 +126,16 @@ public function setPermissionAffectation(?string $permissionAffectation): void
$this->permissionAffectation = $permissionAffectation;
}

public function getOrderType(): ?string
{
return $this->orderType;
}

public function setOrderType(?string $orderType): void
{
$this->orderType = $orderType;
}

public function getUrlParams(): array
{
$params = $this->getUrlParamsBase();
Expand Down
16 changes: 11 additions & 5 deletions templates/back/user/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
</div>
</header>
</section>

{% form_theme form 'form/dsfr_theme.html.twig' %}
{{ form_start(form) }}

<section class="fr-container--fluid overflow-visible">
{% form_theme form 'form/dsfr_theme.html.twig' %}
{{ form_start(form) }}
{{ form_errors(form) }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si on peux le standardiser juste après le {{ form_start(form) }} ca évitera de le zapper

<div class="fr-grid-row fr-grid-row--gutters">
<div class="fr-col-12 fr-col-lg-3">
Expand Down Expand Up @@ -58,10 +60,9 @@
<a href="{{ path('back_user_index') }}" class="fr-link fr-link--icon-left fr-icon-close-circle-line">Réinitialiser les résultats</a>
</div>
</div>
{{ form_end(form) }}
</section>

<section class="fr-col-12 fr-grid-row fr-grid-row--middle fr-p-5v">
<section class="fr-col-12 fr-grid-row fr-grid-row--middle fr-py-5v">
<div class="fr-col-12 fr-col-md-6">
<h2 class="fr-mb-0" id="desc-table">{{users|length}} utilisateur{% if users|length > 1%}s{% endif %}</h2>
</div>
Expand All @@ -70,6 +71,11 @@
</div>
</section>

<section class="fr-col-3 fr-pt-0">
{{ form_row(form.orderType) }}
</section>
{{ form_end(form) }}

<section class="fr-col-12 fr-pt-0 fr-px-5v">
{% set tableHead %}
{% if is_granted('ROLE_ADMIN') %}
Expand Down Expand Up @@ -157,7 +163,7 @@
{% endfor %}
{% endset %}

{% include '_partials/back/table.html.twig' with { 'tableLabel': 'Liste des utilisateurs', 'tableHead': tableHead, 'tableBody': tableBody } %}
{% include '_partials/back/table.html.twig' with { 'tableLabel': 'Liste des utilisateurs', 'tableHead': tableHead, 'tableBody': tableBody, 'cancelSortable': true } %}

<div class="fr-grid-row fr-mt-2v fr-grid-row--center">
{% import '_partials/macros.html.twig' as macros %}
Expand Down
Loading