From ab709ed274dbae5a9c0d1f03a0b525ef093e792a Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Thu, 2 May 2019 12:32:14 +0800 Subject: [PATCH] MDL-65318 core_calendar: Additional fixes * 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. --- calendar/amd/build/view_manager.min.js | Bin 4280 -> 3977 bytes calendar/amd/src/view_manager.js | 44 ++---------------- .../external/calendar_event_exporter.php | 5 -- calendar/classes/external/event_exporter.php | 4 -- .../classes/external/event_exporter_base.php | 10 ++++ calendar/templates/calendar_day.mustache | 2 +- calendar/templates/day_detailed.mustache | 2 +- calendar/templates/event_details.mustache | 4 +- calendar/templates/event_item.mustache | 6 +-- calendar/templates/event_list.mustache | 2 +- calendar/templates/month_detailed.mustache | 4 +- calendar/templates/month_mini.mustache | 2 +- calendar/templates/upcoming_mini.mustache | 2 +- 13 files changed, 25 insertions(+), 62 deletions(-) diff --git a/calendar/amd/build/view_manager.min.js b/calendar/amd/build/view_manager.min.js index dd946d4f9fd411fe5c817757f98a0497c8494e05..e61502877e88c2f5e06faa07f262be0a0aed4b7b 100644 GIT binary patch delta 63 zcmdm?*eSn(nTfG%GYiuSuF3Aa5-f?eI%Sj7csEIvYNY7p7o^JknaB(Mwskv$bN delta 312 zcmYk1%}T>S6oqLl2vRFnyG{+U#HT#+y-=iu^UAJ?xZofv4m$sYZWYhkQe(viypJR=h zdAGqtZqH>q8Q$HV*%`>(C5O-Jm%+2#W-F@|mzDPCYM|*d6Fx-De0~}}PSw0XUKplQ Y7x7YdTL>2l)~ItJ;Ts}w?f-ax1abFop8x;= diff --git a/calendar/amd/src/view_manager.js b/calendar/amd/src/view_manager.js index 2c59a72ba6d..7043f75e355 100644 --- a/calendar/amd/src/view_manager.js +++ b/calendar/amd/src/view_manager.js @@ -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); diff --git a/calendar/classes/external/calendar_event_exporter.php b/calendar/classes/external/calendar_event_exporter.php index f4b629f204e..ea32de3521a 100644 --- a/calendar/classes/external/calendar_event_exporter.php +++ b/calendar/classes/external/calendar_event_exporter.php @@ -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())) { diff --git a/calendar/classes/external/event_exporter.php b/calendar/classes/external/event_exporter.php index 1f30a9d2a17..015d71acb77 100644 --- a/calendar/classes/external/event_exporter.php +++ b/calendar/classes/external/event_exporter.php @@ -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') { diff --git a/calendar/classes/external/event_exporter_base.php b/calendar/classes/external/event_exporter_base.php index d20cfb3d093..b3fb837be21 100644 --- a/calendar/classes/external/event_exporter_base.php +++ b/calendar/classes/external/event_exporter_base.php @@ -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); diff --git a/calendar/templates/calendar_day.mustache b/calendar/templates/calendar_day.mustache index 7d75b5779f6..e82e42a1b63 100644 --- a/calendar/templates/calendar_day.mustache +++ b/calendar/templates/calendar_day.mustache @@ -15,7 +15,7 @@ along with Moodle. If not, see . }} {{! - @template calendar/calendar_day + @template core_calendar/calendar_day Calendar day view. diff --git a/calendar/templates/day_detailed.mustache b/calendar/templates/day_detailed.mustache index 74d48bb4342..fde6b2f4417 100644 --- a/calendar/templates/day_detailed.mustache +++ b/calendar/templates/day_detailed.mustache @@ -15,7 +15,7 @@ along with Moodle. If not, see . }} {{! - @template calendar/day_detailed + @template core_calendar/day_detailed Calendar day view. diff --git a/calendar/templates/event_details.mustache b/calendar/templates/event_details.mustache index 3b17a9ea494..86fcda4cc9b 100644 --- a/calendar/templates/event_details.mustache +++ b/calendar/templates/event_details.mustache @@ -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 @@
{{#pix}} i/calendar, core, {{#str}} eventtype, core_calendar {{/str}} {{/pix}}
-
{{calendareventtype}}
+
{{normalisedeventtypetext}}
{{#description}}
diff --git a/calendar/templates/event_item.mustache b/calendar/templates/event_item.mustache index a58f3ab8f97..ccbf7739e85 100644 --- a/calendar/templates/event_item.mustache +++ b/calendar/templates/event_item.mustache @@ -31,7 +31,7 @@ { "id": 1, "name": "Sample event name", - "calendareventtype": "course", + "normalisedeventtype": "course", "course": { "id": 1 }, @@ -52,12 +52,12 @@ }} 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}}"{{! }}>
-
+
{{#canedit}} {{#candelete}} diff --git a/calendar/templates/event_list.mustache b/calendar/templates/event_list.mustache index f75157a80ad..ae276ae2047 100644 --- a/calendar/templates/event_list.mustache +++ b/calendar/templates/event_list.mustache @@ -15,7 +15,7 @@ along with Moodle. If not, see . }} {{! - @template calendar/event_list + @template core_calendar/event_list Calendar event list. diff --git a/calendar/templates/month_detailed.mustache b/calendar/templates/month_detailed.mustache index 5041ca2abae..84ce421e89e 100644 --- a/calendar/templates/month_detailed.mustache +++ b/calendar/templates/month_detailed.mustache @@ -87,7 +87,7 @@ {{/underway}} {{^underway}}
  • - +   {{> core_calendar/event_icon}} diff --git a/calendar/templates/month_mini.mustache b/calendar/templates/month_mini.mustache index 2a34335462c..b1aa06f1b14 100644 --- a/calendar/templates/month_mini.mustache +++ b/calendar/templates/month_mini.mustache @@ -135,7 +135,7 @@ {{$nocontent}}{{#str}}eventnone, calendar{{/str}}{{/nocontent}} {{$content}} {{#events}} -
    +
    {{#modulename}} {{#pix}} icon, {{modulename}} {{/pix}} {{/modulename}} diff --git a/calendar/templates/upcoming_mini.mustache b/calendar/templates/upcoming_mini.mustache index 082d5bcd922..c95287773c7 100644 --- a/calendar/templates/upcoming_mini.mustache +++ b/calendar/templates/upcoming_mini.mustache @@ -41,7 +41,7 @@ {{#events}} {{#icon}}{{#pix}} {{key}}, {{component}}, {{alttext}} {{/pix}}{{/icon}} -- 2.43.0