From 82fb0e5f6bb21588bc5910803b0f3c9890d94b03 Mon Sep 17 00:00:00 2001 From: Sjoerd van Heijst Date: Sat, 23 Mar 2024 15:31:28 +0100 Subject: [PATCH 1/3] Feature: added support for resourceId If you make a resourceTimeline you need to set a resourceId with your events. I also added a explanation in the Readme. --- README.md | 33 +++++++++++++++++++++++++++++++++ src/Data/EventData.php | 14 ++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/README.md b/README.md index d7af672..58e841b 100644 --- a/README.md +++ b/README.md @@ -436,6 +436,39 @@ protected function headerActions(): array } ``` +## Showing events in a resource Timeline + +If you want to use the resource timeline view, you have to make the following adjustments: + +Add this to the `config` method of the `FilamentFullCalendarPlugin`: +```php +FilamentFullCalendarPlugin::make() +->plugins(['resourceTimeline']) + ->config([ + 'initialView' => 'resourceTimelineMonth', + 'resourceAreaHeaderContent' => 'Resource overview', + 'headerToolbar' => [ + 'left' => 'prev,next today', + 'center' => 'title', + 'right' => 'resourceTimelineDay,resourceTimelineWeek,resourceTimelineMonth', + ], + 'resources' => [ + [ "id" => "1", + "title" => "Resource 1", + "eventColor" => "orange", + ] + , + [ "id" => "2", + "title" => "Resource 2", + "eventColor" => "green", + ], + ], +``` +Add this to your event data: +```php +EventData::make() + ->resourceId($resource->id) // this should match with the id of the resource set in the config above +``` ## Adding the widget to a Blade view Follow the [Filament Docs](https://filamentphp.com/docs/3.x/widgets/adding-a-widget-to-a-blade-view) to know how to add the widget to a Blade view. diff --git a/src/Data/EventData.php b/src/Data/EventData.php index c0c8435..9e2b684 100644 --- a/src/Data/EventData.php +++ b/src/Data/EventData.php @@ -11,6 +11,8 @@ class EventData implements Arrayable protected int|string|null $groupId = null; + protected int|string|array|null $resourceId = null; + protected bool $allDay = false; protected DateTimeInterface|string $start; @@ -58,6 +60,17 @@ public function groupId(int|string $groupId): static return $this; } + /** + * Events can be associated with a resource when its resourceId property matches one of + * the resource object’s id field + */ + public function resourceId(int|string|array $resourceId): static + { + $this->resourceId = $resourceId; + + return $this; + } + /** * Determines if the event is shown in the “all-day” section of relevant views. In addition, if true the time text is not displayed with the event. */ @@ -168,6 +181,7 @@ public function toArray(): array 'start' => $this->start, 'end' => $this->end, 'title' => $this->title, + ...$this->resourceId ? ['resourceId' => $this->resourceId] : [], ...$this->url ? ['url' => $this->url, 'shouldOpenUrlInNewTab' => $this->shouldOpenUrlInNewTab] : [], ...$this->groupId ? ['groupId' => $this->groupId] : [], ...$this->allDay ? ['allDay' => $this->allDay] : [], From 59589306448eeaf293998ccb8b5bdc653439a67e Mon Sep 17 00:00:00 2001 From: Sjoerd van Heijst Date: Sat, 23 Mar 2024 16:01:28 +0100 Subject: [PATCH 2/3] Update EventData.php --- src/Data/EventData.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Data/EventData.php b/src/Data/EventData.php index 9e2b684..56127a9 100644 --- a/src/Data/EventData.php +++ b/src/Data/EventData.php @@ -11,7 +11,9 @@ class EventData implements Arrayable protected int|string|null $groupId = null; - protected int|string|array|null $resourceId = null; + protected int|string|null $resourceId = null; + + protected ?array $resourceIds = null; protected bool $allDay = false; @@ -32,7 +34,6 @@ class EventData implements Arrayable protected ?string $textColor = null; protected ?array $extendedProps = null; - protected array $extraProperties = []; public static function make(): static @@ -64,15 +65,24 @@ public function groupId(int|string $groupId): static * Events can be associated with a resource when its resourceId property matches one of * the resource object’s id field */ - public function resourceId(int|string|array $resourceId): static + public function resourceId(int|string $resourceId): static { $this->resourceId = $resourceId; return $this; } + /** + * It is also possible to associate an event with multiple resources using the resourceIds property. + */ + public function resourceIds(array $resourceIds): static + { + $this->resourceIds = $resourceIds; + return $this; + } /** - * Determines if the event is shown in the “all-day” section of relevant views. In addition, if true the time text is not displayed with the event. + * Determines if the event is shown in the “all-day” section of relevant views. In addition, + * if true the time text is not displayed with the event. */ public function allDay(bool $allDay = true): static { @@ -182,6 +192,7 @@ public function toArray(): array 'end' => $this->end, 'title' => $this->title, ...$this->resourceId ? ['resourceId' => $this->resourceId] : [], + ...$this->resourceIds ? ['resourceIds' => $this->resourceIds] : [], ...$this->url ? ['url' => $this->url, 'shouldOpenUrlInNewTab' => $this->shouldOpenUrlInNewTab] : [], ...$this->groupId ? ['groupId' => $this->groupId] : [], ...$this->allDay ? ['allDay' => $this->allDay] : [], From 6e9c9e2ae3ec0a75d0f1173bdb34e46944b08e2f Mon Sep 17 00:00:00 2001 From: Saade Date: Thu, 28 Mar 2024 13:29:54 -0300 Subject: [PATCH 3/3] wip --- src/Data/EventData.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Data/EventData.php b/src/Data/EventData.php index 56127a9..f19f8ef 100644 --- a/src/Data/EventData.php +++ b/src/Data/EventData.php @@ -12,7 +12,7 @@ class EventData implements Arrayable protected int|string|null $groupId = null; protected int|string|null $resourceId = null; - + protected ?array $resourceIds = null; protected bool $allDay = false; @@ -34,6 +34,7 @@ class EventData implements Arrayable protected ?string $textColor = null; protected ?array $extendedProps = null; + protected array $extraProperties = []; public static function make(): static @@ -62,8 +63,7 @@ public function groupId(int|string $groupId): static } /** - * Events can be associated with a resource when its resourceId property matches one of - * the resource object’s id field + * Events can be associated with a resource when its resourceId property matches one of the resource object’s id field. */ public function resourceId(int|string $resourceId): static {