Skip to content

Commit

Permalink
Adds access to resource on events
Browse files Browse the repository at this point in the history
  • Loading branch information
glennjacobs committed Dec 31, 2023
1 parent 525641a commit 6036517
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dist/filament-fullcalendar.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions resources/js/filament-fullcalendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export default function fullcalendar({

this.$wire.onEventClick(event)
},
eventDrop: async ({ event, oldEvent, relatedEvents, delta, revert }) => {
const shouldRevert = await this.$wire.onEventDrop(event, oldEvent, relatedEvents, delta)
eventDrop: async ({ event, oldEvent, relatedEvents, delta, oldResource, newResource, revert }) => {
const shouldRevert = await this.$wire.onEventDrop(event, oldEvent, relatedEvents, delta, oldResource, newResource)

if (typeof shouldRevert === 'boolean' && shouldRevert) {
revert()
Expand All @@ -70,13 +70,13 @@ export default function fullcalendar({
revert()
}
},
dateClick: ({ dateStr, allDay, view }) => {
dateClick: ({ dateStr, allDay, view, resource }) => {
if (!selectable) return;
this.$wire.onDateSelect(dateStr, null, allDay, view)
this.$wire.onDateSelect(dateStr, null, allDay, view, resource)
},
select: ({ startStr, endStr, allDay, view }) => {
select: ({ startStr, endStr, allDay, view, resource }) => {
if (!selectable) return;
this.$wire.onDateSelect(startStr, endStr, allDay, view)
this.$wire.onDateSelect(startStr, endStr, allDay, view, resource)
},
})

Expand Down
18 changes: 12 additions & 6 deletions src/Widgets/Concerns/InteractsWithEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ public function onEventClick(array $event): void
* @param array $oldEvent An Event Object that holds information about the event before the drop.
* @param array $relatedEvents An array of other related Event Objects that were also dropped. An event might have other recurring event instances or might be linked to other events with the same groupId
* @param array $delta A Duration Object that represents the amount of time the event was moved by.
* @return bool Wether to revert the drop action.
* @param ?array $oldResource A Resource Object that represents the previously assigned resource.
* @param ?array $newResource A Resource Object that represents the newly assigned resource.
* @return bool Whether to revert the drop action.
*/
public function onEventDrop(array $event, array $oldEvent, array $relatedEvents, array $delta): bool
public function onEventDrop(array $event, array $oldEvent, array $relatedEvents, array $delta, ?array $oldResource, ?array $newResource): bool
{
if ($this->getModel()) {
$this->record = $this->resolveRecord($event['id']);
Expand All @@ -44,6 +46,8 @@ public function onEventDrop(array $event, array $oldEvent, array $relatedEvents,
'oldEvent' => $oldEvent,
'relatedEvents' => $relatedEvents,
'delta' => $delta,
'oldResource' => $oldResource,
'newResource' => $newResource,
]);

return false;
Expand All @@ -56,7 +60,7 @@ public function onEventDrop(array $event, array $oldEvent, array $relatedEvents,
* @param array $relatedEvents An array of other related Event Objects that were also dropped. An event might have other recurring event instances or might be linked to other events with the same groupId
* @param array $startDelta A Duration Object that represents the amount of time the event’s start date was moved by.
* @param array $endDelta A Duration Object that represents the amount of time the event’s end date was moved by.
* @return mixed Wether to revert the resize action.
* @return mixed Whether to revert the resize action.
*/
public function onEventResize(array $event, array $oldEvent, array $relatedEvents, array $startDelta, array $endDelta): bool
{
Expand All @@ -79,12 +83,13 @@ public function onEventResize(array $event, array $oldEvent, array $relatedEvent
/**
* Triggered when a date/time selection is made (single or multiple days).
* @param string $start An ISO8601 string representation of the start date. It will have a timezone offset similar to the calendar’s timeZone. If selecting all-day cells, it won’t have a time nor timezone part.
* @param string $end An ISO8601 string representation of the end date. It will have a timezone offset similar to the calendar’s timeZone. If selecting all-day cells, it won’t have a time nor timezone part.
* @param ?string $end An ISO8601 string representation of the end date. It will have a timezone offset similar to the calendar’s timeZone. If selecting all-day cells, it won’t have a time nor timezone part.
* @param bool $allDay Whether the selection happened on all-day cells.
* @param array $view A View array that contains information about a calendar view, such as title and date range.
* @param ?array $view A View array that contains information about a calendar view, such as title and date range.
* @param ?array $resource A Resource Object that represents the selected resource.
* @return void
*/
public function onDateSelect(string $start, ?string $end, bool $allDay, ?array $view): void
public function onDateSelect(string $start, ?string $end, bool $allDay, ?array $view, ?array $resource): void
{
[$start, $end] = $this->calculateTimezoneOffset($start, $end, $allDay);

Expand All @@ -93,6 +98,7 @@ public function onDateSelect(string $start, ?string $end, bool $allDay, ?array $
'start' => $start,
'end' => $end,
'allDay' => $allDay,
'resource' => $resource,
]);
}

Expand Down

0 comments on commit 6036517

Please sign in to comment.