Skip to content

Commit

Permalink
MDL-63457 block_myoverview: Bug fixes
Browse files Browse the repository at this point in the history
* Updated bootstrap theme to match boost
* Fix up logical errors in js
  • Loading branch information
Peter authored and andrewnicols committed Nov 2, 2018
1 parent fb3ab37 commit 645cb7d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 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.

33 changes: 29 additions & 4 deletions blocks/myoverview/amd/src/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ function(

var lastPage = 0;

var lastLimit = 0;

/**
* Get filter values from DOM.
*
Expand Down Expand Up @@ -268,7 +270,19 @@ function(
// Get the next page's data if loaded and pop the first element from it
if (loadedPages[jumpto + 1] != undefined) {
var newElement = loadedPages[jumpto + 1].courses.slice(0, 1);
loadedPages[jumpto + 1].courses = loadedPages[jumpto + 1].courses.slice(1);

// Adjust the dataset for the reset of the pages that are loaded
loadedPages.forEach(function(courseList, index) {
if (index > jumpto) {
var popElement = [];
if (loadedPages[index + 1] != undefined) {
popElement = loadedPages[index + 1].courses.slice(0, 1);
}

loadedPages[index].courses = $.merge(loadedPages[index].courses.slice(1), popElement);
}
});


reducedCourse = $.merge(reducedCourse, newElement);
}
Expand Down Expand Up @@ -381,13 +395,22 @@ function(
var currentPage = pageData.pageNumber;
var limit = pageData.limit;

// Reset local variables if limits have changed
if (lastLimit != limit) {
loadedPages = [];
courseOffset = 0;
lastPage = 0;
}

if (lastPage == currentPage) {
// If we are on the last page and have it's data then load it from cache
actions.allItemsLoaded(lastPage);
promises.push(renderCourses(root, loadedPages[currentPage]));
return;
}

lastLimit = limit;

// Get 2 pages worth of data as we will need it for the hidden functionality.
if (loadedPages[currentPage + 1] == undefined) {
if (loadedPages[currentPage] == undefined) {
Expand Down Expand Up @@ -423,9 +446,11 @@ function(

// Set up the next page
var remainingCourses = courses.slice(nextPageStart, courses.length);
loadedPages[currentPage + 1] = {
courses: remainingCourses
};
if (remainingCourses.length) {
loadedPages[currentPage + 1] = {
courses: remainingCourses
};
}

// Set the last page to either the current or next page
if (loadedPages[currentPage].courses.length < pageData.limit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@
{{#str}} removefromfavourites, block_myoverview {{/str}}
</a>
</li>
<li class="{{^hidden}}hidden{{/hidden}}" data-action="hide-course" data-course-id="{{id}}">
<li class="{{^hidden}}hidden{{/hidden}}" data-action="show-course" data-course-id="{{id}}">
<a class="dropdown-item p-a-1" href="#">
{{#str}} aria:hidecourse, block_myoverview, {{fullname}} {{/str}}
{{#pix}} i/show, core, {{#str}} hidden, block_myoverview {{/str}} {{/pix}}
{{#str}} show, block_myoverview {{/str}}
</a>
</li>
<li class="{{#hidden}}hidden{{/hidden}}" data-action="show-course" data-course-id="{{id}}">
<li class="{{#hidden}}hidden{{/hidden}}" data-action="hide-course" data-course-id="{{id}}">
<a class="dropdown-item p-a-1" href="#">
{{#str}} aria:showcourse, block_myoverview, {{fullname}} {{/str}}
{{#pix}} i/hide, core, {{#str}} hidden, block_myoverview {{/str}} {{/pix}}
{{#str}} hidecourse, block_myoverview {{/str}}
</a>
</li>
</ul>
Expand Down

0 comments on commit 645cb7d

Please sign in to comment.