MDL-65318 core_calendar: Additional fixes
authorJun Pataleta <jun@moodle.com>
Thu, 2 May 2019 04:32:14 +0000 (12:32 +0800)
committerSimey Lameze <simey@moodle.com>
Thu, 2 May 2019 06:19:28 +0000 (14:19 +0800)
* Move 'calendareventtype' property to event_exporter_base and
  rename it to 'normalisedeventtype'
* Add a 'normalisedeventtypetext' property to event_exporter_base
  for displaying the human-friendly text for the normalised
  event type.
* Clean up calendareventtype from other exporter/template locations
* Fix template names.

13 files changed:
calendar/amd/build/view_manager.min.js
calendar/amd/src/view_manager.js
calendar/classes/external/calendar_event_exporter.php
calendar/classes/external/event_exporter.php
calendar/classes/external/event_exporter_base.php
calendar/templates/calendar_day.mustache
calendar/templates/day_detailed.mustache
calendar/templates/event_details.mustache
calendar/templates/event_item.mustache
calendar/templates/event_list.mustache
calendar/templates/month_detailed.mustache
calendar/templates/month_mini.mustache
calendar/templates/upcoming_mini.mustache

index dd946d4..e615028 100644 (file)
Binary files a/calendar/amd/build/view_manager.min.js and b/calendar/amd/build/view_manager.min.js differ
index 2c59a72..7043f75 100644 (file)
@@ -339,28 +339,6 @@ define([
                 .fail(Notification.exception);
         };
 
-        /**
-         * Convert the given event type into one of either user, site,
-         * group, category, or course.
-         *
-         * @param {String} eventType The calendar event type
-         * @return {String}
-         */
-        var normaliseEventType = function(eventType) {
-            switch (eventType) {
-                case 'user':
-                    return 'user';
-                case 'site':
-                    return 'site';
-                case 'group':
-                    return 'group';
-                case 'category':
-                    return 'category';
-                default:
-                    return 'course';
-            }
-        };
-
         /**
          * Get the CSS class to apply for the given event type.
          *
@@ -368,7 +346,7 @@ define([
          * @return {String}
          */
         var getEventTypeClassFromType = function(eventType) {
-            return 'calendar_event_' + normaliseEventType(eventType);
+            return 'calendar_event_' + eventType;
         };
 
         /**
@@ -385,12 +363,9 @@ define([
                     throw new Error('Error encountered while trying to fetch calendar event with ID: ' + eventId);
                 }
                 var eventData = getEventResponse.event;
-                typeClass = getEventTypeClassFromType(eventData.eventtype);
+                typeClass = getEventTypeClassFromType(eventData.normalisedeventtype);
 
-                return getEventType(eventData.eventtype).then(function(eventType) {
-                    eventData.eventtype = eventType;
-                    return eventData;
-                });
+                return eventData;
             }).then(function(eventData) {
                 // Build the modal parameters from the event data.
                 var modalParams = {
@@ -422,19 +397,6 @@ define([
             }).fail(Notification.exception);
         };
 
-        /**
-         * Get the event type lang string.
-         *
-         * @param {String} eventType The event type.
-         * @return {promise} The lang string promise.
-         */
-        var getEventType = function(eventType) {
-            var lang = 'type' + normaliseEventType(eventType);
-            return Str.get_string(lang, 'core_calendar').then(function(langStr) {
-                return langStr;
-            });
-        };
-
         return {
             init: function(root) {
                 registerEventListeners(root);
index f4b629f..ea32de3 100644 (file)
@@ -52,9 +52,6 @@ class calendar_event_exporter extends event_exporter_base {
             'type' => PARAM_BOOL,
             'default' => false,
         ];
-        $values['calendareventtype'] = [
-            'type' => PARAM_TEXT,
-        ];
         $values['popupname'] = [
             'type' => PARAM_RAW,
         ];
@@ -172,8 +169,6 @@ class calendar_event_exporter extends event_exporter_base {
             $values['popupname'] = get_string('eventnameandcourse', 'calendar', $eventnameparams);
         }
 
-        $values['calendareventtype'] = $this->get_calendar_event_type();
-
         if ($event->get_course_module()) {
             $values = array_merge($values, $this->get_module_timestamp_limits($event));
         } else if ($hascourse && $course->id != SITEID && empty($event->get_group())) {
index 1f30a9d..015d71a 100644 (file)
@@ -55,7 +55,6 @@ class event_exporter extends event_exporter_base {
             'type' => event_action_exporter::read_properties_definition(),
             'optional' => true,
         ];
-        $values['calendareventtype'] = ['type' => PARAM_TEXT];
         return $values;
     }
 
@@ -73,7 +72,6 @@ class event_exporter extends event_exporter_base {
 
         $event = $this->event;
         $context = $this->related['context'];
-        $values['calendareventtype'] = $event->get_type();
         if ($moduleproxy = $event->get_course_module()) {
             $modulename = $moduleproxy->get('modname');
             $moduleid = $moduleproxy->get('id');
@@ -83,8 +81,6 @@ class event_exporter extends event_exporter_base {
             $params = array('update' => $moduleid, 'return' => true, 'sesskey' => sesskey());
             $editurl = new \moodle_url('/course/mod.php', $params);
             $values['editurl'] = $editurl->out(false);
-            // Activity events are normalised to "look" like course events.
-            $values['calendareventtype'] = 'course';
         } else if ($event->get_type() == 'category') {
             $url = $event->get_category()->get_proxied_instance()->get_view_link();
         } else if ($event->get_type() == 'course') {
index d20cfb3..b3fb837 100644 (file)
@@ -236,6 +236,12 @@ class event_exporter_base extends exporter {
                 'default' => null,
                 'null' => NULL_ALLOWED
             ],
+            'normalisedeventtype' => [
+                'type' => PARAM_TEXT
+            ],
+            'normalisedeventtypetext' => [
+                'type' => PARAM_TEXT
+            ],
         ];
     }
 
@@ -254,11 +260,14 @@ class event_exporter_base extends exporter {
         $values['isactionevent'] = false;
         $values['iscourseevent'] = false;
         $values['iscategoryevent'] = false;
+        $values['normalisedeventtype'] = $event->get_type();
         if ($moduleproxy = $event->get_course_module()) {
             // We need a separate property to flag if an event is action event.
             // That's required because canedit return true but action action events cannot be edited on the calendar UI.
             // But they are considered editable because you can drag and drop the event on the month view.
             $values['isactionevent'] = true;
+            // Activity events are normalised to "look" like course events.
+            $values['normalisedeventtype'] = 'course';
         } else if ($event->get_type() == 'course') {
             $values['iscourseevent'] = true;
         } else if ($event->get_type() == 'category') {
@@ -266,6 +275,7 @@ class event_exporter_base extends exporter {
         }
         $timesort = $event->get_times()->get_sort_time()->getTimestamp();
         $iconexporter = new event_icon_exporter($event, ['context' => $context]);
+        $values['normalisedeventtypetext'] = get_string('type' . $values['normalisedeventtype'], 'calendar');
 
         $values['icon'] = $iconexporter->export($output);
 
index 7d75b57..e82e42a 100644 (file)
@@ -15,7 +15,7 @@
     along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 }}
 {{!
-    @template calendar/calendar_day
+    @template core_calendar/calendar_day
 
     Calendar day view.
 
index 74d48bb..fde6b2f 100644 (file)
@@ -15,7 +15,7 @@
     along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 }}
 {{!
-    @template calendar/day_detailed
+    @template core_calendar/day_detailed
 
     Calendar day view.
 
index 3b17a9e..86fcda4 100644 (file)
@@ -33,7 +33,7 @@
     Example context (json):
     {
         "formattedtime": "Wednesday, 17 April, 9:27 AM",
-        "calendareventtype": "Group",
+        "normalisedeventtype": "Group",
         "description": "An random event description",
         "location": "Moodle HQ",
         "isactionevent": "true",
@@ -61,7 +61,7 @@
 </div>
 <div class="row mt-1">
     <div class="col-xs-1">{{#pix}} i/calendar, core, {{#str}} eventtype, core_calendar {{/str}} {{/pix}}</div>
-    <div class="col-xs-11">{{calendareventtype}}</div>
+    <div class="col-xs-11">{{normalisedeventtypetext}}</div>
 </div>
 {{#description}}
     <div class="row mt-1">
index a58f3ab..ccbf773 100644 (file)
@@ -31,7 +31,7 @@
     {
         "id": 1,
         "name": "Sample event name",
-        "calendareventtype": "course",
+        "normalisedeventtype": "course",
         "course": {
             "id": 1
         },
     }} data-course-id="{{course.id}}"{{!
     }} data-event-id="{{id}}"{{!
     }} class="event m-t-1"{{!
-    }} data-eventtype-{{calendareventtype}}="1"{{!
+    }} data-eventtype-{{normalisedeventtype}}="1"{{!
     }} data-event-title="{{name}}"{{!
     }} data-event-count="{{eventcount}}"{{!
     }}>
     <div class="card rounded">
-        <div class="box card-header clearfix calendar_event_{{calendareventtype}}">
+        <div class="box card-header clearfix calendar_event_{{normalisedeventtype}}">
             <div class="commands float-sm-right">
                 {{#canedit}}
                     {{#candelete}}
index f75157a..ae276ae 100644 (file)
@@ -15,7 +15,7 @@
     along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 }}
 {{!
-    @template calendar/event_list
+    @template core_calendar/event_list
 
     Calendar event list.
 
index 5041ca2..84ce421 100644 (file)
@@ -87,7 +87,7 @@
                                         {{/underway}}
                                         {{^underway}}
                                             <li data-region="event-item"
-                                                data-eventtype-{{calendareventtype}}="1"
+                                                data-eventtype-{{normalisedeventtype}}="1"
                                                 {{#draggable}}
                                                     draggable="true"
                                                     data-drag-type="move"
                                                 {{/draggable}}>
 
                                                 <a data-action="view-event" data-event-id="{{id}}" href="{{url}}" title="{{name}}">
-                                                    <span class="badge badge-circle calendar_event_{{calendareventtype}}">
+                                                    <span class="badge badge-circle calendar_event_{{normalisedeventtype}}">
                                                         &nbsp;
                                                     </span>
                                                     {{> core_calendar/event_icon}}
index 2a34335..b1aa06f 100644 (file)
                                 {{$nocontent}}{{#str}}eventnone, calendar{{/str}}{{/nocontent}}
                                 {{$content}}
                                     {{#events}}
-                                        <div data-popover-eventtype-{{calendareventtype}}="1">
+                                        <div data-popover-eventtype-{{normalisedeventtype}}="1">
                                             {{#modulename}}
                                                 {{#pix}} icon, {{modulename}} {{/pix}}
                                             {{/modulename}}
index 082d5bc..c952877 100644 (file)
@@ -41,7 +41,7 @@
     {{#events}}
         <div{{!
             }} class="event"{{!
-            }} data-eventtype-{{calendareventtype}}="1"{{!
+            }} data-eventtype-{{normalisedeventtype}}="1"{{!
             }} data-region="event-item"{{!
         }}>
             <span>{{#icon}}{{#pix}} {{key}}, {{component}}, {{alttext}} {{/pix}}{{/icon}}</span>