Skip to content

Commit

Permalink
Feature: added support for resourceId
Browse files Browse the repository at this point in the history
If you make a resourceTimeline you need to set a resourceId with your events. I also added a explanation in the Readme.
  • Loading branch information
Sjoerd24 committed Mar 23, 2024
1 parent 1a36cfb commit 82fb0e5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions src/Data/EventData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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] : [],
Expand Down

0 comments on commit 82fb0e5

Please sign in to comment.