Merge branch 'MDL-64860-38_block_myoverview_improve_pagination' of https://github.com/tomdickman/moodle

This commit is contained in:
Sara Arjona
2019-07-30 14:52:20 +08:00
12 changed files with 54 additions and 35 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+20 -15
View File
@@ -67,7 +67,7 @@ function(
NOCOURSES: 'core_course/no-courses'
};
var NUMCOURSES_PERPAGE = [12, 24, 48];
var NUMCOURSES_PERPAGE = [12, 24, 48, 96, 0];
var loadedPages = [];
@@ -421,19 +421,24 @@ function(
var initializePagedContent = function(root) {
namespace = "block_myoverview_" + root.attr('id') + "_" + Math.random();
var itemsPerPage = NUMCOURSES_PERPAGE;
var pagingLimit = parseInt(root.find(Selectors.courseView.region).attr('data-paging'), 10);
if (pagingLimit) {
itemsPerPage = NUMCOURSES_PERPAGE.map(function(value) {
var active = false;
if (value == pagingLimit) {
active = true;
}
var itemsPerPage = NUMCOURSES_PERPAGE.map(function(value) {
var active = false;
if (value == pagingLimit) {
active = true;
}
return {
value: value,
active: active
};
return {
value: value,
active: active
};
});
// 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;
});
}
@@ -448,7 +453,7 @@ function(
pagesData.forEach(function(pageData) {
var currentPage = pageData.pageNumber;
var limit = pageData.limit;
var limit = (pageData.limit > 0) ? pageData.limit : 0;
// Reset local variables if limits have changed
if (lastLimit != limit) {
@@ -491,7 +496,7 @@ function(
}
} else {
nextPageStart = pageData.limit;
pageCourses = courses.slice(0, pageData.limit);
pageCourses = (pageData.limit > 0) ? courses.slice(0, pageData.limit) : courses;
}
// Finished setting up the current page
@@ -500,7 +505,7 @@ function(
};
// Set up the next page
var remainingCourses = courses.slice(nextPageStart, courses.length);
var remainingCourses = nextPageStart ? courses.slice(nextPageStart, courses.length) : [];
if (remainingCourses.length) {
loadedPages[currentPage + 1] = {
courses: remainingCourses
+9 -1
View File
@@ -94,7 +94,11 @@ class main implements renderable, templatable {
public function __construct($grouping, $sort, $view, $paging) {
$this->grouping = $grouping ? $grouping : BLOCK_MYOVERVIEW_GROUPING_ALL;
$this->sort = $sort ? $sort : BLOCK_MYOVERVIEW_SORTING_TITLE;
$this->paging = $paging ? $paging : BLOCK_MYOVERVIEW_PAGING_12;
if ($paging == BLOCK_MYOVERVIEW_PAGING_ALL) {
$this->paging = BLOCK_MYOVERVIEW_PAGING_ALL;
} else {
$this->paging = $paging ? $paging : BLOCK_MYOVERVIEW_PAGING_12;
}
$config = get_config('block_myoverview');
if (!$config->displaycategories) {
@@ -178,8 +182,11 @@ class main implements renderable, templatable {
*
* @param \renderer_base $output
* @return array Context variables for the template
* @throws \coding_exception
*
*/
public function export_for_template(renderer_base $output) {
global $USER;
$nocoursesurl = $output->image_url('courses', 'block_myoverview')->out();
@@ -187,6 +194,7 @@ class main implements renderable, templatable {
$availablelayouts = $this->get_formatted_available_layouts_for_export();
$defaultvariables = [
'totalcoursecount' => count(enrol_get_all_users_courses($USER->id, true)),
'nocoursesimg' => $nocoursesurl,
'grouping' => $this->grouping,
'sort' => $this->sort == BLOCK_MYOVERVIEW_SORTING_TITLE ? 'fullname' : 'ul.timeaccess desc',
+5 -1
View File
@@ -54,6 +54,8 @@ define('BLOCK_MYOVERVIEW_VIEW_SUMMARY', 'summary');
define('BLOCK_MYOVERVIEW_PAGING_12', 12);
define('BLOCK_MYOVERVIEW_PAGING_24', 24);
define('BLOCK_MYOVERVIEW_PAGING_48', 48);
define('BLOCK_MYOVERVIEW_PAGING_96', 96);
define('BLOCK_MYOVERVIEW_PAGING_ALL', 0);
/**
* Constants for the admin category display setting
@@ -115,7 +117,9 @@ function block_myoverview_user_preferences() {
'choices' => array(
BLOCK_MYOVERVIEW_PAGING_12,
BLOCK_MYOVERVIEW_PAGING_24,
BLOCK_MYOVERVIEW_PAGING_48
BLOCK_MYOVERVIEW_PAGING_48,
BLOCK_MYOVERVIEW_PAGING_96,
BLOCK_MYOVERVIEW_PAGING_ALL
)
);
@@ -35,6 +35,7 @@
data-prev-display="{{view}}"
data-paging="{{paging}}"
data-nocoursesimg="{{nocoursesimg}}"
data-totalcoursecount="{{totalcoursecount}}"
data-displaycategories="{{displaycategories}}">
<div data-region="course-view-content">
{{> block_myoverview/placeholders }}
@@ -38,20 +38,20 @@ Feature: The my overview block allows users to persistence of their page limits
Scenario: Toggle the page limit between page reloads
Given I log in as "student1"
When I click on "Show 12 items per page" "button" in the "Course overview" "block"
And I click on "24" "link"
Then I should see "Course 9"
When I click on "[data-toggle='dropdown']" "css_element" in the "Course overview" "block"
And I click on "All" "link"
Then I should see "Course 13"
And I reload the page
Then I should see "Course 9"
And I should see "24" in the "[data-action='limit-toggle']" "css_element"
Then I should see "Course 13"
And I should see "All" in the "[data-action='limit-toggle']" "css_element"
And I log out
Scenario: Toggle the page limit between grouping changes
Given I log in as "student1"
When I click on "Show 12 items per page" "button" in the "Course overview" "block"
And I click on "24" "link"
When I click on "[data-toggle='dropdown']" "css_element" in the "Course overview" "block"
And I click on "All" "link"
And I click on "All" "button" in the "Course overview" "block"
And I click on "In progress" "link" in the "Course overview" "block"
Then I should see "Course 9"
And I should see "24" in the "[data-action='limit-toggle']" "css_element"
Then I should see "Course 13"
And I should see "All" in the "[data-action='limit-toggle']" "css_element"
And I log out
+1 -1
View File
@@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2019060400; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2019070400; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2019051100; // Requires this Moodle version.
$plugin->component = 'block_myoverview'; // Full name of the plugin (used for diagnostics).
+1 -1
View File
@@ -1,2 +1,2 @@
define ("core/paged_content_factory",["jquery","core/templates","core/notification","core/paged_content","core/paged_content_events","core/pubsub","core/ajax"],function(a,b,c,d,e,f,g){var h={PAGED_CONTENT:"core/paged_content"},j={ITEMS_PER_PAGE_SINGLE:25,ITEMS_PER_PAGE_ARRAY:[25,50,100,0],MAX_PAGES:3},k=function(){return{pagingbar:!1,pagingdropdown:!1,skipjs:!0,ignorecontrolwhileloading:!0,controlplacementbottom:!1}},l=function(){return{showitemsperpageselector:!1,itemsperpage:35,previous:!0,next:!0,activepagenumber:1,hidecontrolonsinglepage:!0,pages:[]}},m=function(a,b){var c=1;if(0<a){var d=a%b;if(d){a-=d;c=a/b+1}else{c=a/b}}return c},n=function(b,c){if(null===c){c=j.ITEMS_PER_PAGE_SINGLE}if(a.isArray(c)){c=c[0]}var d=l();d.itemsperpage=c;for(var e=m(b,c),f=1,g;f<=e;f++){g={number:f,page:""+f};if(1==f){g.active=!0}d.pages.push(g)}return d},o=function(b){if(a.isArray(b)){var c=b.map(function(a){if("number"==typeof a){return{value:a,active:!1}}else{return a}}),d=c.filter(function(a){return a.active});if(!d.length){c[0].active=!0}return c}else{return b}},p=function(b){if(null===b){b=j.ITEMS_PER_PAGE_ARRAY}var c=l();c.itemsperpage=o(b);c.showitemsperpageselector=a.isArray(b);return c},q=function(a,b){if(a){return n(a,b)}else{return p(b)}},r=function(b,c){if(null===b){b=j.ITEMS_PER_PAGE_SINGLE}if(a.isArray(b)){return{options:b}}var d={options:[]},e=0,f=0,g=j.MAX_PAGES;if(c.hasOwnProperty("maxPages")){g=c.maxPages}for(var h=1,k;h<=g;h++){k=0;if(2>=h){k=b;f=b}else{f=2*f;k=f}e+=k;var l={itemcount:k,content:e};if(1==h){l.active=!0}d.options.push(l)}return d},s=function(a,b,c){var d=k();if(c.hasOwnProperty("ignoreControlWhileLoading")){d.ignorecontrolwhileloading=c.ignoreControlWhileLoading}if(c.hasOwnProperty("controlPlacementBottom")){d.controlplacementbottom=c.controlPlacementBottom}if(c.hasOwnProperty("hideControlOnSinglePage")){d.hidecontrolonsinglepage=c.hideControlOnSinglePage}if(c.hasOwnProperty("ariaLabels")){d.arialabels=c.ariaLabels}if(c.hasOwnProperty("dropdown")&&c.dropdown){d.pagingdropdown=r(b,c)}else{d.pagingbar=q(a,b)}return d},t=function(e,f,g,i){i=i||{};var j=a.Deferred(),k=s(e,f,i);b.render(h.PAGED_CONTENT,k).then(function(b,c){b=a(b);var e=b.attr("id");if(i.hasOwnProperty("eventNamespace")){e=i.eventNamespace}var f=b;d.init(f,g,e);v(e,i);j.resolve(b,c)}).fail(function(a){j.reject(a)}).fail(c.exception);return j.promise()},u=function(a){return function callback(b){g.call([{methodname:"core_user_update_user_preferences",args:{preferences:[{type:a,value:b}]}}])}},v=function(a,b){if(b.hasOwnProperty("persistentLimitKey")){f.subscribe(a+e.SET_ITEMS_PER_PAGE_LIMIT,u(b.persistentLimitKey))}};return{create:function create(a,b){return t(null,null,a,b)},createWithLimit:function createWithLimit(a,b,c){return t(null,a,b,c)},createWithTotalAndLimit:t,createFromStaticList:function createFromStaticList(a,b,c,d){if("undefined"==typeof d){d={}}var e=a.length;return t(e,b,function(b){var d=[];b.forEach(function(b){var c=b.offset,f=b.limit?c+b.limit:e,g=a.slice(c,f);d.push(g)});return c(d)},d)},createFromAjax:t,resetLastPageNumber:function resetLastPageNumber(a,b){f.publish(a+e.ALL_ITEMS_LOADED,b)}}});
define ("core/paged_content_factory",["jquery","core/templates","core/notification","core/paged_content","core/paged_content_events","core/pubsub","core/ajax"],function(a,b,c,d,e,f,g){var h={PAGED_CONTENT:"core/paged_content"},j={ITEMS_PER_PAGE_SINGLE:25,ITEMS_PER_PAGE_ARRAY:[25,50,100,0],MAX_PAGES:3},k=function(){return{pagingbar:!1,pagingdropdown:!1,skipjs:!0,ignorecontrolwhileloading:!0,controlplacementbottom:!1}},l=function(){return{showitemsperpageselector:!1,itemsperpage:35,previous:!0,next:!0,activepagenumber:1,hidecontrolonsinglepage:!0,pages:[]}},m=function(a,b){var c=1;if(0<a){var d=a%b;if(d){a-=d;c=a/b+1}else{c=a/b}}return c},n=function(b,c){if(null===c){c=j.ITEMS_PER_PAGE_SINGLE}if(a.isArray(c)){c=c[0]}var d=l();d.itemsperpage=c;for(var e=m(b,c),f=1,g;f<=e;f++){g={number:f,page:""+f};if(1==f){g.active=!0}d.pages.push(g)}return d},o=function(b){if(a.isArray(b)){var c=b.map(function(a){if("number"==typeof a){return{value:a,active:!1}}else{return a}}),d=c.filter(function(a){return a.active});if(!d.length){c[0].active=!0}return c}else{return b}},p=function(b){if(null===b){b=j.ITEMS_PER_PAGE_ARRAY}var c=l();c.itemsperpage=o(b);c.showitemsperpageselector=a.isArray(b)&&1<b.length;return c},q=function(a,b){if(a){return n(a,b)}else{return p(b)}},r=function(b,c){if(null===b){b=j.ITEMS_PER_PAGE_SINGLE}if(a.isArray(b)){return{options:b}}var d={options:[]},e=0,f=0,g=j.MAX_PAGES;if(c.hasOwnProperty("maxPages")){g=c.maxPages}for(var h=1,k;h<=g;h++){k=0;if(2>=h){k=b;f=b}else{f=2*f;k=f}e+=k;var l={itemcount:k,content:e};if(1==h){l.active=!0}d.options.push(l)}return d},s=function(a,b,c){var d=k();if(c.hasOwnProperty("ignoreControlWhileLoading")){d.ignorecontrolwhileloading=c.ignoreControlWhileLoading}if(c.hasOwnProperty("controlPlacementBottom")){d.controlplacementbottom=c.controlPlacementBottom}if(c.hasOwnProperty("hideControlOnSinglePage")){d.hidecontrolonsinglepage=c.hideControlOnSinglePage}if(c.hasOwnProperty("ariaLabels")){d.arialabels=c.ariaLabels}if(c.hasOwnProperty("dropdown")&&c.dropdown){d.pagingdropdown=r(b,c)}else{d.pagingbar=q(a,b)}return d},t=function(e,f,g,i){i=i||{};var j=a.Deferred(),k=s(e,f,i);b.render(h.PAGED_CONTENT,k).then(function(b,c){b=a(b);var e=b.attr("id");if(i.hasOwnProperty("eventNamespace")){e=i.eventNamespace}var f=b;d.init(f,g,e);v(e,i);j.resolve(b,c)}).fail(function(a){j.reject(a)}).fail(c.exception);return j.promise()},u=function(a){return function callback(b){g.call([{methodname:"core_user_update_user_preferences",args:{preferences:[{type:a,value:b}]}}])}},v=function(a,b){if(b.hasOwnProperty("persistentLimitKey")){f.subscribe(a+e.SET_ITEMS_PER_PAGE_LIMIT,u(b.persistentLimitKey))}};return{create:function create(a,b){return t(null,null,a,b)},createWithLimit:function createWithLimit(a,b,c){return t(null,a,b,c)},createWithTotalAndLimit:t,createFromStaticList:function createFromStaticList(a,b,c,d){if("undefined"==typeof d){d={}}var e=a.length;return t(e,b,function(b){var d=[];b.forEach(function(b){var c=b.offset,f=b.limit?c+b.limit:e,g=a.slice(c,f);d.push(g)});return c(d)},d)},createFromAjax:t,resetLastPageNumber:function resetLastPageNumber(a,b){f.publish(a+e.ALL_ITEMS_LOADED,b)}}});
//# sourceMappingURL=paged_content_factory.min.js.map
File diff suppressed because one or more lines are too long
+2 -1
View File
@@ -210,7 +210,8 @@ function(
var context = getDefaultPagingBarTemplateContext();
context.itemsperpage = buildItemsPerPagePagingBarContext(itemsPerPage);
context.showitemsperpageselector = $.isArray(itemsPerPage);
// Only display the items per page selector if there is more than one to choose from.
context.showitemsperpageselector = $.isArray(itemsPerPage) && itemsPerPage.length > 1;
return context;
};
@@ -64,12 +64,13 @@
aria-label="{{.}}"
{{/arialabels.itemsperpage}}
{{^arialabels.itemsperpage}}
aria-label="{{#str}} pagedcontentpagingbaritemsperpage, core, {{#itemsperpage}}{{#active}}{{value}}{{/active}}{{/itemsperpage}}{{/str}}"
aria-label="{{#str}} pagedcontentpagingbaritemsperpage, core, {{#itemsperpage}}{{#active}}{{#value}}{{.}}{{/value}}{{^value}}{{#str}} all, core {{/str}}{{/value}}{{/active}}{{/itemsperpage}}{{/str}}"
{{/arialabels.itemsperpage}}
>
{{#itemsperpage}}
{{#active}}
{{value}}
{{#value}}{{.}}{{/value}}
{{^value}}{{#str}} all, core {{/str}}{{/value}}
{{/active}}
{{/itemsperpage}}
</button>
@@ -101,7 +102,6 @@
{{/showitemsperpageselector}}
<nav
role="navigation"
id="{{$pagingbarid}}paging-bar-{{uniqid}}{{/pagingbarid}}"
class="{{#showitemsperpageselector}}ml-auto{{/showitemsperpageselector}}"
data-region="paging-bar"