From 849e7158e41f107c63bb8e1276cb784f46126cac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 29 Jun 2022 15:28:37 +0200 Subject: [PATCH] adding location to ranges and more control on MyCalendarRanges --- .../Entity/CalendarRange.php | 38 +++++++- .../Resources/public/types.ts | 13 ++- .../Resources/public/vuejs/Calendar/api.ts | 18 +--- .../public/vuejs/Calendar/store/utils.ts | 2 + .../public/vuejs/MyCalendarRange/App2.vue | 80 +++++++++++++--- .../vuejs/MyCalendarRange/store/index.ts | 44 ++------- .../store/modules/calendarRanges.ts | 16 ++-- .../MyCalendarRange/store/modules/location.ts | 57 ++++++++++++ .../migrations/Version20220629095515.php | 30 ++++++ .../Resources/public/lib/api/locations.ts | 6 ++ .../Resources/public/lib/api/user.ts | 25 +++++ .../ChillMainBundle/Resources/public/types.ts | 92 +++++++++++++++++++ src/vue-multiselect.d.ts | 14 +++ 13 files changed, 357 insertions(+), 78 deletions(-) create mode 100644 src/Bundle/ChillCalendarBundle/Resources/public/vuejs/MyCalendarRange/store/modules/location.ts create mode 100644 src/Bundle/ChillCalendarBundle/migrations/Version20220629095515.php create mode 100644 src/Bundle/ChillMainBundle/Resources/public/lib/api/locations.ts create mode 100644 src/Bundle/ChillMainBundle/Resources/public/lib/api/user.ts create mode 100644 src/vue-multiselect.d.ts diff --git a/src/Bundle/ChillCalendarBundle/Entity/CalendarRange.php b/src/Bundle/ChillCalendarBundle/Entity/CalendarRange.php index 76596347c..3cd87b7f6 100644 --- a/src/Bundle/ChillCalendarBundle/Entity/CalendarRange.php +++ b/src/Bundle/ChillCalendarBundle/Entity/CalendarRange.php @@ -15,10 +15,12 @@ use Chill\MainBundle\Doctrine\Model\TrackCreationInterface; use Chill\MainBundle\Doctrine\Model\TrackCreationTrait; use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface; use Chill\MainBundle\Doctrine\Model\TrackUpdateTrait; +use Chill\MainBundle\Entity\Location; use Chill\MainBundle\Entity\User; use DateTimeImmutable; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation\Groups; +use Symfony\Component\Validator\Constraints as Assert; /** * @ORM\Table( @@ -42,7 +44,8 @@ class CalendarRange implements TrackCreationInterface, TrackUpdateInterface /** * @ORM\Column(type="datetime_immutable", nullable=false) - * @groups({"read", "write", "calendar:read"}) + * @Groups({"read", "write", "calendar:read"}) + * @Assert\NotNull() */ private ?DateTimeImmutable $endDate = null; @@ -50,29 +53,54 @@ class CalendarRange implements TrackCreationInterface, TrackUpdateInterface * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") - * @groups({"read"}) + * @Groups({"read"}) */ private $id; + /** + * @ORM\ManyToOne(targetEntity=Location::class) + * @ORM\JoinColumn(nullable=false) + * @Groups({"read", "write", "calendar:read"}) + * @Assert\NotNull() + */ + private ?Location $location; + /** * @ORM\Column(type="datetime_immutable", nullable=false) * @groups({"read", "write", "calendar:read"}) + * @Assert\NotNull() */ private ?DateTimeImmutable $startDate = null; /** * @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\User") - * @groups({"read", "write", "calendar:read"}) + * @Groups({"read", "write", "calendar:read"}) + * @Assert\NotNull() */ private ?User $user = null; + /** + * @return Location|null + */ + public function getLocation(): ?Location + { + return $this->location; + } + + /** + * @param Location|null $location + */ + public function setLocation(?Location $location): void + { + $this->location = $location; + } + + public function getCalendar(): ?Calendar { return $this->calendar; } - //TODO Lieu - public function getEndDate(): ?DateTimeImmutable { return $this->endDate; diff --git a/src/Bundle/ChillCalendarBundle/Resources/public/types.ts b/src/Bundle/ChillCalendarBundle/Resources/public/types.ts index 438d43e64..d5684009d 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/public/types.ts +++ b/src/Bundle/ChillCalendarBundle/Resources/public/types.ts @@ -1,11 +1,12 @@ import {EventInput} from '@fullcalendar/vue3'; -import {DateTime, User, UserAssociatedInterface} from '../../../ChillMainBundle/Resources/public/types' ; +import {DateTime, Location, User, UserAssociatedInterface} from '../../../ChillMainBundle/Resources/public/types' ; export interface CalendarRange { id: number; endDate: DateTime; startDate: DateTime; user: User; + location: Location; createdAt: DateTime; createdBy: User; updatedAt: DateTime; @@ -13,14 +14,16 @@ export interface CalendarRange { } export interface CalendarRangeCreate { - user: UserAssociatedInterface, - startDate: DateTime, - endDate: DateTime + user: UserAssociatedInterface; + startDate: DateTime; + endDate: DateTime; + location: Location; } export interface CalendarRangeEdit { startDate?: DateTime, endDate?: DateTime + location?: Location; } export interface Calendar { @@ -38,6 +41,8 @@ export type EventInputCalendarRange = EventInput & { id: string, userId: number, calendarRangeId: number, + locationId: number, + locationName: string, start: string, end: string, is: "range" diff --git a/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/api.ts b/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/api.ts index ee769877c..f209a632a 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/api.ts +++ b/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/api.ts @@ -3,22 +3,8 @@ import {datetimeToISO} from '../../../../../ChillMainBundle/Resources/public/chi import {User} from '../../../../../ChillMainBundle/Resources/public/types'; import {CalendarRange, CalendarRemote} from '../../types'; -export const whoami = (): Promise => { - const url = `/api/1.0/main/whoami.json`; - return fetch(url) - .then(response => { - if (response.ok) { - return response.json(); - } - throw { - msg: 'Error while getting whoami.', - sta: response.status, - txt: response.statusText, - err: new Error(), - body: response.body - }; - }); -}; +// re-export whoami +export {whoami} from "../../../../../ChillMainBundle/Resources/public/lib/api/user"; /** * diff --git a/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/store/utils.ts b/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/store/utils.ts index 1b32f234c..7ce63a45c 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/store/utils.ts +++ b/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/store/utils.ts @@ -73,6 +73,8 @@ export const calendarRangeToFullCalendarEvent = (entity: CalendarRange): EventIn allDay: false, userId: entity.user.id, calendarRangeId: entity.id, + locationId: entity.location.id, + locationName: entity.location.name, is: 'range', }; } diff --git a/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/MyCalendarRange/App2.vue b/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/MyCalendarRange/App2.vue index 99b3b9613..aa27f2d1c 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/MyCalendarRange/App2.vue +++ b/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/MyCalendarRange/App2.vue @@ -1,5 +1,10 @@