Skip to content

Commit

Permalink
Merge pull request #2408 from MTES-MCT/feature/2117-refonte-liste-sig…
Browse files Browse the repository at this point in the history
…nalement

[BO - Liste signalement][Back] Gestion liste et filtre existants signalements sous format JSON
  • Loading branch information
numew committed Apr 5, 2024
2 parents 0800d68 + ba8e3bc commit aa95965
Show file tree
Hide file tree
Showing 16 changed files with 441 additions and 90 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ MAINTENANCE_BANNER_ENABLE=0
MAINTENANCE_BANNER_MESSAGE="Une opération de maintenance est prévu le XX/XX/XXXX à XX:XX. Le site sera indisponible pendant la durée de l'opération."
AXIOS_TIMEOUT=30000
LIMIT_DAILY_RELANCES_BY_REQUEST=275
FEATURE_LIST_FILTER_ENABLE=0
### histologe ###

### object storage S3 ###
Expand Down
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ MAINTENANCE_BANNER_ENABLE=0
MAINTENANCE_BANNER_MESSAGE="Une opération de maintenance est prévu le XX/XX/XXXX à XX:XX. Le site sera indisponible pendant la durée de l'opération."
AXIOS_TIMEOUT=30000
LIMIT_DAILY_RELANCES_BY_REQUEST=275
FEATURE_LIST_FILTER_ENABLE=0

