From f73e2918504c4786fe0609b1593971b4a959fa98 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms <tleilax+studip@gmail.com> Date: Tue, 19 Nov 2024 14:42:53 +0000 Subject: [PATCH] allow setting different default view (regular and responsive), re #4421 Merge request studip/studip!3657 --- app/controllers/calendar/schedule.php | 1 + lib/classes/Fullcalendar.php | 24 +++++++++++++------ .../assets/javascripts/lib/fullcalendar.js | 13 ++++++++-- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/app/controllers/calendar/schedule.php b/app/controllers/calendar/schedule.php index 0a99314a4f9..8f5e6e533b3 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 db8364adb18..86746010ae2 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 af86d59cf9c..615cb2d919e 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); } -- GitLab