Skip to content

Commit

Permalink
MDL-67623 block overview: fix pagination regression
Browse files Browse the repository at this point in the history
Fixed a regression caused by MDL-64194 resulting in Dashboard - Course
overview pagination not working from second page of courses onwards.

Course overview block should now do the following:
- Display no pagination controls when user has no courses
- Display no pagination controls when less than 12 courses to display
- Only display pagination controls up to the number of courses user is
enrolled in
- Work correctly when on a page greater than the second page.
  • Loading branch information
Tom Dickman committed Dec 14, 2020
1 parent c307f3b commit c00fc97
Show file tree
Hide file tree
Showing 10 changed files with 239 additions and 50 deletions.
2 changes: 1 addition & 1 deletion blocks/myoverview/amd/build/view.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 blocks/myoverview/amd/build/view.min.js.map

Large diffs are not rendered by default.

15 changes: 7 additions & 8 deletions blocks/myoverview/amd/src/view.js
Expand Up @@ -543,11 +543,9 @@ function(

// Filter out all pagination options which are too large for the amount of courses user is enrolled in.
var totalCourseCount = parseInt(root.find(Selectors.courseView.region).attr('data-totalcoursecount'), 10);
if (totalCourseCount) {
itemsPerPage = itemsPerPage.filter(function(pagingOption) {
return pagingOption.value < totalCourseCount;
});
}
itemsPerPage = itemsPerPage.filter(function(pagingOption) {
return pagingOption.value < totalCourseCount || pagingOption.value === 0;
});

var filters = getFilterValues(root);
var config = $.extend({}, DEFAULT_PAGED_CONTENT_CONFIG);
Expand Down Expand Up @@ -602,7 +600,8 @@ function(
pageCourses = $.merge(loadedPages[currentPage].courses, courses.slice(0, nextPageStart));
}
} else {
nextPageStart = pageData.limit;
// When the page limit is zero, there is only one page of courses, no start for next page.
nextPageStart = pageData.limit || false;
pageCourses = (pageData.limit > 0) ? courses.slice(0, pageData.limit) : courses;
}

Expand All @@ -611,8 +610,8 @@ function(
courses: pageCourses
};

// Set up the next page
var remainingCourses = nextPageStart ? courses.slice(nextPageStart, courses.length) : [];
// Set up the next page (if there is more than one page).
var remainingCourses = nextPageStart !== false ? courses.slice(nextPageStart, courses.length) : [];
if (remainingCourses.length) {
loadedPages[currentPage + 1] = {
courses: remainingCourses
Expand Down
5 changes: 3 additions & 2 deletions blocks/myoverview/classes/output/main.php
Expand Up @@ -202,8 +202,9 @@ public function __construct($grouping, $sort, $view, $paging, $customfieldvalue
// Check and remember the given view.
$this->view = $view ? $view : BLOCK_MYOVERVIEW_VIEW_CARD;

// Check and remember the given page size.
if ($paging == BLOCK_MYOVERVIEW_PAGING_ALL) {
// Check and remember the given page size, `null` indicates no page size set
// while a `0` indicates a paging size of `All`.
if (!is_null($paging) && $paging == BLOCK_MYOVERVIEW_PAGING_ALL) {
$this->paging = BLOCK_MYOVERVIEW_PAGING_ALL;
} else {
$this->paging = $paging ? $paging : BLOCK_MYOVERVIEW_PAGING_12;
Expand Down

0 comments on commit c00fc97

Please sign in to comment.