###> knplabs/knp-snappy-bundle ###
WKHTMLTOPDF_PATH=wkhtmltopdf
Expand Down
33 changes: 33 additions & 0 deletions migrations/Version20240402090719.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20240402090719 extends AbstractMigration
{
public function getDescription(): string
{
return 'Update some signalements with is_allocataire from 0 or 1 to Oui or Non';
}

public function up(Schema $schema): void
{
$this->addSql(
'UPDATE signalement SET is_allocataire = 0 WHERE is_allocataire LIKE :allocataire_non',
['allocataire_non' => 'Non']
);

$this->addSql(
'UPDATE signalement SET is_allocataire = 1 WHERE is_allocataire LIKE :allocataire_oui',
['allocataire_oui' => 'Oui']
);
}

public function down(Schema $schema): void
{
}
}
39 changes: 39 additions & 0 deletions migrations/Version20240402091719.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use App\Entity\Enum\ProfileDeclarant;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20240402091719 extends AbstractMigration
{
public function getDescription(): string
{
return 'Update profile declarant to legacy signalement';
}

public function up(Schema $schema): void
{
$this->addSql(
'UPDATE signalement SET profile_declarant = :profile_locataire WHERE created_from_id IS NULL AND is_not_occupant = 0',
['profile_locataire' => ProfileDeclarant::LOCATAIRE->value]
);

$this->addSql(
'UPDATE signalement SET profile_declarant = :profile_tiers_pro WHERE created_from_id IS NULL AND is_not_occupant = 1 AND lien_declarant_occupant IN (\'PROFESSIONNEL\', \'pro\', \'assistante sociale\', \'curatrice\')',
['profile_tiers_pro' => ProfileDeclarant::TIERS_PRO->value]
);

$this->addSql(
'UPDATE signalement SET profile_declarant = :profile_tiers_particulier WHERE created_from_id IS NULL AND is_not_occupant = 1 AND lien_declarant_occupant NOT IN (\'PROFESSIONNEL\', \'pro\', \'assistante sociale\', \'curatrice\')',
['profile_tiers_particulier' => ProfileDeclarant::TIERS_PARTICULIER->value]
);
}

public function down(Schema $schema): void
{
}
}
8 changes: 4 additions & 4 deletions src/Controller/Back/CartographieController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use App\Repository\CritereRepository;
use App\Repository\SignalementRepository;
use App\Repository\TagRepository;
use App\Service\SearchFilterService;
use App\Service\Signalement\SearchFilter;
use App\Service\Signalement\SearchFilterOptionDataProvider;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -17,7 +17,7 @@
class CartographieController extends AbstractController
{
public function __construct(
private SearchFilterService $searchFilterService,
private SearchFilter $searchFilter,
private SearchFilterOptionDataProvider $searchFilterOptionDataProvider
) {
}
Expand All @@ -30,8 +30,8 @@ public function index(
CritereRepository $critereRepository,
): Response {
$title = 'Cartographie';
$filters = $this->searchFilterService->setRequest($request)->setFilters()->getFilters();
$countActiveFilters = $this->searchFilterService->getCountActive();
$filters = $this->searchFilter->setRequest($request)->setFilters()->getFilters();
$countActiveFilters = $this->searchFilter->getCountActive();

/** @var User $user */
$user = $this->getUser();
Expand Down
28 changes: 24 additions & 4 deletions src/Controller/Back/SignalementListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@

namespace App\Controller\Back;

use App\Dto\Request\Signalement\SignalementSearchQuery;
use App\Entity\User;
use App\Manager\SignalementManager;
use App\Service\SearchFilterService;
use App\Service\Signalement\SearchFilter;
use App\Service\Signalement\SearchFilterOptionDataProvider;
use Psr\Cache\InvalidArgumentException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\MapQueryString;
use Symfony\Component\Routing\Annotation\Route;

#[Route('/bo')]
Expand All @@ -22,12 +25,12 @@ class SignalementListController extends AbstractController
#[Route('/signalements/', name: 'back_index')]
public function index(
Request $request,
SearchFilterService $searchFilterService,
SearchFilter $searchFilter,
SearchFilterOptionDataProvider $searchFilterOptionDataProvider,
SignalementManager $signalementManager,
ParameterBagInterface $parameterBag,
): Response {
$filters = $searchFilterService->setRequest($request)->setFilters()->getFilters();
$filters = $searchFilter->setRequest($request)->setFilters()->getFilters();
$request->getSession()->set('filters', $filters);
/** @var User $user */
$user = $this->getUser();
Expand All @@ -43,9 +46,26 @@ public function index(
return $this->render('back/index.html.twig', [
'filters' => $filters,
'filtersOptionData' => $searchFilterOptionDataProvider->getData($user),
'countActiveFilters' => $searchFilterService->getCountActive(),
'countActiveFilters' => $searchFilter->getCountActive(),
'displayRefreshAll' => true,
'signalements' => $signalements,
]);
}

#[Route('/list/signalements/', name: 'back_signalement_list_json')]
public function list(
SignalementManager $signalementManager,
SearchFilter $searchFilter,
#[MapQueryString] ?SignalementSearchQuery $signalementQuery = null,
): JsonResponse {
/** @var User $user */
$user = $this->getUser();
$filters = null !== $signalementQuery
? $searchFilter->setRequest($signalementQuery)->buildFilters()
: ['maxItemsPerPage' => SignalementSearchQuery::MAX_LIST_PAGINATION];

$signalements = $signalementManager->findSignalementAffectationList($user, $filters);

return $this->json($signalements);
}
}
187 changes: 187 additions & 0 deletions src/Dto/Request/Signalement/SignalementSearchQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
<?php

namespace App\Dto\Request\Signalement;

use App\Entity\Enum\SignalementStatus;
use Symfony\Component\Validator\Constraints as Assert;

class SignalementSearchQuery
{
public const MAX_LIST_PAGINATION = 25;

public function __construct(
private readonly ?string $territory = null,
private readonly ?string $searchTerms = null,
#[Assert\Choice(['nouveau', 'en cours', 'ferme', 'refuse'])]
private readonly ?string $status = null,
private readonly ?string $commune = null,
private readonly ?array $etiquettes = null,
#[Assert\Date(message: 'La date de début n\'est pas une date valide')]
private readonly ?string $dateDepotDebut = null,
#[Assert\Date(message: 'La date de fin n\'est pas une date valide')]
private readonly ?string $dateDepotFin = null,
private readonly ?array $partenaires = null,
#[Assert\Choice(['Non planifiée', 'Planifiée', 'Conclusion à renseigner', 'Terminée'])]
private readonly ?string $visiteStatus = null,
private readonly ?string $typeDernierSuivi = null,
private readonly ?string $statusAffectations = null,
#[Assert\GreaterThanOrEqual(0)]
private readonly ?float $criticiteScoreMin = null,
#[Assert\LessThanOrEqual(100)]
private readonly ?float $criticiteScoreMax = null,
#[Assert\Choice(['locataire', 'bailleur_occupant', 'tiers_particulier', 'tiers_pro', 'service_secours', 'bailleur'])]
private readonly ?string $typeDeclarant = null,
#[Assert\Choice(['privee', 'public'])]
private readonly ?string $natureParc = null,
#[Assert\Choice(['caf', 'msa', 'non', 'oui'])]
private readonly ?string $allocataire = null,
private readonly ?bool $enfantsM6 = null,
private readonly ?string $situation = null,
private readonly ?int $page = 1,
#[Assert\Choice(['reference', 'nomOccupant', 'createdAt'])]
private readonly string $sortBy = 'reference',
private readonly string $orderBy = 'DESC',
) {
}

public function getTerritory(): ?string
{
return $this->territory;
}

public function getSearchTerms(): ?string
{
return $this->searchTerms;
}

public function getStatus(): ?string
{
return $this->status;
}

public function getCommune(): ?string
{
return $this->commune;
}

public function getEtiquettes(): ?array
{
return $this->etiquettes;
}

public function getDateDepotDebut(): ?string
{
return $this->dateDepotDebut;
}

public function getDateDepotFin(): ?string
{
return $this->dateDepotFin;
}

public function getPartenaires(): ?array
{
return $this->partenaires;
}

public function getVisiteStatus(): ?string
{
return $this->visiteStatus;
}

public function getTypeDernierSuivi(): ?string
{
return $this->typeDernierSuivi;
}

public function getStatusAffectations(): ?string
{
return $this->statusAffectations;
}

public function getCriticiteScoreMin(): ?float
{
return $this->criticiteScoreMin;
}

public function getCriticiteScoreMax(): ?float
{
return $this->criticiteScoreMax;
}

public function getTypeDeclarant(): ?string
{
return !empty($this->typeDeclarant) ? strtoupper($this->typeDeclarant) : null;
}

public function getNatureParc(): ?string
{
return $this->natureParc;
}

public function getAllocataire(): ?string
{
return !empty($this->allocataire) ? strtoupper($this->allocataire) : null;
}

public function getEnfantsM6(): ?bool
{
return $this->enfantsM6;
}

public function getSituation(): ?string
{
return $this->situation;
}

public function getPage(): ?int
{
return $this->page;
}

public function getSortBy(): string
{
return $this->sortBy;
}

public function getOrderBy(): string
{
return $this->orderBy;
}

public function getFilters(): array
{
$filters = [];
$filters['searchterms'] = $this->getSearchTerms() ?? null;
$filters['territories'] = $this->getTerritory() ?? null;
$filters['statuses'] = null !== $this->getStatus()
? [SignalementStatus::mapFilterStatus($this->getStatus())]
: null;
$filters['cities'] = null !== $this->getCommune() ? [$this->getCommune()] : null;
$filters['partners'] = $this->getPartenaires() ?? null;
$filters['allocs'] = null !== $this->getAllocataire() ? [$this->getAllocataire()] : null;
$filters['housetypes'] = null !== $this->getNatureParc() ? ['public' === $this->getNatureParc()] : null;
$filters['enfantsM6'] = null !== $this->getEnfantsM6() ? [$this->getEnfantsM6()] : null;
$filters['visites'] = null !== $this->getVisiteStatus() ? [$this->getVisiteStatus()] : null;
if (null !== $this->getCriticiteScoreMin() || null !== $this->getCriticiteScoreMax()) {
$filters['scores'] = [
'on' => $this->getCriticiteScoreMin() ?? 0,
'off' => $this->getCriticiteScoreMax() ?? 100,
];
}
if (null !== $this->getDateDepotDebut() && null !== $this->getDateDepotFin()) {
$filters['dates'] = [
'on' => $this->getDateDepotDebut(),
'off' => $this->getDateDepotFin(),
];
}
$filters['tags'] = $this->getEtiquettes() ?? null;
$filters['typeDeclarant'] = $this->getTypeDeclarant();
$filters['page'] = $this->getPage() ?? 1;
$filters['maxItemsPerPage'] = self::MAX_LIST_PAGINATION;
$filters['sortBy'] = $this->getSortBy() ?? 'reference';
$filters['orderBy'] = $this->getOrderBy() ?? 'DESC';

return array_filter($filters);
}
}
13 changes: 13 additions & 0 deletions src/Dto/SignalementAffectationListView.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function __construct(
private ?array $affectations = null,
private ?array $qualifications = null,
private ?array $qualificationsStatuses = null,
private ?string $csrfToken = null,
) {
}

Expand Down Expand Up @@ -137,4 +138,16 @@ public function getQualificationsStatusesLabels(): array

return $listLabels;
}

public function getCsrfToken(): ?string
{
return $this->csrfToken;
}

public function setCsrfToken(string $csrfToken): self
{
$this->csrfToken = $csrfToken;

return $this;
}
}
Loading

0 comments on commit aa95965

Please sign in to comment.