Skip to content

Commit 165a4c1

Browse files
authored
Merge pull request #95 from saade/feat/enable-disable-plugins
enable/ disable plugins
2 parents 5649fc1 + 510b922 commit 165a4c1

4 files changed

Lines changed: 98 additions & 59 deletions

File tree

README.md

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
# Features
1111

12-
- Accepts all configurations from [FullCalendar](https://fullcalendar.io/docs#toc)
13-
- Event click and drop events
14-
- Modals for creating and editing events <sup>New in v1.0</sup>
12+
- Accepts all configurations from [FullCalendar](https://fullcalendar.io/docs#toc)
13+
- Event click and drop events
14+
- Modals for creating and editing events <sup>New in v1.0</sup>
1515

1616
<br>
1717

@@ -25,18 +25,18 @@
2525

2626
# Table of contents
2727

28-
- [Installation](#installation)
29-
- [Usage](#usage)
30-
- [Configuration](#configuration)
31-
- [Styling](#styling)
32-
- [Listening for events](#listening-for-events)
33-
- [Creating and Editing events with modals.](#creating-and-editing-events-with-modals)
34-
* [Creating Events](#creating-events)
35-
* [Editing Events](#editing-events)
36-
* [Authorizing actions](#authorizing-actions)
37-
* [Listening for cancelled modal](#listening-for-cancelled-modal)
38-
- [Refreshing calendar events](#refreshing-calendar-events)
39-
- [Filtering events based on the calendar view](#filtering-events-based-on-the-calendar-view)
28+
- [Installation](#installation)
29+
- [Usage](#usage)
30+
- [Configuration](#configuration)
31+
- [Styling](#styling)
32+
- [Listening for events](#listening-for-events)
33+
- [Creating and Editing events with modals.](#creating-and-editing-events-with-modals)
34+
- [Creating Events](#creating-events)
35+
- [Editing Events](#editing-events)
36+
- [Authorizing actions](#authorizing-actions)
37+
- [Listening for cancelled modal](#listening-for-cancelled-modal)
38+
- [Refreshing calendar events](#refreshing-calendar-events)
39+
- [Filtering events based on the calendar view](#filtering-events-based-on-the-calendar-view)
4040

4141
<br>
4242

@@ -60,7 +60,6 @@ php artisan vendor:publish --tag="filament-fullcalendar-config"
6060

6161
Since the package **does not** automatically add the `FullCalendarWidget` widget to your Filament panel, you are free to extend the widget and customise it yourself.
6262

63-
6463
1. First, create a [Filament Widget](https://filamentadmin.com/docs/2.x/admin/dashboard#getting-started):
6564

6665
```bash
@@ -125,15 +124,19 @@ class CalendarWidget extends FullCalendarWidget
125124
126125
> Both methods should retun an array of [EventObject](https://fullcalendar.io/docs/event-object).
127126
128-
129127
<br>
130128

131129
# Configuration
130+
132131
This is the contents of the default config file.
133132

134133
You can use any property that FullCalendar uses on its root object.
135134
Please refer to: [FullCalendar Docs](https://fullcalendar.io/docs#toc) to see the available options. It supports most of them.
136135

136+
### Plugins
137+
138+
You can enable or disable plugins by setting the `plugins` property to `true` or `false`. By default, all non-standard plugins are disabled.
139+
137140
```php
138141
<?php
139142

@@ -148,6 +151,11 @@ return [
148151

149152
'locale' => config('app.locale'),
150153

154+
'plugins' => [
155+
'rrule' => false,
156+
'resourceTimeline' => false,
157+
],
158+
151159
'headerToolbar' => [
152160
'left' => 'prev,next today',
153161
'center' => 'title',
@@ -236,19 +244,18 @@ Since [v1.0.0](https://github.com/saade/filament-fullcalendar/releases/tag/v1.0.
236244

237245
To customise the modal, override the following properties in your widget:
238246

239-
- `protected string $modalWidth`
240-
- `protected string $modalLabel`
241-
- `protected bool $modalSlideover`
247+
- `protected string $modalWidth`
248+
- `protected string $modalLabel`
249+
- `protected bool $modalSlideover`
242250

243251
The process of saving and editing the event is up to you, since this plugin does not rely on a Model to save the calendar events.
244252

245-
246253
## Creating Events
247254

248255
Events can be created in two ways.
249256

250-
- Clicking on a day (default)
251-
- Selecting a date range (click and drag across calendar days) (you need to opt-in for this, set `selectable => true` in the config file.)
257+
- Clicking on a day (default)
258+
- Selecting a date range (click and drag across calendar days) (you need to opt-in for this, set `selectable => true` in the config file.)
252259

253260
This will open the Create Event modal.
254261

@@ -278,21 +285,23 @@ protected static function getCreateEventFormSchema(): array
278285
```
279286

280287
You can override the `getCreateEventModalTitle()` method to change the modal title to a custom one:
288+
281289
```php
282-
public function getCreateEventModalTitle(): string
290+
public function getCreateEventModalTitle(): string
283291
{
284292
return __('filament::resources/pages/create-record.title', ['label' => $this->getModalLabel()]);
285293
}
286294
```
287295

288296
You can override the `getCreateEventModalSubmitButtonLabel()` and `getCreateEventModalCloseButtonLabel()` methods to change the modal button labels to custom labels:
297+
289298
```php
290-
public function getCreateEventModalSubmitButtonLabel(): string
299+
public function getCreateEventModalSubmitButtonLabel(): string
291300
{
292301
return __('filament::resources/pages/create-record.form.actions.create.label');
293302
}
294303

295-
public function getCreateEventModalCloseButtonLabel(): string
304+
public function getCreateEventModalCloseButtonLabel(): string
296305
{
297306
return __('filament::resources/pages/create-record.form.actions.cancel.label');
298307
}
@@ -354,21 +363,23 @@ protected static function getEditEventFormSchema(): array
354363
```
355364

356365
You can override the `getEditEventModalTitle()` method to change the modal title to a custom one:
366+
357367
```php
358-
public function getCreateEventModalTitle(): string
368+
public function getCreateEventModalTitle(): string
359369
{
360370
return __('filament::resources/pages/create-record.title', ['label' => $this->getModalLabel()]);
361371
}
362372
```
363373

364374
You can override the `getEditEventModalSubmitButtonLabel()` and `getEditEventModalCloseButtonLabel()` methods to change the modal button labels to custom labels:
375+
365376
```php
366-
public function getEditEventModalSubmitButtonLabel(): string
377+
public function getEditEventModalSubmitButtonLabel(): string
367378
{
368379
return __('filament::resources/pages/edit-record.form.actions.save.label');
369380
}
370381

371-
public function getEditEventModalCloseButtonLabel(): string
382+
public function getEditEventModalCloseButtonLabel(): string
372383
{
373384
return $this->editEventForm->isDisabled()
374385
? __('filament-support::actions/view.single.modal.actions.close.label')
@@ -389,7 +400,7 @@ public static function canView(?array $event = null): bool
389400
if ($event === null) {
390401
return true;
391402
}
392-
403+
393404
// Returning 'false' will not show the event Modal.
394405
return true;
395406
}
@@ -469,6 +480,7 @@ public function fetchEvents(array $fetchInfo): array
469480
you can filter events based on the timespan `$fetchInfo['start']` and `$fetchInfo['end']`.
470481

471482
example:
483+
472484
```php
473485
public function fetchEvents(array $fetchInfo): array
474486
{
@@ -507,8 +519,8 @@ Please review [our security policy](../../security/policy) on how to report secu
507519

508520
## Credits
509521

510-
- [Saade](https://github.com/saade)
511-
- [All Contributors](../../contributors)
522+
- [Saade](https://github.com/saade)
523+
- [All Contributors](../../contributors)
512524

513525
## License
514526

config/filament-fullcalendar.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111

1212
'locale' => config('app.locale'),
1313

14+
'plugins' => [
15+
'rrule' => false,
16+
'resourceTimeline' => false,
17+
],
18+
1419
'headerToolbar' => [
1520
'left' => 'prev,next today',
1621
'center' => 'title',

resources/js/components/calendar.js

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { Calendar } from '@fullcalendar/core';
2-
import rrulePlugin from '@fullcalendar/rrule';
3-
import dayGridPlugin from '@fullcalendar/daygrid';
4-
import timeGridPlugin from '@fullcalendar/timegrid';
5-
import listPlugin from '@fullcalendar/list';
6-
import resourceTimelinePlugin from '@fullcalendar/resource-timeline';
7-
import interactionPlugin from '@fullcalendar/interaction';
8-
import momentPlugin from '@fullcalendar/moment';
9-
import momentTimezonePlugin from '@fullcalendar/moment-timezone';
10-
import locales from '@fullcalendar/core/locales-all';
1+
import { Calendar } from '@fullcalendar/core'
2+
import rrulePlugin from '@fullcalendar/rrule'
3+
import dayGridPlugin from '@fullcalendar/daygrid'
4+
import timeGridPlugin from '@fullcalendar/timegrid'
5+
import listPlugin from '@fullcalendar/list'
6+
import resourceTimelinePlugin from '@fullcalendar/resource-timeline'
7+
import interactionPlugin from '@fullcalendar/interaction'
8+
import momentPlugin from '@fullcalendar/moment'
9+
import momentTimezonePlugin from '@fullcalendar/moment-timezone'
10+
import locales from '@fullcalendar/core/locales-all'
1111

1212
export default (Alpine) => {
1313
Alpine.data(
@@ -25,7 +25,7 @@ export default (Alpine) => {
2525
handleEventResizeUsing,
2626
handleDateClickUsing,
2727
handleSelectUsing,
28-
fetchEventsUsing
28+
fetchEventsUsing,
2929
}) => {
3030
return {
3131
calendar: null,
@@ -34,30 +34,52 @@ export default (Alpine) => {
3434

3535
init: function () {
3636
this.calendar = new Calendar(this.$refs.calendar, {
37-
plugins: [rrulePlugin, dayGridPlugin, timeGridPlugin, listPlugin, resourceTimelinePlugin, interactionPlugin, momentPlugin, momentTimezonePlugin],
3837
...config,
38+
plugins: [
39+
dayGridPlugin,
40+
timeGridPlugin,
41+
listPlugin,
42+
interactionPlugin,
43+
momentPlugin,
44+
momentTimezonePlugin,
45+
...(config.plugins.rrule ? [rrulePlugin] : []),
46+
...(config.plugins.resourceTimeline ? [resourceTimelinePlugin] : []),
47+
],
3948
locales,
4049
locale,
4150
eventClick: handleEventClickUsing,
4251
eventDrop: handleEventDropUsing,
4352
eventResize: handleEventResizeUsing,
4453
dateClick: handleDateClickUsing,
4554
select: handleSelectUsing,
46-
eventSources: [
47-
{ events },
48-
fetchEventsUsing
49-
],
50-
...shouldSaveState && {
51-
initialView: localStorage.getItem('fullcalendar.view.' + key) ?? initialView ?? undefined,
52-
initialDate: localStorage.getItem('fullcalendar.date.' + key) ?? initialDate ?? undefined,
55+
eventSources: [{ events }, fetchEventsUsing],
56+
...(shouldSaveState && {
57+
initialView:
58+
localStorage.getItem(
59+
'fullcalendar.view.' + key,
60+
) ??
61+
initialView ??
62+
undefined,
63+
initialDate:
64+
localStorage.getItem(
65+
'fullcalendar.date.' + key,
66+
) ??
67+
initialDate ??
68+
undefined,
5369
datesSet: function ({ start, view }) {
54-
localStorage.setItem('fullcalendar.view.' + key, view.type);
55-
localStorage.setItem('fullcalendar.date.' + key, start.toISOString());
70+
localStorage.setItem(
71+
'fullcalendar.view.' + key,
72+
view.type,
73+
)
74+
localStorage.setItem(
75+
'fullcalendar.date.' + key,
76+
start.toISOString(),
77+
)
5678
},
57-
}
58-
});
79+
}),
80+
})
5981

60-
this.calendar.render();
82+
this.calendar.render()
6183
},
6284
}
6385
},
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import calendarComponent from './components/calendar';
1+
import calendarComponent from './components/calendar'
22

33
document.addEventListener('alpine:init', () => {
4-
window.Alpine.plugin(calendarComponent);
5-
});
4+
window.Alpine.plugin(calendarComponent)
5+
})

0 commit comments

Comments
 (0)