MDL-60967 calendar: only load course filter when required
authorRyan Wyllie <ryan@moodle.com>
Tue, 9 Jan 2018 05:57:38 +0000 (05:57 +0000)
committerRyan Wyllie <ryan@moodle.com>
Tue, 9 Jan 2018 05:57:38 +0000 (05:57 +0000)
calendar/amd/build/calendar_threemonth.min.js
calendar/amd/build/repository.min.js
calendar/amd/build/view_manager.min.js
calendar/amd/src/calendar_threemonth.js
calendar/amd/src/repository.js
calendar/amd/src/view_manager.js
calendar/classes/external/month_exporter.php
calendar/externallib.php
calendar/lib.php
calendar/templates/calendar_mini.mustache

index f0300b1..db4a1a3 100644 (file)
Binary files a/calendar/amd/build/calendar_threemonth.min.js and b/calendar/amd/build/calendar_threemonth.min.js differ
index 2c8f751..6b1db42 100644 (file)
Binary files a/calendar/amd/build/repository.min.js and b/calendar/amd/build/repository.min.js differ
index 7a451fb..dd946d4 100644 (file)
Binary files a/calendar/amd/build/view_manager.min.js and b/calendar/amd/build/view_manager.min.js differ
index 3743d4b..4d9f278 100644 (file)
@@ -71,6 +71,7 @@ function(
             var placeHolder = $('<span>');
             placeHolder.attr('data-template', 'core_calendar/threemonth_month');
             placeHolder.attr('data-includenavigation', false);
+            placeHolder.attr('data-mini', true);
             var placeHolderContainer = $('<div>');
             placeHolderContainer.hide();
             placeHolderContainer.append(placeHolder);
index e522bb2..049f819 100644 (file)
@@ -95,9 +95,10 @@ define(['jquery', 'core/ajax'], function($, Ajax) {
      * @param {Number} courseid The course id.
      * @param {Number} categoryid The category id.
      * @param {Bool} includenavigation Whether to include navigation.
+     * @param {Bool} mini Whether the month is in mini view.
      * @return {promise} Resolved with the month view data.
      */
-    var getCalendarMonthData = function(year, month, courseid, categoryid, includenavigation) {
+    var getCalendarMonthData = function(year, month, courseid, categoryid, includenavigation, mini) {
         var request = {
             methodname: 'core_calendar_get_calendar_monthly_view',
             args: {
@@ -106,6 +107,7 @@ define(['jquery', 'core/ajax'], function($, Ajax) {
                 courseid: courseid,
                 categoryid: categoryid,
                 includenavigation: includenavigation,
+                mini: mini
             }
         };
 
index 299aece..2c59a72 100644 (file)
@@ -121,7 +121,8 @@ define([
 
             M.util.js_pending([root.get('id'), year, month, courseid].join('-'));
             var includenavigation = root.data('includenavigation');
-            return CalendarRepository.getCalendarMonthData(year, month, courseid, categoryid, includenavigation)
+            var mini = root.data('mini');
+            return CalendarRepository.getCalendarMonthData(year, month, courseid, categoryid, includenavigation, mini)
                 .then(function(context) {
                     return Templates.render(root.attr('data-template'), context);
                 })
index 08acf56..d3d4c73 100644 (file)
@@ -64,6 +64,11 @@ class month_exporter extends exporter {
      */
     protected $initialeventsloaded = true;
 
+    /**
+     * @var bool $showcoursefilter Whether to render the course filter selector as well.
+     */
+    protected $showcoursefilter = false;
+
     /**
      * Constructor for month_exporter.
      *
@@ -120,6 +125,7 @@ class month_exporter extends exporter {
             ],
             'filter_selector' => [
                 'type' => PARAM_RAW,
+                'optional' => true,
             ],
             'weeks' => [
                 'type' => week_exporter::read_properties_definition(),
@@ -206,7 +212,6 @@ class month_exporter extends exporter {
 
         $return = [
             'courseid' => $this->calendar->courseid,
-            'filter_selector' => $this->get_course_filter_selector($output),
             'weeks' => $this->get_weeks($output),
             'daynames' => $this->get_day_names($output),
             'view' => 'month',
@@ -224,6 +229,10 @@ class month_exporter extends exporter {
             'initialeventsloaded' => $this->initialeventsloaded,
         ];
 
+        if ($this->showcoursefilter) {
+            $return['filter_selector'] = $this->get_course_filter_selector($output);
+        }
+
         if ($context = $this->get_default_add_context()) {
             $return['defaulteventcontext'] = $context->id;
         }
@@ -405,6 +414,18 @@ class month_exporter extends exporter {
         return $this;
     }
 
+    /**
+     * Set whether the course filter selector should be shown.
+     *
+     * @param   bool    $show
+     * @return  $this
+     */
+    public function set_showcoursefilter(bool $show) {
+        $this->showcoursefilter = $show;
+
+        return $this;
+    }
+
     /**
      * Get the default context for use when adding a new event.
      *
index 7592536..0aeb9a4 100644 (file)
@@ -945,9 +945,10 @@ class core_calendar_external extends external_api {
      * @param   int     $courseid The course to be included
      * @param   int     $categoryid The category to be included
      * @param   bool    $includenavigation Whether to include navigation
+     * @param   bool    $mini Whether to return the mini month view or not
      * @return  array
      */
-    public static function get_calendar_monthly_view($year, $month, $courseid, $categoryid, $includenavigation) {
+    public static function get_calendar_monthly_view($year, $month, $courseid, $categoryid, $includenavigation, $mini) {
         global $CFG, $DB, $USER, $PAGE;
         require_once($CFG->dirroot."/calendar/lib.php");
 
@@ -958,6 +959,7 @@ class core_calendar_external extends external_api {
             'courseid' => $courseid,
             'categoryid' => $categoryid,
             'includenavigation' => $includenavigation,
+            'mini' => $mini,
         ]);
 
         $context = \context_user::instance($USER->id);
@@ -970,7 +972,8 @@ class core_calendar_external extends external_api {
         $calendar = \calendar_information::create($time, $params['courseid'], $params['categoryid']);
         self::validate_context($calendar->context);
 
-        list($data, $template) = calendar_get_view($calendar, 'month', $params['includenavigation']);
+        $view = $params['mini'] ? 'mini' : 'month';
+        list($data, $template) = calendar_get_view($calendar, $view, $params['includenavigation']);
 
         return $data;
     }
@@ -994,6 +997,13 @@ class core_calendar_external extends external_api {
                     true,
                     NULL_ALLOWED
                 ),
+                'mini' => new external_value(
+                    PARAM_BOOL,
+                    'Whether to return the mini month view or not',
+                    VALUE_DEFAULT,
+                    false,
+                    NULL_ALLOWED
+                ),
             ]
         );
     }
index beac35f..e178f5f 100644 (file)
@@ -3483,6 +3483,7 @@ function calendar_get_view(\calendar_information $calendar, $view, $includenavig
         $month = new \core_calendar\external\month_exporter($calendar, $type, $related);
         $month->set_includenavigation($includenavigation);
         $month->set_initialeventsloaded(!$skipevents);
+        $month->set_showcoursefilter($view == "month");
         $data = $month->export($renderer);
     } else if ($view == "day") {
         $day = new \core_calendar\external\calendar_day_exporter($calendar, $related);
index e7929f8..53b6943 100644 (file)
@@ -35,6 +35,7 @@
     }} id="calendar-month-{{date.year}}-{{date.month}}-{{uniqid}}" {{!
     }} data-template="core_calendar/month_mini" {{!
     }} data-includenavigation="{{#includenavigation}}true{{/includenavigation}}{{^includenavigation}}false{{/includenavigation}}"{{!
+    }} data-mini="true"{{!
     }}>
     {{> core_calendar/month_mini}}
 </div>