diff --git a/app/controllers/calendar/schedule.php b/app/controllers/calendar/schedule.php index 0a99314a4f9c2695a7656b98bad4f707a92febfb..8f5e6e533b30ae1a3b799a4a09e7c4d943642ee2 100644 --- a/app/controllers/calendar/schedule.php +++ b/app/controllers/calendar/schedule.php @@ -109,6 +109,7 @@ class Calendar_ScheduleController extends AuthenticatedController $semester->id ?? '', Request::bool('show_hidden', false) ); + $fullcalendar->setResponsiveDefaultView('timeGridDay'); $this->fullcalendar = $fullcalendar->render(); } diff --git a/lib/classes/Fullcalendar.php b/lib/classes/Fullcalendar.php index db8364adb1808410f594275c33f5a87dc031de37..86746010ae26619fb4b4c8962e8e357515d73db2 100644 --- a/lib/classes/Fullcalendar.php +++ b/lib/classes/Fullcalendar.php @@ -1,9 +1,6 @@ <?php - - namespace Studip; - class Fullcalendar { protected $title; @@ -20,7 +17,6 @@ class Fullcalendar */ protected $attributes; - /** * The name of the fullcalendar for the data attribute. This is set * to "fullcalendar" by default, but custom fullcalendars may require @@ -29,7 +25,6 @@ class Fullcalendar */ protected $data_name; - public static function create( $title = '', $config = [], @@ -47,7 +42,6 @@ class Fullcalendar return $instance->render(); } - public function __construct( $title = '', $config = [], @@ -61,6 +55,23 @@ class Fullcalendar $this->data_name = $data_name; } + public function setDefaultView(?string $view): void + { + if ($view === null) { + unset($this->config['defaultView']); + } else { + $this->config['defaultView'] = $view; + } + } + + public function setResponsiveDefaultView(?string $view): void + { + if ($view === null) { + unset($this->config['responsiveDefaultView']); + } else { + $this->config['responsiveDefaultView'] = $view; + } + } public function render() { @@ -79,7 +90,6 @@ class Fullcalendar ); } - /** * Creates an array with data for a Fullcalendar instance * from Stud.IP objects that implement the EventSource interface. diff --git a/resources/assets/javascripts/lib/fullcalendar.js b/resources/assets/javascripts/lib/fullcalendar.js index af86d59cf9c97007cdb77c94dfa51d3c86f5395f..615cb2d919ebac40a5a908a85fc30ff558e1ec53 100644 --- a/resources/assets/javascripts/lib/fullcalendar.js +++ b/resources/assets/javascripts/lib/fullcalendar.js @@ -15,6 +15,7 @@ import resourceTimelinePlugin from '@fullcalendar/resource-timeline'; import { jsPDF } from 'jspdf'; import html2canvas from 'html2canvas'; +import Responsive from "./responsive"; Date.prototype.getWeekNumber = function () { var d = new Date(Date.UTC(this.getFullYear(), this.getMonth(), this.getDate())); @@ -395,14 +396,20 @@ class Fullcalendar return; } - var config = $(node).data('config'); + let config = $(node).data('config'); + + let defaultView = 'timeGridWeek'; + if (Responsive.isResponsive() && config.responsiveDefaultView !== undefined) { + defaultView = config.responsiveDefaultView; + } else if (config.defaultView !== undefined) { + defaultView = config.defaultView; + } //Make sure the default values are set, if they are not found //in the additional_config object: config = $.extend({ plugins: [ interactionPlugin, dayGridPlugin, timeGridPlugin, resourceCommonPlugin, resourceTimeGridPlugin, resourceTimelinePlugin ], schedulerLicenseKey: 'GPL-My-Project-Is-Open-Source', - defaultView: 'timeGridWeek', header: { left: 'dayGridMonth,timeGridWeek,timeGridDay' }, @@ -696,6 +703,8 @@ class Fullcalendar config = $.extend({}, config, additional_config); + config.defaultView = defaultView; + return this.init(node, config); }