diff --git a/CHANGELOG.md b/CHANGELOG.md index 71b72e2b4..1b90c93a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,10 @@ and this project adheres to * [household] household member editor: remove markNoAddress button (champs-libres/departement-de-la-vendee/accent-suivi-developpement#109) * [person]: ordering fields in add person (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/61) * [person]: Add email and alt names in add person (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/61) +* [accompanyingCourse] Add a delete action and delete buttons to delete a accompanying course when step = DRAFT (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/64) +* [accompanyingCourse] Add a administrative location in the accompanying course, set the user current location as default, allow to select a location in a select field and do not allow to confirm the accompanying course if location is empty. +* [accompanyingCourse] Add the administrative location in the available variables for document generation + * AddAddress: optimize loading: wait for the user finish typing; * UserPicker: fix bug with deprecated role * docgen: add base context + tests diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php index 5088b2381..9abd85f64 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php @@ -19,6 +19,7 @@ use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepos use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter; use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\HttpFoundation\Exception\BadRequestException; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -110,6 +111,60 @@ class AccompanyingCourseController extends Controller ]); } + /** + * Delete page of Accompanying Course section. + * + * @Route("/{_locale}/parcours/{accompanying_period_id}/delete", name="chill_person_accompanying_course_delete") + * @ParamConverter("accompanyingCourse", options={"id": "accompanying_period_id"}) + */ + public function deleteAction(Request $request, AccompanyingPeriod $accompanyingCourse) + { + $em = $this->getDoctrine()->getManager(); + + $person_id = $request->query->get('person_id'); + + $form = $this->createFormBuilder() + ->setAction($this->generateUrl('chill_person_accompanying_course_delete', [ + 'accompanying_period_id' => $accompanyingCourse->getId(), + 'person_id' => $person_id, + ])) + ->setMethod('DELETE') + ->add('submit', SubmitType::class, ['label' => 'Delete']) + ->getForm(); + + if ($request->getMethod() === Request::METHOD_DELETE) { + $form->handleRequest($request); + + if ($form->isValid()) { + $em->remove($accompanyingCourse); + $em->flush(); + + $this->addFlash('success', $this->get('translator') + ->trans('The accompanying course has been successfully removed.')); + + if (null !== $person_id) { + return $this->redirectToRoute('chill_person_accompanying_period_list', [ + 'person_id' => $person_id, + ]); + } + + return $this->redirectToRoute('chill_main_homepage'); + } + } + + if (null !== $person_id) { + $view = '@ChillPerson/AccompanyingCourse/confirm_delete_person.html.twig'; + } else { + $view = '@ChillPerson/AccompanyingCourse/confirm_delete_accompanying_course.html.twig'; + } + + return $this->render($view, [ + 'accompanyingCourse' => $accompanyingCourse, + 'person_id' => $person_id, + 'delete_form' => $form->createView(), + ]); + } + /** * Edit page of Accompanying Course section. * @@ -208,6 +263,9 @@ class AccompanyingCourseController extends Controller } } + $userLocation = $this->getUser()->getCurrentLocation(); + $period->setAdministrativeLocation($userLocation); + $this->denyAccessUnlessGranted(AccompanyingPeriodVoter::CREATE, $period); $em->persist($period); diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index 9628da187..06e4f0c8b 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -17,6 +17,7 @@ use Chill\MainBundle\Entity\Address; use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Entity\HasCentersInterface; use Chill\MainBundle\Entity\HasScopesInterface; +use Chill\MainBundle\Entity\Location; use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Entity\User; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork; @@ -118,6 +119,13 @@ class AccompanyingPeriod implements */ private ?Address $addressLocation = null; + /** + * @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Location") + * @Groups({"read", "write"}) + * @Assert\NotBlank(groups={AccompanyingPeriod::STEP_CONFIRMED}) + */ + private ?Location $administrativeLocation = null; + /** * @var DateTime * @@ -507,6 +515,11 @@ class AccompanyingPeriod implements return $this->addressLocation; } + public function getAdministrativeLocation(): ?Location + { + return $this->administrativeLocation; + } + /** * Get a list of person which have an adresse available for a valid location. * @@ -980,6 +993,13 @@ class AccompanyingPeriod implements return $this; } + public function setAdministrativeLocation(?Location $administrativeLocation): AccompanyingPeriod + { + $this->administrativeLocation = $administrativeLocation; + + return $this; + } + /** * Set closingDate. * diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/App.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/App.vue index 30a8bbf2a..c0f279760 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/App.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/App.vue @@ -8,6 +8,7 @@ + @@ -28,6 +29,7 @@ import { mapGetters, mapState } from 'vuex' import Banner from './components/Banner.vue'; import StickyNav from './components/StickyNav.vue'; import OriginDemand from './components/OriginDemand.vue'; +import AdminLocation from './components/AdminLocation.vue'; import PersonsAssociated from './components/PersonsAssociated.vue'; import Requestor from './components/Requestor.vue'; import SocialIssue from './components/SocialIssue.vue'; @@ -44,6 +46,7 @@ export default { Banner, StickyNav, OriginDemand, + AdminLocation, PersonsAssociated, Requestor, SocialIssue, diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/AdminLocation.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/AdminLocation.vue new file mode 100644 index 000000000..201360a6e --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/AdminLocation.vue @@ -0,0 +1,103 @@ + + + + + + diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Comment.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Comment.vue index 5df43cdac..a852d71a0 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Comment.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Comment.vue @@ -1,6 +1,6 @@