Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function paginationHandler(loadPanelContent) {
container = link.closest('.fr-tabs__panel')?.querySelector('[data-url]');
}
if (!container) {
const error = "Pagination: aucun container avec data-url trouvé";
const error = 'Pagination: aucun container avec data-url trouvé';
console.error(error);
Sentry.captureException(new Error(error));
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ export default function initTabsLoader() {
}

if (err.message.includes('404')) {
loader.innerHTML =
'<div class="fr-text--error">Chargement de données impossible.</div>';
loader.innerHTML = '<div class="fr-text--error">Chargement de données impossible.</div>';
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
attacheAutocompleteAddressEvent,
initComponentAddress,
} from '../../services/component/component_search_address';
import { jsonResponseHandler } from '../../services/component/component_json_response_handler';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Plus nécessaire si on supprime la route service_secours_complete_localisation


import axios from 'axios';

attachFormServiceSecoursEvent();
Expand Down Expand Up @@ -81,6 +83,58 @@

initDesordresAutreToggle();
initUploadPhotos();
initPickLocalisationButton();
}

function initPickLocalisationButton() {
const adresseInput = document.querySelector('#service_secours_step2_adresseOccupant');
const cpInput = document.querySelector('#service_secours_step2_cpOccupant');
const pickButton = document.querySelector('.btn-pick-localisation');
const modal = document.querySelector('#fr-modal-pick-localisation');

if (!adresseInput || !cpInput || !pickButton || !modal) {
return;
}

function updatePickButton() {
const address = adresseInput.value.trim();
const postcode = cpInput.value.trim();
if (address && postcode) {
pickButton.classList.remove('fr-hidden');
modal.setAttribute('data-address', address);

Check failure on line 104 in assets/scripts/vanilla/controllers/front_service_secours/front_service_secours.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `.dataset` over `setAttribute(…)`.

See more on https://sonarcloud.io/project/issues?id=MTES-MCT_histologe&issues=AZ15Q8go44PnsT_gSVT-&open=AZ15Q8go44PnsT_gSVT-&pullRequest=5704
modal.setAttribute('data-postcode', postcode);

Check failure on line 105 in assets/scripts/vanilla/controllers/front_service_secours/front_service_secours.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `.dataset` over `setAttribute(…)`.

See more on https://sonarcloud.io/project/issues?id=MTES-MCT_histologe&issues=AZ15Q8go44PnsT_gSVT_&open=AZ15Q8go44PnsT_gSVT_&pullRequest=5704
} else {
pickButton.classList.add('fr-hidden');
}
}

adresseInput.addEventListener('input', updatePickButton);
cpInput.addEventListener('input', updatePickButton);

updatePickButton();

const submitBtn = document.getElementById('fr-modal-pick-localisation-submit');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Plus nécessaire si on supprime la route service_secours_complete_localisation

if (submitBtn) {
const form = submitBtn.form;
form.addEventListener('submit', async (event) => {
event.preventDefault();
const formData = new FormData(form);
const response = await fetch(form.action, {
method: 'POST',
body: JSON.stringify(Object.fromEntries(formData)),
headers: { 'Content-Type': 'application/json' },
});
const responseClone = response.clone();
const data = await response.json();

jsonResponseHandler(responseClone);
if (data.success) {
document.getElementById('service_secours_step2_lat').value = data.lat;
document.getElementById('service_secours_step2_lng').value = data.lng;
document.getElementById('service_secours_step2_rnbId').value = data.rnbId;
}
});
}
}

