feat: add more infos in dashboard page (#673)

Co-authored-by: Sarahshr <sarah@les-tilleuls.coop>
This commit is contained in:
Sarahshr 2024-01-03 19:15:31 +01:00 committed by Slim
parent a664e9a9bd
commit f88fa2ef00
7 changed files with 189 additions and 2 deletions

View file

@ -11,6 +11,7 @@ App\Entity\ServiceRequest:
recipient: '@user_17' recipient: '@user_17'
startAt: '<date_create_immutable("tomorrow midnight")>' startAt: '<date_create_immutable("tomorrow midnight")>'
endAt: '<date_create_immutable("+1 week midnight")>' endAt: '<date_create_immutable("+1 week midnight")>'
createdAt: <date_create_immutable('+1 month')>
# ongoing service request, can be finalized manually # ongoing service request, can be finalized manually
# @see ServiceRequestStatusWorkflowControllerFinalizeTest # @see ServiceRequestStatusWorkflowControllerFinalizeTest

View file

@ -75,6 +75,7 @@ App\Entity\User:
address: '@address_region_hauts_de_france' address: '@address_region_hauts_de_france'
schedule: '9h30 - 17h30' schedule: '9h30 - 17h30'
phoneNumber: null phoneNumber: null
createdAt: <date_create_immutable('+1 month')>
# —— Users ————————————————————————————————————————————————————————————————— # —— Users —————————————————————————————————————————————————————————————————
# user with vacation mode # user with vacation mode
@ -111,6 +112,7 @@ App\Entity\User:
confirmationExpiresAt: <date_create_immutable('+12 hours')> confirmationExpiresAt: <date_create_immutable('+12 hours')>
firstname: <firstname()> firstname: <firstname()>
lastname: <lastname()> lastname: <lastname()>
createdAt: <date_create_immutable('-1 month')>
# user with an expired confirmation token # user with an expired confirmation token
# user with an unconfirmed email # user with an unconfirmed email

View file

@ -11,8 +11,13 @@ use App\Entity\Page;
use App\Entity\ServiceRequest; use App\Entity\ServiceRequest;
use App\Entity\User; use App\Entity\User;
use App\Entity\UserGroup; use App\Entity\UserGroup;
use App\Enum\User\UserType;
use App\Repository\GroupRepository; use App\Repository\GroupRepository;
use App\Repository\ServiceRequestRepository;
use App\Repository\UserRepository;
use App\Security\Checker\AuthorizationChecker; use App\Security\Checker\AuthorizationChecker;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\NoResultException;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard; use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem; use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
@ -55,6 +60,8 @@ final class DashboardController extends AbstractDashboardController
private readonly GroupRepository $groupRepository, private readonly GroupRepository $groupRepository,
private readonly AdminUrlGenerator $adminUrlGenerator, private readonly AdminUrlGenerator $adminUrlGenerator,
private readonly AuthorizationChecker $authorizationChecker, private readonly AuthorizationChecker $authorizationChecker,
private readonly UserRepository $userRepository,
private readonly ServiceRequestRepository $requestRepository
) { ) {
} }
@ -74,6 +81,10 @@ final class DashboardController extends AbstractDashboardController
; ;
} }
/**
* @throws NonUniqueResultException
* @throws NoResultException
*/
#[Route('/admin', name: 'admin')] #[Route('/admin', name: 'admin')]
public function index(): Response public function index(): Response
{ {
@ -87,6 +98,11 @@ final class DashboardController extends AbstractDashboardController
return $this->render('admin/dashboard.html.twig', [ return $this->render('admin/dashboard.html.twig', [
'group_count' => $this->groupRepository->count([]), 'group_count' => $this->groupRepository->count([]),
'user_count' => $this->userRepository->getUserCountByType(UserType::USER),
'place_count' => $this->userRepository->getUserCountByType(UserType::PLACE),
'month_users_count' => $this->userRepository->getNewUsersOfMonthByType(UserType::USER),
'month_places_count' => $this->userRepository->getNewUsersOfMonthByType(UserType::PLACE),
'month_requests_count' => $this->requestRepository->getNewServiceRequestsOfMonth(),
]); ]);
} }

View file

@ -10,6 +10,8 @@ use App\Entity\User;
use App\Enum\ServiceRequest\ServiceRequestStatus; use App\Enum\ServiceRequest\ServiceRequestStatus;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\NoResultException;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Doctrine\Persistence\ManagerRegistry; use Doctrine\Persistence\ManagerRegistry;
@ -126,4 +128,26 @@ final class ServiceRequestRepository extends ServiceEntityRepository
{ {
return $this->getActionSoon('endAt'); return $this->getActionSoon('endAt');
} }
/**
* @throws NonUniqueResultException
* @throws NoResultException
*/
public function getNewServiceRequestsOfMonth(): int
{
$today = new \DateTime();
/** @var int */
return $this
->createQueryBuilder('sr')
->select('COUNT(sr.id)')
->where('sr.createdAt >= :firstDay')
->andWhere('sr.createdAt <= :lastDay')
->setParameters([
'firstDay' => $today->modify('first day of this month')->format('Y-m-d'),
'lastDay' => $today->modify('last day of this month')->format('Y-m-d'),
])
->getQuery()
->getSingleScalarResult();
}
} }

View file

