diff --git a/assets/styles/histologe.scss b/assets/styles/histologe.scss index 9170363a1..7d4c1fb26 100644 --- a/assets/styles/histologe.scss +++ b/assets/styles/histologe.scss @@ -773,6 +773,10 @@ h2, h3 { } } +#tags_active_container, #tags_inactive_container{ + .fr-badge{cursor: pointer;} +} + @media (min-width: 992px) { .text-align-right--lg { diff --git a/src/Controller/Back/SignalementActionController.php b/src/Controller/Back/SignalementActionController.php index 09074f334..e890e7ef8 100755 --- a/src/Controller/Back/SignalementActionController.php +++ b/src/Controller/Back/SignalementActionController.php @@ -194,37 +194,19 @@ public function switchValue(Signalement $signalement, Request $request, EntityMa { $this->denyAccessUnlessGranted('SIGN_EDIT', $signalement); if ($this->isCsrfTokenValid('signalement_switch_value_'.$signalement->getUuid(), $request->get('_token'))) { - $return = 0; - $item = $request->get('item'); - $getMethod = 'get'.$item; - $setMethod = 'set'.$item; $value = $request->get('value'); - if ('Tag' === $item) { - $tag = $entityManager->getRepository(Tag::class)->find((int) $value); - if ($signalement->getTags()->contains($tag)) { - $signalement->removeTag($tag); - } else { - $signalement->addTag($tag); - } - } else { - if (!$value) { - $value = !(int) $signalement->$getMethod() ?? 1; - $return = 1; - } - $signalement->$setMethod($value); + $tag = $entityManager->getRepository(Tag::class)->find((int) $value); + if ($signalement->getTags()->contains($tag)) { + $signalement->removeTag($tag); + } else { + $signalement->addTag($tag); } + $entityManager->persist($signalement); $entityManager->flush(); - if ('CodeProcedure' === $item) { - $item = 'Le type de procédure'; - } - if (\is_bool($value) || 'Tag' === $item) { - return $this->json(['response' => 'success', 'return' => $return]); - } - $this->addFlash('success', $item.' a bien été enregistré !'); - return $this->redirectToRoute('back_signalement_view', ['uuid' => $signalement->getUuid()]); + return $this->json(['response' => 'success']); } return $this->json(['response' => 'error'], 400); diff --git a/templates/back/signalement/view.html.twig b/templates/back/signalement/view.html.twig index f01f6c143..c15acafd6 100755 --- a/templates/back/signalement/view.html.twig +++ b/templates/back/signalement/view.html.twig @@ -1,13 +1,7 @@ {% extends 'back/base_bo.html.twig' %} -{% set picto_yes = '

Oui

' %} -{% set picto_no = '

Non

' %} -{% set picto_nsp = '

NSP

' %} {% set static_picto_yes = '

Oui

' %} {% set static_picto_no = '

Non

' %} -{% set static_picto_nsp = '

NSP

' %} -{% set procedures = ["RSD" , "Mise en sécurité","Incurie","Insalubrité", "Décence", "ADIL"] %} - {% block content %} {% include '_partials/_modal_affectation.html.twig' %} diff --git a/tests/Functional/Controller/Back/SignalementActionControllerTest.php b/tests/Functional/Controller/Back/SignalementActionControllerTest.php index 83d86c463..aa394f3df 100644 --- a/tests/Functional/Controller/Back/SignalementActionControllerTest.php +++ b/tests/Functional/Controller/Back/SignalementActionControllerTest.php @@ -59,4 +59,47 @@ public function testDeleteSuivi(): void $this->assertStringContainsString(Suivi::DESCRIPTION_DELETED, $suivi->getDescription()); $this->assertResponseRedirects('/bo/signalements/'.$signalement->getUuid().'#suivis'); } + + public function testSwitchValue(): void + { + $signalement = $this->signalementRepository->findOneBy(['uuid' => '00000000-0000-0000-2023-000000000010']); + + $route = $this->router->generate('back_signalement_switch_value', ['uuid' => $signalement->getUuid()]); + $this->client->request('GET', $route); + + $this->client->request( + 'POST', + $route, + [ + 'value' => 1, + '_token' => $this->generateCsrfToken($this->client, 'KO'), + ] + ); + $this->assertResponseHeaderSame('Content-Type', 'application/json'); + $this->assertEquals('{"response":"error"}', $this->client->getResponse()->getContent()); + + $this->client->request( + 'POST', + $route, + [ + 'value' => 1, + '_token' => $this->generateCsrfToken($this->client, 'signalement_switch_value_'.$signalement->getUuid()), + ] + ); + $this->assertResponseHeaderSame('Content-Type', 'application/json'); + $this->assertEquals('{"response":"success"}', $this->client->getResponse()->getContent()); + + $this->client->request( + 'POST', + $route, + [ + 'value' => 3, + '_token' => $this->generateCsrfToken($this->client, 'signalement_switch_value_'.$signalement->getUuid()), + ] + ); + $this->assertResponseHeaderSame('Content-Type', 'application/json'); + $this->assertEquals('{"response":"success"}', $this->client->getResponse()->getContent()); + $this->assertEquals(1, $signalement->getTags()->count()); + $this->assertEquals(3, $signalement->getTags()->first()->getId()); + } }