function initUploadPhotos() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function jsonResponseProcess(response) {
const openModalElement = document.querySelector('.fr-modal--opened');
if (openModalElement) {
dsfr(openModalElement).modal.conceal();
if(response.resetForm) {
if (response.resetForm) {
const formElement = openModalElement.querySelector('form');
if (formElement) {
formElement.reset();
Expand Down
77 changes: 77 additions & 0 deletions src/Controller/ServiceSecours/ServiceSecoursController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use App\Messenger\Message\SignalementServiceSecoursFileMessage;
use App\Repository\DesordreCritereRepository;
use App\Repository\SignalementRepository;
use App\Service\Gouv\Rnb\RnbService;
use App\Service\Mailer\NotificationMail;
use App\Service\Mailer\NotificationMailerRegistry;
use App\Service\Mailer\NotificationMailerType;
Expand Down Expand Up @@ -101,6 +102,82 @@
]);
}

#[Route(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Je ne comprends pas l'utilité de cette route.
L'information qu'il nous faut stoker c'est le rnbId et on le récupère directement coté JS, si cette données doit être utilisé pour faire un traitement il faut déplacer cela dans la factory.

Il me semble que ca permettrais de simplifier je met des autres com sur les élément à supprimer si on cette option.

'/services-secours/{slug:serviceSecoursRoute}/{uuid:serviceSecoursRoute}/completer/localisation',
name: 'service_secours_complete_localisation',
methods: 'POST',
defaults: ['_signed' => true]
)]
public function completeLocalisation(

Check warning on line 111 in src/Controller/ServiceSecours/ServiceSecoursController.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

This method has 4 returns, which is more than the 3 allowed.

See more on https://sonarcloud.io/project/issues?id=MTES-MCT_histologe&issues=AZ15Q8k844PnsT_gSVUA&open=AZ15Q8k844PnsT_gSVUA&pullRequest=5704
ServiceSecoursRoute $serviceSecoursRoute, // Valide la route (slug/uuid/domaine)
Request $request,
RnbService $rnbService,
): JsonResponse {
$requestData = json_decode($request->getContent(), true);
$rnbId = $requestData['rnbId'] ?? null;
$token = $requestData['_token'] ?? null;
if (!$this->isCsrfTokenValid('service_secours_set_rnb', $token)) {
$errorMsg = 'Token CSRF invalide, veuillez recharger la page';

return $this->json([
'success' => false,
'stayOnPage' => true,
'flashMessages' => [
[
'type' => 'alert',
'title' => 'Erreur',
'message' => $errorMsg,
],
],
], Response::HTTP_BAD_REQUEST);
}

if (!$rnbId) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

la partie gestion d'erreur pourrait être concaténée dans un service, non ? on a 3 fois les mêmes tests pour ça

return $this->json([
'success' => false,
'stayOnPage' => true,
'flashMessages' => [
[
'type' => 'alert',
'title' => 'Erreur',
'message' => 'RNB ID manquant ou bâtiment non trouvé.',
],
],
], Response::HTTP_BAD_REQUEST);
}

$building = $rnbService->getBuilding($rnbId);
if (!$building) {
return $this->json([
'success' => false,
'stayOnPage' => true,
'flashMessages' => [
[
'type' => 'alert',
'title' => 'Erreur',
'message' => 'Bâtiment introuvable.',
],
],
], Response::HTTP_NOT_FOUND);
}

return $this->json([
'success' => true,
'stayOnPage' => true,
'closeModal' => true,
'lat' => $building->getLat(),
'lng' => $building->getLng(),
'rnbId' => $building->getRnbId(),
'flashMessages' => [
[
'type' => 'success',
'title' => 'Succès',
'message' => 'Bâtiment sélectionné avec succès.',
],
],
]);
}

#[Route(
'/services-secours/{slug:serviceSecoursRoute}/{uuid:serviceSecoursRoute}/pdf/{uuidSignalement}',
name: 'service_secours_pdf',
Expand Down
6 changes: 6 additions & 0 deletions src/Dto/ServiceSecours/FormServiceSecoursStep2.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ class FormServiceSecoursStep2

public ?string $inseeOccupant = null;

public ?string $rnbId = null;

public ?float $lat = null;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Plus nécessaire si on supprime la route service_secours_complete_localisation


public ?float $lng = null;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Plus nécessaire si on supprime la route service_secours_complete_localisation


#[Assert\Length(max: 255, groups: ['step2'])]
public ?string $adresseAutreOccupant = null;