@ -7,6 +7,8 @@ namespace App\Repository;
use App\Entity\User; use App\Entity\User;
use App\Enum\User\UserType; use App\Enum\User\UserType;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\NoResultException;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ManagerRegistry; use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException; use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
@ -105,4 +107,44 @@ class UserRepository extends ServiceEntityRepository implements PasswordUpgrader
->orderBy('p.name', 'ASC') ->orderBy('p.name', 'ASC')
; ;
} }
/**
* @throws NonUniqueResultException
* @throws NoResultException
*/
public function getUserCountByType(UserType $type): int
{
/** @var int */
return $this
->createQueryBuilder('u')
->select('COUNT(u.id)')
->where('u.type = :type')
->setParameter('type', $type)
->getQuery()
->getSingleScalarResult();
}
/**
* @throws NonUniqueResultException
* @throws NoResultException
*/
public function getNewUsersOfMonthByType(UserType $type): int
{
$today = new \DateTime();
/** @var int */
return $this
->createQueryBuilder('u')
->select('COUNT(u.id)')
->where('u.type = :type')
->andWhere('u.createdAt >= :firstDay')
->andWhere('u.createdAt <= :lastDay')
->setParameters([
'firstDay' => $today->modify('first day of this month')->format('Y-m-d'),
'lastDay' => $today->modify('last day of this month')->format('Y-m-d'),
'type' => $type,
])
->getQuery()
->getSingleScalarResult();
}
} }

View file

@ -3,6 +3,8 @@
{% trans_default_domain 'admin' %} {% trans_default_domain 'admin' %}
{% set i18n_prefix = _self|i18n_prefix %}
{% block content_title %}Dashboard{% endblock %} {% block content_title %}Dashboard{% endblock %}
{% block page_actions %} {% block page_actions %}
@ -17,13 +19,54 @@
<table class="datagrid"> <table class="datagrid">
<thead> <thead>
<tr> <tr>
<td><b>Nombre de groupes</b></td> <td><b>{{ (i18n_prefix ~ '.group')|trans }}</b></td>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td>{{ group_count }}</td> <td>{{ (i18n_prefix ~ '.group_count')|trans({'%group_count%': group_count}) }}</td>
</tr> </tr>
</tbody> </tbody>
<thead>
<tr>
<td><b>{{ (i18n_prefix ~ '.users')|trans }}</b></td>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>{{ (i18n_prefix ~ '.month_users_count')|trans({'%month_users_count%': month_users_count}) }}</p>
<p>{{ (i18n_prefix ~ '.user_count')|trans({'%user_count%': user_count}) }}</p>
</td>
</tr>
</tbody>
<thead>
<tr>
<td><b>{{ (i18n_prefix ~ '.places')|trans }}</b></td>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>{{ (i18n_prefix ~ '.month_places_count')|trans({'%month_places_count%': month_places_count}) }}</p>
<p>{{ (i18n_prefix ~ '.place_count')|trans({'%place_count%': place_count}) }}</p>
</td>
</tr>
</tbody>
<thead>
<tr>
<td><b>{{ (i18n_prefix ~ '.loans')|trans }}</b></td>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>{{ (i18n_prefix ~ '.month_requests_count')|trans({'%month_requests_count%': month_requests_count}) }}</p>
</td>
</tr>
</tbody>
</table> </table>
{% endblock %} {% endblock %}

View file

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file source-language="en" target-language="fr" datatype="plaintext" original="file.ext">
<header>
<tool tool-id="symfony" tool-name="Symfony" />
</header>
<body>
<trans-unit id="xIbdP9t" resname="templates.admin.dashboard.group">
<source>templates.admin.dashboard.group</source>
<target>Groupes</target>
</trans-unit>
<trans-unit id="kjbR67l" resname="templates.admin.dashboard.group_count">
<source>templates.admin.dashboard.group_count</source>
<target>Nombre de groupe: %group_count%</target>
</trans-unit>
<trans-unit id="jhQrGv7" resname="templates.admin.dashboard.users">
<source>templates.admin.dashboard.users</source>
<target>Utilisateurs</target>
</trans-unit>
<trans-unit id="aml4vgY" resname="templates.admin.dashboard.month_users_count">
<source>templates.admin.dashboard.month_users_count</source>
<target>Nombre de nouveaux utilisateurs du mois: %month_users_count%</target>
</trans-unit>
<trans-unit id="xhMdko2" resname="templates.admin.dashboard.user_count">
<source>templates.admin.dashboard.user_count</source>
<target>Nombre total: %user_count%</target>
</trans-unit>
<trans-unit id="kjBr0ll" resname="templates.admin.dashboard.places">
<source>templates.admin.dashboard.places</source>
<target>Lieux</target>
</trans-unit>
<trans-unit id="hGa6vcQ" resname="templates.admin.dashboard.month_places_count">
<source>templates.admin.dashboard.month_places_count</source>
<target>Nombre de nouveaux lieux du mois: %month_places_count%</target>
</trans-unit>
<trans-unit id="om9jZug" resname="templates.admin.dashboard.place_count">
<source>templates.admin.dashboard.place_count</source>
<target>Nombre total: %place_count%</target>
</trans-unit>
<trans-unit id="xIhuGv7" resname="templates.admin.dashboard.loans">
<source>templates.admin.dashboard.loans</source>
<target>Emprunts</target>
</trans-unit>
<trans-unit id="olk9wsr" resname="templates.admin.dashboard.month_requests_count">
<source>templates.admin.dashboard.month_requests_count</source>
<target>Nombre demprunts du mois: %month_requests_count%</target>
</trans-unit>
</body>
</file>
</xliff>