MDL-71817 calendar: Set the calendar view mode properly for month view

* Store the view mode of the calendar in the calendar_information
   object.
 * Let the month exporter handle the production of context data by
   moving 'viewingmonth', 'showviewselector', and 'viewinginblock'
   inside it.
 * Set the proper calendar view mode in the core_calendar/month_detailed
   template.
 * Pass the calendar view mode to the
   core_calendar_get_calendar_monthly_view WS function.
This commit is contained in:
Jun Pataleta
2021-07-22 09:04:44 +08:00
committed by Simey Lameze
parent d748c71693
commit 8a2c797cc0
10 changed files with 63 additions and 23 deletions
+1 -1
View File
@@ -1,2 +1,2 @@
define ("core_calendar/repository",["exports","core/ajax"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.getCourseGroupsData=a.getCalendarUpcomingData=a.updateEventStartDay=a.getCalendarDayData=a.getCalendarMonthData=a.submitCreateUpdateForm=a.getEventById=a.deleteEvent=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);var c=function(a){var c=1<arguments.length&&arguments[1]!==void 0?arguments[1]:!1;return b.default.call([{methodname:"core_calendar_delete_calendar_events",args:{events:[{eventid:a,repeat:c}]}}])[0]};a.deleteEvent=c;var d=function(a){return b.default.call([{methodname:"core_calendar_get_calendar_event_by_id",args:{eventid:a}}])[0]};a.getEventById=d;var e=function(a){return b.default.call([{methodname:"core_calendar_submit_create_update_form",args:{formdata:a}}])[0]};a.submitCreateUpdateForm=e;var f=function(a,c,d,e,f,g){var h=6<arguments.length&&arguments[6]!==void 0?arguments[6]:1;return b.default.call([{methodname:"core_calendar_get_calendar_monthly_view",args:{year:a,month:c,courseid:d,categoryid:e,includenavigation:f,mini:g,day:h}}])[0]};a.getCalendarMonthData=f;var g=function(a,c,d,e,f){return b.default.call([{methodname:"core_calendar_get_calendar_day_view",args:{year:a,month:c,day:d,courseid:e,categoryid:f}}])[0]};a.getCalendarDayData=g;var h=function(a,c){return b.default.call([{methodname:"core_calendar_update_event_start_day",args:{eventid:a,daytimestamp:c}}])[0]};a.updateEventStartDay=h;var i=function(a,c){return b.default.call([{methodname:"core_calendar_get_calendar_upcoming_view",args:{courseid:a,categoryid:c}}])[0]};a.getCalendarUpcomingData=i;var j=function(a){return b.default.call([{methodname:"core_group_get_course_groups",args:{courseid:a}}])[0]};a.getCourseGroupsData=j});
define ("core_calendar/repository",["exports","core/ajax"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.getCourseGroupsData=a.getCalendarUpcomingData=a.updateEventStartDay=a.getCalendarDayData=a.getCalendarMonthData=a.submitCreateUpdateForm=a.getEventById=a.deleteEvent=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);var c=function(a){var c=1<arguments.length&&arguments[1]!==void 0?arguments[1]:!1;return b.default.call([{methodname:"core_calendar_delete_calendar_events",args:{events:[{eventid:a,repeat:c}]}}])[0]};a.deleteEvent=c;var d=function(a){return b.default.call([{methodname:"core_calendar_get_calendar_event_by_id",args:{eventid:a}}])[0]};a.getEventById=d;var e=function(a){return b.default.call([{methodname:"core_calendar_submit_create_update_form",args:{formdata:a}}])[0]};a.submitCreateUpdateForm=e;var f=function(a,c,d,e,f,g){var h=6<arguments.length&&arguments[6]!==void 0?arguments[6]:1,i=7<arguments.length&&arguments[7]!==void 0?arguments[7]:"month";return b.default.call([{methodname:"core_calendar_get_calendar_monthly_view",args:{year:a,month:c,courseid:d,categoryid:e,includenavigation:f,mini:g,day:h,view:i}}])[0]};a.getCalendarMonthData=f;var g=function(a,c,d,e,f){return b.default.call([{methodname:"core_calendar_get_calendar_day_view",args:{year:a,month:c,day:d,courseid:e,categoryid:f}}])[0]};a.getCalendarDayData=g;var h=function(a,c){return b.default.call([{methodname:"core_calendar_update_event_start_day",args:{eventid:a,daytimestamp:c}}])[0]};a.updateEventStartDay=h;var i=function(a,c){return b.default.call([{methodname:"core_calendar_get_calendar_upcoming_view",args:{courseid:a,categoryid:c}}])[0]};a.getCalendarUpcomingData=i;var j=function(a){return b.default.call([{methodname:"core_group_get_course_groups",args:{courseid:a}}])[0]};a.getCourseGroupsData=j});
//# sourceMappingURL=repository.min.js.map
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+3 -1
View File
@@ -92,9 +92,10 @@ export const submitCreateUpdateForm = (formData) => {
* @param {boolean} includeNavigation Whether to include navigation.
* @param {boolean} mini Whether the month is in mini view.
* @param {number} day Day (optional)
* @param {string} view The calendar view mode.
* @return {promise} Resolved with the month view data.
*/
export const getCalendarMonthData = (year, month, courseId, categoryId, includeNavigation, mini, day = 1) => {
export const getCalendarMonthData = (year, month, courseId, categoryId, includeNavigation, mini, day = 1, view = 'month') => {
const request = {
methodname: 'core_calendar_get_calendar_monthly_view',
args: {
@@ -105,6 +106,7 @@ export const getCalendarMonthData = (year, month, courseId, categoryId, includeN
includenavigation: includeNavigation,
mini,
day,
view,
}
};
+3 -4
View File
@@ -83,7 +83,7 @@ const registerEventListeners = (root) => {
const categoryId = wrapper.data('categoryid');
const link = e.currentTarget;
if (view === 'month') {
if (view === 'month' || view === 'monthblock') {
changeMonth(root, link.href, link.dataset.year, link.dataset.month, courseId, categoryId, link.dataset.day);
e.preventDefault();
} else if (view === 'day') {
@@ -152,10 +152,9 @@ export const refreshMonthContent = (root, year, month, courseId, categoryId, tar
M.util.js_pending([root.get('id'), year, month, courseId].join('-'));
const includenavigation = root.data('includenavigation');
const mini = root.data('mini');
return CalendarRepository.getCalendarMonthData(year, month, courseId, categoryId, includenavigation, mini, day)
const viewMode = target.data('view');
return CalendarRepository.getCalendarMonthData(year, month, courseId, categoryId, includenavigation, mini, day, viewMode)
.then(context => {
context.viewingmonth = true;
context.showviewselector = !mini;
return Templates.render(template, context);
})
.then((html, js) => {
+17 -1
View File
@@ -204,6 +204,18 @@ class month_exporter extends exporter {
'type' => PARAM_INT,
'default' => 0,
],
'viewingmonth' => [
'type' => PARAM_BOOL,
'default' => true,
],
'showviewselector' => [
'type' => PARAM_BOOL,
'default' => true,
],
'viewinginblock' => [
'type' => PARAM_BOOL,
'default' => false,
],
];
}
@@ -224,11 +236,13 @@ class month_exporter extends exporter {
$previousperiodlink = new moodle_url($this->url);
$previousperiodlink->param('time', $previousperiod[0]);
$viewmode = $this->calendar->get_viewmode() ?? 'month';
$return = [
'courseid' => $this->calendar->courseid,
'weeks' => $this->get_weeks($output),
'daynames' => $this->get_day_names($output),
'view' => 'month',
'view' => $viewmode,
'date' => (new date_exporter($date))->export($output),
'periodname' => userdate($this->calendar->time, get_string('strftimemonthyear')),
'previousperiod' => (new date_exporter($previousperiod))->export($output),
@@ -242,6 +256,8 @@ class month_exporter extends exporter {
'includenavigation' => $this->includenavigation,
'initialeventsloaded' => $this->initialeventsloaded,
'calendarinstanceid' => $this->calendarinstanceid,
'showviewselector' => $viewmode === 'month',
'viewinginblock' => $viewmode === 'monthblock',
];
if ($this->showcoursefilter) {
+13 -9
View File
@@ -984,16 +984,18 @@ class core_calendar_external extends external_api {
/**
* Get data for the monthly calendar view.
*
* @param int $year The year to be shown
* @param int $month The month to be shown
* @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
* @param int $day The day we want to keep as the current day
* @param int $year The year to be shown
* @param int $month The month to be shown
* @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
* @param int $day The day we want to keep as the current day
* @param string|null $view The view mode for the calendar.
* @return array
*/
public static function get_calendar_monthly_view($year, $month, $courseid, $categoryid, $includenavigation, $mini, $day) {
public static function get_calendar_monthly_view($year, $month, $courseid, $categoryid, $includenavigation, $mini, $day,
?string $view = null) {
global $USER, $PAGE;
// Parameter validation.
@@ -1005,6 +1007,7 @@ class core_calendar_external extends external_api {
'includenavigation' => $includenavigation,
'mini' => $mini,
'day' => $day,
'view' => $view,
]);
$context = \context_user::instance($USER->id);
@@ -1017,7 +1020,7 @@ class core_calendar_external extends external_api {
$calendar = \calendar_information::create($time, $params['courseid'], $params['categoryid']);
self::validate_context($calendar->context);
$view = $params['mini'] ? 'mini' : 'month';
$view = $params['view'] ?? ($params['mini'] ? 'mini' : 'month');
list($data, $template) = calendar_get_view($calendar, $view, $params['includenavigation']);
return $data;
@@ -1050,6 +1053,7 @@ class core_calendar_external extends external_api {
NULL_ALLOWED
),
'day' => new external_value(PARAM_INT, 'Day to be viewed', VALUE_DEFAULT, 1),
'view' => new external_value(PARAM_ALPHA, 'The view mode of the calendar', VALUE_DEFAULT, 'month', NULL_ALLOWED),
]
);
}
+22 -3
View File
@@ -1057,6 +1057,9 @@ class calendar_information {
/** @var context The anticipated context that the calendar is viewed in */
public $context = null;
/** @var string The calendar's view mode. */
protected $viewmode;
/**
* Creates a new instance
*
@@ -1316,6 +1319,24 @@ class calendar_information {
$block->title = get_string('monthlyview', 'calendar');
$renderer->add_pretend_calendar_block($block, BLOCK_POS_RIGHT);
}
/**
* Getter method for the calendar's view mode.
*
* @return string
*/
public function get_viewmode(): string {
return $this->viewmode;
}
/**
* Setter method for the calendar's view mode.
*
* @param string $viewmode
*/
public function set_viewmode(string $viewmode): void {
$this->viewmode = $viewmode;
}
}
/**
@@ -3493,15 +3514,13 @@ function calendar_get_view(\calendar_information $calendar, $view, $includenavig
];
$data = [];
$calendar->set_viewmode($view);
if ($view == "month" || $view == "monthblock" || $view == "mini" || $view == "minithree" ) {
$month = new \core_calendar\external\month_exporter($calendar, $type, $related);
$month->set_includenavigation($includenavigation);
$month->set_initialeventsloaded(!$skipevents);
$month->set_showcoursefilter(($view == "month" || $view == "monthblock"));
$data = $month->export($renderer);
$data->viewingmonth = true;
$data->showviewselector = ($view == "month");
$data->viewinginblock = ($view == "monthblock");
} else if ($view == "day") {
$day = new \core_calendar\external\calendar_day_exporter($calendar, $related);
$data = $day->export($renderer);
+1 -1
View File
@@ -38,7 +38,7 @@
}} data-context-id="{{defaulteventcontext}}"{{!
}} data-month="{{date.mon}}"{{!
}} data-year="{{date.year}}"{{!
}} data-view="month"{{!
}} data-view="{{view}}"{{!
}}>
{{> core_calendar/month_navigation }}
{{> core/overlay_loading}}