Expand Down
6 changes: 4 additions & 2 deletions src/Factory/SignalementServiceSecoursFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ private function handleStep2(

if (empty($formServiceSecours->step2->inseeOccupant)) {
$signalement->setManualAddressOccupant(true);
$signalement->setRnbIdOccupant($formServiceSecours->step2->rnbId)
->setGeoloc(['lat' => $formServiceSecours->step2->lat, 'lng' => $formServiceSecours->step2->lng]);
$this->signalementAddressUpdater->updateAddressOccupantFromBanData(signalement: $signalement, updateRnbId: false);
} else {
$signalement->setInseeOccupant($formServiceSecours->step2->inseeOccupant);
$this->signalementAddressUpdater->updateAddressOccupantFromBanData(signalement: $signalement);
}

$isLogementSocial = $formServiceSecours->step2->isLogementSocial;
Expand All @@ -92,8 +96,6 @@ private function handleStep2(
$signalement->setIsLogementSocial(false);
}

$this->signalementAddressUpdater->updateAddressOccupantFromBanData(signalement: $signalement);

$signalement->setTerritory(
territory: $this->zipcodeProvider->getTerritoryByInseeCode($signalement->getInseeOccupant())
);
Expand Down
9 changes: 9 additions & 0 deletions src/Form/ServiceSecours/ServiceSecoursStep2Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'data-autocomplete-insee' => 'true',
],
])
->add('rnbId', HiddenType::class, [
'required' => false,
])
->add('lat', HiddenType::class, [
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Plus nécessaire si on supprime la route service_secours_complete_localisation

'required' => false,
])
->add('lng', HiddenType::class, [
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Plus nécessaire si on supprime la route service_secours_complete_localisation

'required' => false,
])

->add('adresseAutreOccupant', TextType::class, [
'label' => 'Complément d\'adresse',
Expand Down
1 change: 1 addition & 0 deletions src/Validator/AdresseOccupant.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class AdresseOccupant extends Constraint
public string $messageVille = 'La ville est obligatoire.';
public string $messageInsee = 'Le territoire n\'est pas actif pour le code INSEE "{{ code }}".';
public string $messagePostalCode = 'Le territoire n\'est pas actif pour le code postal "{{ code }}".';
public string $messageRnbId = 'Veuillez sélectionner un bâtiment sur la carte.';

public function getTargets(): string
{
Expand Down
9 changes: 9 additions & 0 deletions src/Validator/AdresseOccupantValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@
$hasViolation = true;
}

if ($value instanceof FormServiceSecoursStep2) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

si on fait ça, il faut vérifier que l'adresse est manuelle, sinon ça bloque pour les cas simples

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

En effet ca alerte y compris en adresse automatique, je pense cependant qu'il ne faut pas du tout mettre de validation à ce niveau. Vu le peu d'élément obligatoire je ne vois pas pourquoi le rnbId le serait

if (empty($value->rnbId)) {

Check warning on line 67 in src/Validator/AdresseOccupantValidator.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Merge this if statement with the enclosing one.

See more on https://sonarcloud.io/project/issues?id=MTES-MCT_histologe&issues=AZ15Q8lW44PnsT_gSVUB&open=AZ15Q8lW44PnsT_gSVUB&pullRequest=5704
$this->context->buildViolation($constraint->messageRnbId)
->atPath('adresseCompleteOccupant')
->addViolation();
$hasViolation = true;
}
}

// S'il y a des violations, on s'arrête ici
if ($hasViolation) {
return;
Expand Down
2 changes: 2 additions & 0 deletions templates/service_secours/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<link rel="stylesheet" href="{{ asset('build/dsfr/utility/icons/icons-device/icons-device.min.css') }}">
<link rel="stylesheet" href={{ asset('build/app.css') }}>

{% block stylesheets %}{% endblock %}

{% block customscripts %}
{{ encore_entry_script_tags('app') }}
{{ encore_entry_link_tags('app') }}
Expand Down
71 changes: 70 additions & 1 deletion templates/service_secours/index.html.twig
Original file line number Diff line number Diff line change
@@ -1,10 +1,68 @@
{% extends 'service_secours/base.html.twig' %}

{% block stylesheets %}
<link rel="stylesheet" href="{{ asset('build/leaflet/leaflet.css')}}">
{% endblock %}

{% block body %}
<main class="fr-container fr-mb-5w" id="content">
{% include "flash-messages.html.twig" %}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Plus nécessaire si on supprime la route service_secours_complete_localisation

<div id="flash-messages-live-container"></div>
{% set current_step = form.vars.cursor.currentStep %}
{% if current_step == 'step2' %}
<div data-ajax-form>
<form action="{{ sign_url(path('service_secours_complete_localisation', {
'slug': 'ppp',
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

pourquoi ppp ?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ah ben ça devait être chez toi, il faudrait que tu modifies, ça ne fonctionne pas chez moi

'uuid': 'serviceSecoursRoute.uuid',
'domain': root_domain(app.request.host)
}), 3600) }}" method="POST" id="fr-modal-pick-localisation-form">

