Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
saade committed Jun 27, 2022
1 parent 352d294 commit 2da36bf
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 40 deletions.
Empty file.
56 changes: 38 additions & 18 deletions resources/views/fullcalendar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,49 @@
<x-filament::hr />
@endif

<div wire:ignore x-data="" x-init='document.addEventListener("DOMContentLoaded", () => {
const calendar = new FullCalendar.Calendar($el, Object.assign(
@json($this->getConfig()),
{
events: @json($events),
eventClick: ({ event, jsEvent }) => {
if(event.url) {
<div
wire:ignore
x-data=""
x-init='
document.addEventListener("DOMContentLoaded", function() {
const config = @json($this->getConfig());
const events = @json($events);
const eventClick = function ({ event, jsEvent }) {
if( event.url ) {
jsEvent.preventDefault();
window.open(event.url, "_blank");
return false;
}
@js($this->isListeningClickEvent()) && window.livewire.find("{{ $this->id }}").onEventClick(event)
},
eventDrop: ({ event, oldEvent, relatedEvents }) => @js($this->isListeningDropEvent()) && window.livewire.find("{{ $this->id }}").onEventDrop(event, oldEvent, relatedEvents),
}
));
calendar.render();
})'>
</div>
@if ($this::isListeningClickEvent())
$wire.onEventClick(event)
@endif
}
const eventDrop = function ({ event, oldEvent, relatedEvents }) {
@if($this::isListeningDropEvent())
$wire.onEventDrop(event, oldEvent, relatedEvents)
@endif
}
const calendar = new FullCalendar.Calendar($el, {
...config,
events,
eventClick,
eventDrop
});
calendar.render();
})
'></div>
</x-filament::card>

@includeWhen($this::canCreate(), 'filament-fullcalendar::modals.create-event-modal')
@if($this::canCreate())
<x:filament-fullcalendar::create-event-modal />
@endif

@includeWhen($this::canEdit(), 'filament-fullcalendar::modals.edit-event-modal')
@if($this::canEdit())
<x:filament-fullcalendar::edit-event-modal />
@endif
</x-filament::widget>
14 changes: 12 additions & 2 deletions src/Widgets/Concerns/CanManageEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,21 @@

trait CanManageEvents
{
use AuthorizesActions;
use CreateEventForm;
use EditEventForm;

protected function setUpForms(): void
{
if (static::canCreate()) {
$this->createEventForm->fill();
}

if (static::canEdit()) {
$this->editEventForm->fill();
}
}

protected function getForms(): array
{
return [
Expand All @@ -35,8 +47,6 @@ public function onCreateEventClick(): void
return;
}

$this->createEventForm->fill();

$this->dispatchBrowserEvent('open-modal', ['id' => 'fullcalendar--create-event-modal']);
}
}
21 changes: 21 additions & 0 deletions src/Widgets/Concerns/CantManageEvents.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Saade\FilamentFullCalendar\Widgets\Concerns;

trait CantManageEvents
{
public static function canCreate(): bool
{
return false;
}

public static function canEdit(?array $event = null): bool
{
return false;
}

public static function canDelete(?array $event = null): bool
{
return false;
}
}
8 changes: 4 additions & 4 deletions src/Widgets/Concerns/FiresEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ trait FiresEvents
// //
// }

public function isListeningClickEvent(): bool
public static function isListeningClickEvent(): bool
{
return method_exists($this, 'onEventClick');
return method_exists(static::class, 'onEventClick');
}

/**
Expand All @@ -31,8 +31,8 @@ public function isListeningClickEvent(): bool
// //
// }

public function isListeningDropEvent(): bool
public static function isListeningDropEvent(): bool
{
return method_exists($this, 'onEventDrop');
return method_exists(static::class, 'onEventDrop');
}
}
8 changes: 2 additions & 6 deletions src/Widgets/Forms/CreateEventForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,8 @@ protected function getCreateEventForm(): array
{
return [
'createEventForm' => $this->makeForm()
->schema(
array_map(
fn ($component) => $component->statePath('createEventFormState'),
static::getCreateEventFormSchema()
)
),
->schema(static::getCreateEventFormSchema())
->statePath('createEventFormState'),
];
}
}
8 changes: 2 additions & 6 deletions src/Widgets/Forms/EditEventForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,8 @@ protected function getEditEventForm(): array
{
return [
'editEventForm' => $this->makeForm()
->schema(
array_map(
fn ($component) => $component->statePath('editEventFormState'),
static::getEditEventFormSchema()
)
),
->schema(static::getEditEventFormSchema())
->statePath('editEventFormState'),
];
}
}
6 changes: 2 additions & 4 deletions src/Widgets/FullCalendarWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Filament\Forms\Contracts\HasForms;
use Filament\Widgets\Widget;
use Illuminate\View\View;
use Saade\FilamentFullCalendar\Widgets\Concerns\AuthorizesActions;
use Saade\FilamentFullCalendar\Widgets\Concerns\CanManageEvents;
use Saade\FilamentFullCalendar\Widgets\Concerns\FiresEvents;
use Saade\FilamentFullCalendar\Widgets\Concerns\UsesConfig;
Expand All @@ -17,17 +16,16 @@ class FullCalendarWidget extends Widget implements HasForms
CanManageEvents::getForms insteadof InteractsWithForms;
}

use AuthorizesActions;
use FiresEvents;
use UsesConfig;

protected static string $view = 'filament-fullcalendar::fullcalendar';

protected int | string | array $columnSpan = 'full';

public function getViewData(): array
public function mount(): void
{
return [];
$this->setUpForms();
}

public function render(): View
Expand Down

0 comments on commit 2da36bf

Please sign in to comment.