From 9650a74cf69b18a65f44810e455fe151d996e17c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20St=C3=B6ckler?= Date: Tue, 30 Jan 2018 00:13:00 +0100 Subject: [PATCH 1/3] Add Scheduler support --- .../fullcalendar_scheduler.info.yml | 7 + .../fullcalendar_scheduler.libraries.yml | 22 +++ .../fullcalendar_scheduler.module | 17 ++ ...lendar_scheduler.fullcalendar_scheduler.js | 52 ++++++ .../type/FullcalendarScheduler.php | 170 ++++++++++++++++++ 5 files changed, 268 insertions(+) create mode 100644 fullcalendar_scheduler/fullcalendar_scheduler.info.yml create mode 100644 fullcalendar_scheduler/fullcalendar_scheduler.libraries.yml create mode 100644 fullcalendar_scheduler/fullcalendar_scheduler.module create mode 100644 fullcalendar_scheduler/js/fullcalendar_scheduler.fullcalendar_scheduler.js create mode 100644 fullcalendar_scheduler/src/Plugin/fullcalendar/type/FullcalendarScheduler.php diff --git a/fullcalendar_scheduler/fullcalendar_scheduler.info.yml b/fullcalendar_scheduler/fullcalendar_scheduler.info.yml new file mode 100644 index 0000000..7558211 --- /dev/null +++ b/fullcalendar_scheduler/fullcalendar_scheduler.info.yml @@ -0,0 +1,7 @@ +name: FullCalendar Scheduler +type: module +description: Adds Scheduler support to Fullcalendar views. +core: 8.x +package: FullCalendar +dependencies: + - fullcalendar diff --git a/fullcalendar_scheduler/fullcalendar_scheduler.libraries.yml b/fullcalendar_scheduler/fullcalendar_scheduler.libraries.yml new file mode 100644 index 0000000..ab11782 --- /dev/null +++ b/fullcalendar_scheduler/fullcalendar_scheduler.libraries.yml @@ -0,0 +1,22 @@ +fullcalendar_scheduler: + remote: https://fullcalendar.io/scheduler/ + version: 1.9.1 + license: + name: proprietary + url: https://github.com/fullcalendar/fullcalendar-scheduler/blob/master/LICENSE.md + gpl-compatible: true + js: + /libraries/fullcalendar-scheduler/scheduler.js: {} + css: + theme: + /libraries/fullcalendar-scheduler/scheduler.css: {} + dependencies: + - fullcalendar/fullcalendar + +drupal.fullcalendar_scheduler: + version: VERSION + js: + js/fullcalendar_scheduler.fullcalendar_scheduler.js: { } + dependencies: + - fullcalendar_scheduler/fullcalendar_scheduler + - fullcalendar/drupal.fullcalendar.js diff --git a/fullcalendar_scheduler/fullcalendar_scheduler.module b/fullcalendar_scheduler/fullcalendar_scheduler.module new file mode 100644 index 0000000..f653de6 --- /dev/null +++ b/fullcalendar_scheduler/fullcalendar_scheduler.module @@ -0,0 +1,17 @@ + []]; + $variables['#attached'] += ['library' => []]; + $variables['#attached']['library'][] = 'fullcalendar_scheduler/drupal.fullcalendar_scheduler'; + } +} diff --git a/fullcalendar_scheduler/js/fullcalendar_scheduler.fullcalendar_scheduler.js b/fullcalendar_scheduler/js/fullcalendar_scheduler.fullcalendar_scheduler.js new file mode 100644 index 0000000..f642468 --- /dev/null +++ b/fullcalendar_scheduler/js/fullcalendar_scheduler.fullcalendar_scheduler.js @@ -0,0 +1,52 @@ +/** + * @file + * Processes the FullCalendar options and passes them to the integration. + */ + +(function ($, Drupal, drupalSettings) { + + "use strict"; + + Drupal.fullcalendar.plugins.fullcalendar_scheduler = { + options: function (fullcalendar, settings) { + + fullcalendar.parseEvents = function (callback) { + var events = []; + var details = this.$calendar.find('.fullcalendar-event-details'); + for (var i = 0; i < details.length; i++) { + var event = $(details[i]); + var eid = event.data('eid'); + events.push({ + field: event.data('field'), + index: event.data('index'), + eid: eid, + entity_type: event.data('entity-type'), + title: event.attr('title'), + start: event.data('start'), + end: event.data('end'), + url: event.attr('href'), + allDay: (event.data('all-day') === 1), + className: event.data('cn'), + editable: (event.data('editable') === 1), + dom_id: this.dom_id, + resourceId: settings.events[eid].resourceId, + }); + } + callback(events); + }; + + var options = Drupal.fullcalendar.plugins.fullcalendar.options(fullcalendar, settings); + + // Merge in our settings. + $.extend(options, settings.fullcalendar_scheduler); + + options.resourceRender = function (resourceObj, labelTds, bodyTds) { + labelTds.find('.fc-cell-text').html(resourceObj.html); + }; + + return options; + } + + }; + +})(jQuery, Drupal, drupalSettings); diff --git a/fullcalendar_scheduler/src/Plugin/fullcalendar/type/FullcalendarScheduler.php b/fullcalendar_scheduler/src/Plugin/fullcalendar/type/FullcalendarScheduler.php new file mode 100644 index 0000000..2ba7d33 --- /dev/null +++ b/fullcalendar_scheduler/src/Plugin/fullcalendar/type/FullcalendarScheduler.php @@ -0,0 +1,170 @@ + [ + 'enabled' => ['default' => FALSE], + 'resource_field' => ['default' => NULL], + 'defaultView' => ['default' => 'timelineDay'], + 'views' => ['default' => [ + 'timelineDay' => [ + 'slotLabelFormat' => '', + ], + 'agendaDay' => [ + 'slotLabelFormat' => '', + ], + 'timelineWeek' => [ + 'slotLabelFormat' => '', + ], + 'agendaWeek' => [ + 'slotLabelFormat' => '', + ], + 'timelineMonth' => [ + 'slotLabelFormat' => '', + ], + 'timelineYear' => [ + 'slotLabelFormat' => '', + ], + ]], + 'schedulerLicenseKey' => ['default' => ''], + ], + ]; + return $options; + } + + /** + * {@inheritdoc} + */ + public function buildOptionsForm(&$form, FormStateInterface $form_state) { + $form['fullcalendar_scheduler'] = [ + '#type' => 'details', + '#title' => $this->t('Scheduler'), + '#open' => TRUE, + ]; + $form['fullcalendar_scheduler']['enabled'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Use the Scheduler display'), + '#default_value' => $this->style->options['fullcalendar_scheduler']['enabled'], + '#fieldset' => 'fullcalendar_scheduler', + ]; + + $field_labels = $this->style->displayHandler->getFieldLabels(TRUE); + $form['fullcalendar_scheduler']['resource_field'] = [ + '#type' => 'select', + '#title' => $this->t('Resource field'), + '#options' => $field_labels, + '#default_value' => $this->style->options['fullcalendar_scheduler']['resource_field'], + '#fieldset' => 'fullcalendar_scheduler', + ]; + $form['fullcalendar_scheduler']['defaultView'] = [ + '#type' => 'select', + '#title' => $this->t('Initial display'), + '#options' => [ + 'timelineDay' => $this->t('Day'), + 'agendaDay' => $this->t('Day (Agenda)'), + 'timelineWeek' => $this->t('Week'), + 'agendaWeek' => $this->t('Week (Agenda)'), + 'timelineMonth' => $this->t('Month'), + 'timelineYear' => $this->t('Year'), + ], + '#description' => Link::fromTextAndUrl($this->t('More info'), Url::fromUri('http://arshaw.com/fullcalendar/docs/views/Available_Views', ['attributes' => ['target' => '_blank']])), + '#default_value' => $this->style->options['fullcalendar_scheduler']['defaultView'], + '#fieldset' => 'fullcalendar_scheduler', + ]; + $form['fullcalendar_scheduler']['views'] = [ + '#type' => 'details', + '#title' => $this->t('Display configuration'), + ]; + foreach ($form['fullcalendar_scheduler']['defaultView']['#options'] as $option => $label) { + $form['fullcalendar_scheduler']['views'][$option] = [ + '#type' => 'details', + '#title' => $label, + ]; + $form['fullcalendar_scheduler']['views'][$option]['slotLabelFormat'] = [ + '#type' => 'textfield', + '#title' => $this->t('Header date format'), + '#default_value' => $this->style->options['fullcalendar_scheduler']['views'][$option]['slotLabelFormat'], + '#description' => Link::fromTextAndUrl($this->t('More info'), Url::fromUri('http://arshaw.com/fullcalendar/docs/agenda/slotLabelFormat', array('attributes' => array('target' => '_blank')))), + ]; + $form['fullcalendar_scheduler']['views'][$option]['slotWidth'] = [ + '#type' => 'textfield', + '#title' => $this->t('Column width'), + '#default_value' => $this->style->options['fullcalendar_scheduler']['views'][$option]['slotWidth'], + '#field_suffix' => 'px', + '#description' => Link::fromTextAndUrl($this->t('More info'), Url::fromUri('http://arshaw.com/fullcalendar/docs/agenda/slotWidth', array('attributes' => array('target' => '_blank')))), + ]; + } + + $form['fullcalendar_scheduler']['schedulerLicenseKey'] = [ + '#type' => 'textfield', + '#title' => $this->t('License key'), + '#default_value' => $this->style->options['fullcalendar_scheduler']['schedulerLicenseKey'], + '#description' => Link::fromTextAndUrl($this->t('More info'), Url::fromUri('https://fullcalendar.io/scheduler/license/', ['attributes' => ['target' => '_blank']])), + ]; + } + + /** + * {@inheritdoc} + */ + public function process(&$settings) { + if ($settings['fullcalendar_scheduler']['enabled']) { + $default_view = $settings['fullcalendar_scheduler']['defaultView']; + if (isset($settings['fullcalendar']['titleFormat']) && !is_array($settings['fullcalendar']['titleFormat'])) { + $type = strtolower(substr($default_view, 8)); + $settings['fullcalendar']['titleFormat'] = $settings['fullcalendar']['titleFormat'][$type]; + } + + $resource_field = $settings['fullcalendar_scheduler']['resource_field']; + + $settings['events'] = []; + $resources = []; + foreach ($this->style->view->result as $delta => $row) { + $field_value = $this->style->getFieldValue($delta, $resource_field); + $field = (string) $this->style->getField($delta, $resource_field); + + $entity = $row->_entity; + $settings['events'][$entity->id()] = [ + 'resourceId' => $field_value, + ]; + + $resources[$field_value] = [ + 'id' => $field_value, + 'title' => strip_tags(htmlspecialchars_decode($field)), + 'html' => $field, + ]; + } + $settings['fullcalendar_scheduler']['resources'] = array_values($resources); + + unset( + $settings['fullcalendar_scheduler']['enabled'], + $settings['fullcalendar_scheduler']['resource_field'] + ); + } + else { + unset($settings['fullcalendar_scheduler']); + } + } + +} From 0ced1eccf7d855b5372bf9d7819aa57d20d79706 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20St=C3=B6ckler?= Date: Fri, 9 Feb 2018 14:30:18 +0100 Subject: [PATCH 2/3] Update patch for #2853942 See comment #6 --- .../fullcalendar_scheduler.libraries.yml | 2 +- .../fullcalendar_scheduler.module | 17 ----------------- .../fullcalendar/type/FullcalendarScheduler.php | 1 + 3 files changed, 2 insertions(+), 18 deletions(-) delete mode 100644 fullcalendar_scheduler/fullcalendar_scheduler.module diff --git a/fullcalendar_scheduler/fullcalendar_scheduler.libraries.yml b/fullcalendar_scheduler/fullcalendar_scheduler.libraries.yml index ab11782..9a6a0bc 100644 --- a/fullcalendar_scheduler/fullcalendar_scheduler.libraries.yml +++ b/fullcalendar_scheduler/fullcalendar_scheduler.libraries.yml @@ -13,7 +13,7 @@ fullcalendar_scheduler: dependencies: - fullcalendar/fullcalendar -drupal.fullcalendar_scheduler: +drupal.fullcalendar_scheduler.js: version: VERSION js: js/fullcalendar_scheduler.fullcalendar_scheduler.js: { } diff --git a/fullcalendar_scheduler/fullcalendar_scheduler.module b/fullcalendar_scheduler/fullcalendar_scheduler.module deleted file mode 100644 index f653de6..0000000 --- a/fullcalendar_scheduler/fullcalendar_scheduler.module +++ /dev/null @@ -1,17 +0,0 @@ - []]; - $variables['#attached'] += ['library' => []]; - $variables['#attached']['library'][] = 'fullcalendar_scheduler/drupal.fullcalendar_scheduler'; - } -} diff --git a/fullcalendar_scheduler/src/Plugin/fullcalendar/type/FullcalendarScheduler.php b/fullcalendar_scheduler/src/Plugin/fullcalendar/type/FullcalendarScheduler.php index 2ba7d33..5dd85ed 100644 --- a/fullcalendar_scheduler/src/Plugin/fullcalendar/type/FullcalendarScheduler.php +++ b/fullcalendar_scheduler/src/Plugin/fullcalendar/type/FullcalendarScheduler.php @@ -13,6 +13,7 @@ * @FullcalendarOption( * id = "fullcalendar_scheduler", * module = "fullcalendar_scheduler", + * js = TRUE, * weight = "10", * ) */ From b4b0a5ef818e20fed60785de44db5ab0b5a5d348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20St=C3=B6ckler?= Date: Fri, 9 Feb 2018 17:41:24 +0100 Subject: [PATCH 3/3] Fix some codestyle issues and add event color support --- .../js/fullcalendar_scheduler.fullcalendar_scheduler.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fullcalendar_scheduler/js/fullcalendar_scheduler.fullcalendar_scheduler.js b/fullcalendar_scheduler/js/fullcalendar_scheduler.fullcalendar_scheduler.js index f642468..9f0f430 100644 --- a/fullcalendar_scheduler/js/fullcalendar_scheduler.fullcalendar_scheduler.js +++ b/fullcalendar_scheduler/js/fullcalendar_scheduler.fullcalendar_scheduler.js @@ -28,8 +28,9 @@ allDay: (event.data('all-day') === 1), className: event.data('cn'), editable: (event.data('editable') === 1), + color: event.data('color'), dom_id: this.dom_id, - resourceId: settings.events[eid].resourceId, + resourceId: settings.events[eid].resourceId }); } callback(events); @@ -39,7 +40,7 @@ // Merge in our settings. $.extend(options, settings.fullcalendar_scheduler); - + options.resourceRender = function (resourceObj, labelTds, bodyTds) { labelTds.find('.fc-cell-text').html(resourceObj.html); };