<dialog
aria-labelledby="fr-modal-pick-localisation-title"
id="fr-modal-pick-localisation"
class="fr-modal"
data-address="{{form.step2.adresseOccupant.vars.value}}"
data-postcode="{{form.step2.cpOccupant.vars.value}}"
data-loaded="false"
>
<div class="fr-container fr-container--fluid fr-container-md">
<div class="fr-grid-row fr-grid-row--center">
<div class="fr-col-12 fr-col-md-8 fr-col-lg-6">
<div class="fr-modal__body">
<div class="fr-modal__header">
<button type="button" class="fr-btn--close fr-btn" aria-controls="fr-modal-pick-localisation">Fermer</button>
</div>
<div class="fr-modal__content">
<h1 class="fr-modal__title">Sélectionner le bâtiment correspondant au logement</h1>
<div id="fr-modal-pick-localisation-message">Chargement en cours</div>
<div id="fr-modal-pick-localisation-map"></div>
</div>
<input type="hidden" name="rnbId" id="fr-modal-pick-localisation-rnb-id">
<input type="hidden" name="_token" id="fr-modal-pick-localisation-token" value="{{ csrf_token('service_secours_set_rnb') }}">
<div class="fr-modal__footer">
<ul class="fr-btns-group fr-btns-group--right fr-btns-group--inline-reverse fr-btns-group--inline-lg fr-btns-group--icon-left">
<li>
<button class="fr-btn fr-icon-check-line" id="fr-modal-pick-localisation-submit" disabled type="submit" form="fr-modal-pick-localisation-form">
Valider
</button>
</li>
<li>
<button type="button" class="fr-btn fr-btn--secondary fr-icon-close-line" aria-controls="fr-modal-pick-localisation">
Annuler
</button>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</dialog>
</form>
</div>
{% endif %}
<section class="fr-grid-row fr-grid-row--center">
<div class="fr-mt-5v fr-col-md-12">
{% set current_step = form.vars.cursor.currentStep %}
{% if current_step === 'step1' %}
{% set step_number = 1 %}
{% set step_title = 'Vos coordonnées' %}
Expand Down Expand Up @@ -76,6 +134,17 @@
{{ form_row(form.step2.cpOccupant) }}
{{ form_row(form.step2.villeOccupant) }}
{{ form_row(form.step2.inseeOccupant) }}
{{ form_widget(form.step2.rnbId) }}
{{ form_widget(form.step2.lat) }}
{{ form_widget(form.step2.lng) }}
<button
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

il manque le picto sur le bouton (il faut inclure des css dsfr, il me semble)

type="button"
class="fr-btn fr-btn--sm fr-btn--icon-left fr-icon-map-pin-2-line btn-pick-localisation fr-hidden"
data-fr-opened="false"
aria-controls="fr-modal-pick-localisation"
>
Sélectionner le bâtiment sur la carte
</button>
</div>
{{ form_row(form.step2.adresseAutreOccupant) }}
{{ form_row(form.step2.isLogementSocial, {display_mode: 'block'}) }}
Expand Down
Loading
Loading