Skip to content

Commit

Permalink
MDL-59890 calendar: Display category events on calendars
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Oct 3, 2017
1 parent 5ba6507 commit d0e56d8
Show file tree
Hide file tree
Showing 29 changed files with 189 additions and 55 deletions.
15 changes: 14 additions & 1 deletion blocks/calendar_month/block_calendar_month.php
Expand Up @@ -51,11 +51,24 @@ public function get_content() {
$courseid = $this->page->course->id;
$issite = ($courseid == SITEID);

$course = null;
$courses = null;
$categories = null;

if ($issite) {
// Being displayed at site level. This will cause the filter to fall back to auto-detecting
// the list of courses it will be grabbing events from.
$course = get_site();
$courses = calendar_get_default_courses();

if ($this->page->context->contextlevel === CONTEXT_COURSECAT) {
// Restrict to categories, and their parents, and the courses that the user is enrolled in within those
// categories.
$categories = array_keys($this->page->categories);
$courses = array_filter($courses, function($course) use ($categories) {
return array_search($course->category, $categories) !== false;
});
}
} else {
// Forcibly filter events to include only those from the particular course we are in.
$course = $this->page->course;
Expand All @@ -65,7 +78,7 @@ public function get_content() {
$renderer = $this->page->get_renderer('core_calendar');

$calendar = new calendar_information();
$calendar->prepare_for_view($course, $courses);
$calendar->set_sources($course, $courses, $this->page->category);

list($data, $template) = calendar_get_view($calendar, 'mini');
$this->content->text .= $renderer->render_from_template($template, $data);
Expand Down
2 changes: 1 addition & 1 deletion calendar/amd/build/calendar.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion calendar/amd/build/calendar_threemonth.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion calendar/amd/build/repository.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion calendar/amd/build/selectors.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion calendar/amd/build/view_manager.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion calendar/amd/src/calendar.js
Expand Up @@ -287,7 +287,7 @@ define([
root.on('change', SELECTORS.COURSE_SELECTOR, function() {
var selectElement = $(this);
var courseId = selectElement.val();
CalendarViewManager.reloadCurrentMonth(root, courseId)
CalendarViewManager.reloadCurrentMonth(root, courseId, null)
.then(function() {
// We need to get the selector again because the content has changed.
return root.find(SELECTORS.COURSE_SELECTOR).val(courseId);
Expand Down
13 changes: 9 additions & 4 deletions calendar/amd/src/calendar_threemonth.js
Expand Up @@ -24,13 +24,15 @@
*/
define([
'jquery',
'core/notification',
'core_calendar/selectors',
'core_calendar/events',
'core/templates',
'core_calendar/view_manager',
],
function(
$,
Notification,
CalendarSelectors,
CalendarEvents,
Templates,
Expand All @@ -45,18 +47,20 @@ function(
*/
var registerCalendarEventListeners = function(root) {
var body = $('body');
body.on(CalendarEvents.monthChanged, function(e, year, month, courseId) {
body.on(CalendarEvents.monthChanged, function(e, year, month, courseId, categoryId) {
// We have to use a queue here because the calling code is decoupled from these listeners.
// It's possible for the event to be called multiple times before one call is fully resolved.
root.queue(function(next) {
return processRequest(e, year, month, courseId)
return processRequest(e, year, month, courseId, categoryId)
.then(function() {
return next();
});
})
.fail(Notification.exception)
;
});
});

var processRequest = function(e, year, month, courseId) {
var processRequest = function(e, year, month, courseId, categoryId) {
var newCurrentMonth = root.find('[data-year="' + year + '"][data-month="' + month + '"]');
var newParent = newCurrentMonth.closest(CalendarSelectors.calendarPeriods.month);
var allMonths = root.find(CalendarSelectors.calendarPeriods.month);
Expand Down Expand Up @@ -95,6 +99,7 @@ function(
requestYear,
requestMonth,
courseId,
categoryId,
placeHolder
)
.then(function() {
Expand Down

0 comments on commit d0e56d8

Please sign in to comment.