From 7dcd5be7358b6e42d76dd0d295794c5084c3ac16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 23 May 2022 17:30:40 +0200 Subject: [PATCH] fixes for editing calendar --- .../views/Activity/concernedGroups.html.twig | 6 ++--- .../Controller/CalendarController.php | 19 +++++----------- .../ChillCalendarBundle/Entity/Calendar.php | 12 +++++++++- .../public/vuejs/Calendar/store/utils.js | 22 +++++++++++++++++-- .../listByAccompanyingCourse.html.twig | 10 ++------- 5 files changed, 42 insertions(+), 27 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Resources/views/Activity/concernedGroups.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/Activity/concernedGroups.html.twig index d9d72845a..8e1d8c713 100644 --- a/src/Bundle/ChillActivityBundle/Resources/views/Activity/concernedGroups.html.twig +++ b/src/Bundle/ChillActivityBundle/Resources/views/Activity/concernedGroups.html.twig @@ -18,7 +18,7 @@ {% endmacro %} {% set blocks = [] %} -{% if entity.activityType.personsVisible %} +{% if context == 'calendar_accompanyingCourse' or entity.activityType.personsVisible %} {% if context == 'person' %} {% set blocks = blocks|merge([{ 'title': 'Others persons'|trans, @@ -43,7 +43,7 @@ }]) %} {% endif %} {% endif %} -{% if entity.activityType.thirdPartiesVisible %} +{% if context == 'calendar_accompanyingCourse' or entity.activityType.thirdPartiesVisible %} {% set blocks = blocks|merge([{ 'title': 'Third parties'|trans, 'items': entity.thirdParties, @@ -52,7 +52,7 @@ 'key' : 'id', }]) %} {% endif %} -{% if entity.activityType.usersVisible %} +{% if context == 'calendar_accompanyingCourse' or entity.activityType.usersVisible %} {% set blocks = blocks|merge([{ 'title': 'Users concerned'|trans, 'items': entity.users, diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php index 5f9f8cd1d..f64a7a6bc 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php @@ -137,7 +137,7 @@ class CalendarController extends AbstractController * * @Route("/{_locale}/calendar/calendar/{id}/edit", name="chill_calendar_calendar_edit") */ - public function editAction(int $id, Request $request): Response + public function editAction(Calendar $entity, Request $request): Response { $view = null; $em = $this->getDoctrine()->getManager(); @@ -147,21 +147,14 @@ class CalendarController extends AbstractController if ($accompanyingPeriod instanceof AccompanyingPeriod) { $view = '@ChillCalendar/Calendar/editByAccompanyingCourse.html.twig'; } elseif ($user instanceof User) { + throw new Exception('to analyze'); $view = '@ChillCalendar/Calendar/editByUser.html.twig'; } - $entity = $em->getRepository(\Chill\CalendarBundle\Entity\Calendar::class)->find($id); - - if (!$entity) { - throw $this->createNotFoundException('Unable to find Calendar entity.'); - } - - $form = $this->createForm(CalendarType::class, $entity, [ - 'accompanyingPeriod' => $accompanyingPeriod, - ])->handleRequest($request); + $form = $this->createForm(CalendarType::class, $entity); + $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $em->persist($entity); $em->flush(); $this->addFlash('success', $this->get('translator')->trans('Success : calendar item updated!')); @@ -175,7 +168,7 @@ class CalendarController extends AbstractController $this->addFlash('error', $this->get('translator')->trans('This form contains errors')); } - $deleteForm = $this->createDeleteForm($id, $user, $accompanyingPeriod); + $deleteForm = $this->createDeleteForm($entity->getId(), $user, $accompanyingPeriod); if (null === $view) { throw $this->createNotFoundException('Template not found'); @@ -188,7 +181,7 @@ class CalendarController extends AbstractController 'form' => $form->createView(), 'delete_form' => $deleteForm->createView(), 'accompanyingCourse' => $accompanyingPeriod, - 'user' => $user, + // 'user' => $user, 'entity_json' => $entity_array, ]); } diff --git a/src/Bundle/ChillCalendarBundle/Entity/Calendar.php b/src/Bundle/ChillCalendarBundle/Entity/Calendar.php index 426827701..7b551013a 100644 --- a/src/Bundle/ChillCalendarBundle/Entity/Calendar.php +++ b/src/Bundle/ChillCalendarBundle/Entity/Calendar.php @@ -23,6 +23,7 @@ use Chill\MainBundle\Entity\User; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\Person; use Chill\ThirdPartyBundle\Entity\ThirdParty; +use DateInterval; use DateTimeImmutable; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; @@ -30,8 +31,8 @@ use Doctrine\ORM\Mapping as ORM; use LogicException; use Symfony\Component\Serializer\Annotation as Serializer; use Symfony\Component\Validator\Constraints\NotBlank; -use Symfony\Component\Validator\Constraints\Range; +use Symfony\Component\Validator\Constraints\Range; use Symfony\Component\Validator\Mapping\ClassMetadata; use function in_array; @@ -219,6 +220,15 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface return $this->comment; } + public function getDuration(): ?DateInterval + { + if ($this->getStartDate() === null || $this->getEndDate() === null) { + return null; + } + + return $this->getStartDate()->diff($this->getEndDate()); + } + public function getEndDate(): ?DateTimeImmutable { return $this->endDate; diff --git a/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/store/utils.js b/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/store/utils.js index 75cf65f04..692d19ba2 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/store/utils.js +++ b/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/store/utils.js @@ -1,4 +1,5 @@ import {COLORS} from '../const'; +import {ISOToDatetime} from 'ChillMainAssets/chill/js/date'; const addIdToValue = (string, id) => { let array = string ? string.split(',') : []; @@ -18,8 +19,25 @@ const removeIdFromValue = (string, id) => { * Assign missing keys for the ConcernedGroups component */ const mapEntity = (entity) => { - Object.assign(entity, {thirdParties: entity.professionals, users: entity.invites}); - return entity; + console.log('mapEntity', entity); + let calendar = { ...entity}; + Object.assign(calendar, {thirdParties: entity.professionals, users: entity.invites}); + + if (entity.startDate !== null ) { + calendar.startDate = ISOToDatetime(entity.startDate.datetime); + } + if (entity.endDate !== null) { + calendar.endDate = ISOToDatetime(entity.endDate.datetime); + } + + if (entity.calendarRange !== null) { + calendar.calendarRange.calendarRangeId = entity.calendarRange.id; + calendar.calendarRange.id = `range_${entity.calendarRange.id}`; + } + + console.log('new calendar object ', calendar); + + return calendar; }; const createUserData = (user, colorIndex) => { diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByAccompanyingCourse.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByAccompanyingCourse.html.twig index 56e7b70e0..b189d0eb2 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByAccompanyingCourse.html.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByAccompanyingCourse.html.twig @@ -37,7 +37,7 @@

- {{ calendar.endDate.diff(calendar.startDate)|date("%H:%M")}} + {{ calendar.duration|date('%H:%I')}}

{% endif %} @@ -47,12 +47,6 @@