Skip to content

Commit 7d40db0

Browse files
damsfxLukeTowers
andauthored
Add backend calendar controller (#1313)
* Update to fullcalendar v6.1.15 -add widget initial view config -add widget first day of week config -add model attribute config for all day event * Clean up * Update modules/backend/widgets/Calendar.php * Update modules/backend/widgets/calendar/assets/less/calendar.less * Clean css - remove unused files - remove comments * Use compiled css - add calendar less file to ServiceProvider - use fullcalendar css variables for theming - add option to chosse calendar theme for buttons style base on Winter's ones --------- Co-authored-by: Luke Towers <[email protected]> Co-authored-by: Luke Towers <[email protected]>
1 parent 6583b40 commit 7d40db0

File tree

13 files changed

+14954
-1541
lines changed

13 files changed

+14954
-1541
lines changed

modules/backend/ServiceProvider.php

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ protected function registerAssetBundles()
8989
$combiner->registerBundle('~/modules/backend/assets/js/winter.js');
9090
$combiner->registerBundle('~/modules/backend/widgets/table/assets/js/build.js');
9191
$combiner->registerBundle('~/modules/backend/widgets/mediamanager/assets/js/mediamanager-browser.js');
92+
$combiner->registerBundle('~/modules/backend/widgets/calendar/assets/less/calendar.less');
9293
$combiner->registerBundle('~/modules/backend/widgets/mediamanager/assets/less/mediamanager.less');
9394
$combiner->registerBundle('~/modules/backend/widgets/reportcontainer/assets/less/reportcontainer.less');
9495
$combiner->registerBundle('~/modules/backend/widgets/table/assets/less/table.less');

modules/backend/behaviors/CalendarController.php

+16-4
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,28 @@ class CalendarController extends ControllerBehavior
5353
*/
5454
protected array $requiredConfig = ['modelClass', 'searchList'];
5555

56+
/**
57+
* @var array Visible actions in context of the controller
58+
*/
59+
protected $actions = ['calendar'];
60+
61+
/**
62+
* @var mixed Configuration for this behaviour
63+
*/
64+
public $calendarConfig = 'config_calendar.yaml';
65+
5666
/**
5767
* Behavior constructor
5868
*/
5969
public function __construct(\Backend\Classes\Controller $controller)
6070
{
6171
parent::__construct($controller);
6272

63-
// Build the configuration
64-
$this->config = $this->makeConfig($controller->calendarConfig, $this->requiredConfig);
65-
$this->config->modelClass = Str::normalizeClassName($this->config->modelClass);
73+
/*
74+
* Build configuration
75+
*/
76+
$config = $controller->calendarConfig ?: $this->calendarConfig;
77+
$this->setConfig($config, $this->requiredConfig);
6678
}
6779

6880
/**
@@ -72,7 +84,7 @@ public function calendar(): void
7284
{
7385
$this->controller->pageTitle = $this->controller->pageTitle ? : Lang::get($this->getConfig(
7486
'title',
75-
'luketowers.calendarwidget::lang.behaviors.calendar.title'
87+
'backend::lang.calendar.title'
7688
));
7789
$this->controller->bodyClass = 'slim-container';
7890
$this->makeCalendar();

modules/backend/behaviors/calendarcontroller/docs/example.config_calendar.yaml

+47-30
Original file line numberDiff line numberDiff line change
@@ -5,56 +5,49 @@
55
# Model to use for getting the records to display on the calendar
66
modelClass: Author\Plugin\Models\Event
77

8+
# Calendar Title
9+
title: 'backend::lang.calendar.title'
10+
811
# Search columns
912
# Used for configuration of additional columns to search by
1013
searchList: $/author/plugin/models/event/columns.yaml
1114

1215
# Record URL
13-
recordUrl: author/plugins/events/update/:event_id
14-
16+
recordUrl: author/plugins/events/update/:id
1517

16-
# Record on click
17-
# @see custom.calendar.js sample
18-
# data is a plain object with the following properties:
19-
# startDate: is a JS Date Object
20-
# endDate: is a JS Date Object, may be null
21-
# event: A standard JavaScript object that FullCalendar uses to store information about a calendar event, including id, title, start, end
22-
# eventEl: The HTML element for this event
23-
# recordOnClick: $.wn.eventController.onEventClick(:data, :startDate, :endDate, :event, :eventEl)
24-
25-
# Triggered when the user clicks on a date or a time
26-
# data is a plain object with the following properties
27-
# date: is the a JS Date Object for the clicked day/time.
28-
# dateStr: An ISO8601 string representation of the date
29-
# allDay: true or false
30-
# dayEl: An HTML element that represents the whole-day that was clicked on.
31-
# event: The native JavaScript event with low-level information such as click coordinates.
32-
# view: The current view @see https://fullcalendar.io/docs/v4/view-object
33-
onClickDate: $.wn.availabilitySlotController.onClickDate(:data, :date, :dateStr, :allDay, :dayEl, :event, :view)
34-
35-
# The property to use as the title displayed on the calendar
18+
# Record property used as the title displayed on the calendar
3619
recordTitle: name
3720

38-
# The property to use as the start time for the record
39-
recordStart: start_time
21+
# Record property used as the start time
22+
recordStart: start_at
23+
24+
# Record property used as the end time
25+
recordEnd: end_at
4026

41-
# The property to use as the end time for the record
42-
recordEnd: end_time
27+
# Record property used as all day long event
28+
recordAllDay: all_day
4329

44-
# The property to use as the background color displayed on the record, , '' = the default background color in the calendar.less
30+
# Record property used as the background color displayed on the record, , '' = the default background color in the calendar.less
4531
recordColor: event_color
4632

47-
# The property to use as the content of the tooltip for the record
33+
# Record property used as the content of the tooltip
4834
recordTooltip: [recordTitle]
4935

36+
# Calendar widget theme color for buttons ('' for default, primary or secondary)
37+
calendarTheme:
38+
5039
# Available display modes to be supported in this instance
5140
availableDisplayModes: [month, week, day, list]
5241

42+
# Default view for calendar widget (month, week, day or list)
43+
initialView: month
44+
45+
# First day of week, 0=Sun, 1=Mon ...
46+
firstDay: 0
47+
5348
# Flag for whether calendar is read only or editable
5449
previewMode: true
5550

56-
# load one month of records at a time, ensure they stay loaded between month pages
57-
5851
# Toolbar widget configuration
5952
toolbar:
6053
# Partial for toolbar buttons
@@ -63,7 +56,31 @@ toolbar:
6356
# Search widget configuration
6457
search:
6558
prompt: backend::lang.list.search_prompt
59+
60+
# The filter config file for the controller
6661
filter: calendar_filter.yaml
6762

6863
# when filter gets applied, clear the client's cache of events, essentially start them over
6964
# if they had just loaded this page / month with the current filters applied
65+
66+
67+
# Record on click
68+
# @see custom.calendar.js sample
69+
# data is a plain object with the following properties:
70+
# startDate: is a JS Date Object
71+
# endDate: is a JS Date Object, may be null
72+
# event: A standard JavaScript object that FullCalendar uses to store information about a calendar event, including id, title, start, end
73+
# eventEl: The HTML element for this event
74+
# recordOnClick: $.wn.eventController.onEventClick(:data, :startDate, :endDate, :event, :eventEl)
75+
76+
# Triggered when the user clicks on a date or a time
77+
# data is a plain object with the following properties
78+
# date: is the a JS Date Object for the clicked day/time.
79+
# dateStr: An ISO8601 string representation of the date
80+
# allDay: true or false
81+
# dayEl: An HTML element that represents the whole-day that was clicked on.
82+
# event: The native JavaScript event with low-level information such as click coordinates.
83+
# view: The current view @see https://fullcalendar.io/docs/v4/view-object
84+
onClickDate: $.wn.availabilitySlotController.onClickDate(:data, :date, :dateStr, :allDay, :dayEl, :event, :view)
85+
86+
# load one month of records at a time, ensure they stay loaded between month pages

0 commit comments

Comments
 (0)