MDL-70871 table: Add 'Show all X' functionality to dynamic_table
This commit is contained in:
Vendored
+1
-1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1
-1
@@ -1,2 +1,2 @@
|
||||
define ("core_table/local/dynamic/selectors",["exports"],function(a){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.default=void 0;a.default={main:{region:"[data-region=\"core_table/dynamic\"]",fromRegionId:function fromRegionId(a){return"[data-region=\"core_table/dynamic\"][data-table-uniqueid=\"".concat(a,"\"]")}},table:{links:{sortableColumn:"a[data-sortable=\"1\"]",hide:"a[data-action=\"hide\"]",show:"a[data-action=\"show\"]"}},initialsBar:{links:{firstInitial:".firstinitial [data-initial]",lastInitial:".lastinitial [data-initial]"}},paginationBar:{links:{pageItem:".pagination [data-page-number]"}}};return a.default});
|
||||
define ("core_table/local/dynamic/selectors",["exports"],function(a){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.default=void 0;a.default={main:{region:"[data-region=\"core_table/dynamic\"]",fromRegionId:function fromRegionId(a){return"[data-region=\"core_table/dynamic\"][data-table-uniqueid=\"".concat(a,"\"]")}},table:{links:{sortableColumn:"a[data-sortable=\"1\"]",hide:"a[data-action=\"hide\"]",show:"a[data-action=\"show\"]"}},initialsBar:{links:{firstInitial:".firstinitial [data-initial]",lastInitial:".lastinitial [data-initial]"}},paginationBar:{links:{pageItem:".pagination [data-page-number]"}},showCount:{links:{toggle:"[data-action=\"showcount\"]"}}};return a.default});
|
||||
//# sourceMappingURL=selectors.min.js.map
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"sources":["../../../src/local/dynamic/selectors.js"],"names":["main","region","fromRegionId","regionId","table","links","sortableColumn","hide","show","initialsBar","firstInitial","lastInitial","paginationBar","pageItem"],"mappings":"8JAuBe,CACXA,IAAI,CAAE,CACFC,MAAM,CAAE,sCADN,CAEFC,YAAY,CAAE,sBAAAC,CAAQ,6EAA+DA,CAA/D,QAFpB,CADK,CAKXC,KAAK,CAAE,CACHC,KAAK,CAAE,CACHC,cAAc,CAAE,wBADb,CAEHC,IAAI,CAAE,yBAFH,CAGHC,IAAI,CAAE,yBAHH,CADJ,CALI,CAYXC,WAAW,CAAE,CACTJ,KAAK,CAAE,CACHK,YAAY,CAAE,8BADX,CAEHC,WAAW,CAAE,6BAFV,CADE,CAZF,CAkBXC,aAAa,CAAE,CACXP,KAAK,CAAE,CACHQ,QAAQ,CAAE,gCADP,CADI,CAlBJ,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Dynamic table selectors.\n *\n * @module core_table/selectors\n * @package core_table\n * @copyright 2020 Simey Lameze <[email protected]>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nexport default {\n main: {\n region: '[data-region=\"core_table/dynamic\"]',\n fromRegionId: regionId => `[data-region=\"core_table/dynamic\"][data-table-uniqueid=\"${regionId}\"]`,\n },\n table: {\n links: {\n sortableColumn: 'a[data-sortable=\"1\"]',\n hide: 'a[data-action=\"hide\"]',\n show: 'a[data-action=\"show\"]',\n },\n },\n initialsBar: {\n links: {\n firstInitial: '.firstinitial [data-initial]',\n lastInitial: '.lastinitial [data-initial]',\n },\n },\n paginationBar: {\n links: {\n pageItem: '.pagination [data-page-number]'\n }\n },\n};\n"],"file":"selectors.min.js"}
|
||||
{"version":3,"sources":["../../../src/local/dynamic/selectors.js"],"names":["main","region","fromRegionId","regionId","table","links","sortableColumn","hide","show","initialsBar","firstInitial","lastInitial","paginationBar","pageItem","showCount","toggle"],"mappings":"8JAuBe,CACXA,IAAI,CAAE,CACFC,MAAM,CAAE,sCADN,CAEFC,YAAY,CAAE,sBAAAC,CAAQ,6EAA+DA,CAA/D,QAFpB,CADK,CAKXC,KAAK,CAAE,CACHC,KAAK,CAAE,CACHC,cAAc,CAAE,wBADb,CAEHC,IAAI,CAAE,yBAFH,CAGHC,IAAI,CAAE,yBAHH,CADJ,CALI,CAYXC,WAAW,CAAE,CACTJ,KAAK,CAAE,CACHK,YAAY,CAAE,8BADX,CAEHC,WAAW,CAAE,6BAFV,CADE,CAZF,CAkBXC,aAAa,CAAE,CACXP,KAAK,CAAE,CACHQ,QAAQ,CAAE,gCADP,CADI,CAlBJ,CAuBXC,SAAS,CAAE,CACPT,KAAK,CAAE,CACHU,MAAM,CAAE,6BADL,CADA,CAvBA,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Dynamic table selectors.\n *\n * @module core_table/selectors\n * @package core_table\n * @copyright 2020 Simey Lameze <[email protected]>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nexport default {\n main: {\n region: '[data-region=\"core_table/dynamic\"]',\n fromRegionId: regionId => `[data-region=\"core_table/dynamic\"][data-table-uniqueid=\"${regionId}\"]`,\n },\n table: {\n links: {\n sortableColumn: 'a[data-sortable=\"1\"]',\n hide: 'a[data-action=\"hide\"]',\n show: 'a[data-action=\"show\"]',\n },\n },\n initialsBar: {\n links: {\n firstInitial: '.firstinitial [data-initial]',\n lastInitial: '.lastinitial [data-initial]',\n },\n },\n paginationBar: {\n links: {\n pageItem: '.pagination [data-page-number]'\n }\n },\n showCount: {\n links: {\n toggle: '[data-action=\"showcount\"]',\n },\n },\n};\n"],"file":"selectors.min.js"}
|
||||
@@ -440,6 +440,13 @@ export const init = () => {
|
||||
|
||||
resetTablePreferences(tableRoot).catch(Notification.exception);
|
||||
}
|
||||
|
||||
const showCountLink = e.target.closest(Selectors.showCount.links.toggle);
|
||||
if (showCountLink) {
|
||||
e.preventDefault();
|
||||
|
||||
setPageSize(tableRoot, showCountLink.dataset.targetPageSize).catch(Notification.exception);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -44,4 +44,9 @@ export default {
|
||||
pageItem: '.pagination [data-page-number]'
|
||||
}
|
||||
},
|
||||
showCount: {
|
||||
links: {
|
||||
toggle: '[data-action="showcount"]',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
+53
-1
@@ -46,6 +46,11 @@ define('TABLE_P_TOP', 1);
|
||||
define('TABLE_P_BOTTOM', 2);
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Constant that defines the 'Show all' page size.
|
||||
*/
|
||||
define('TABLE_SHOW_ALL_PAGE_SIZE', 5000);
|
||||
|
||||
use core_table\local\filter\filterset;
|
||||
|
||||
/**
|
||||
@@ -108,6 +113,9 @@ class flexible_table {
|
||||
var $sort_default_column = NULL;
|
||||
var $sort_default_order = SORT_ASC;
|
||||
|
||||
/** @var integer The defeult per page size for the table. */
|
||||
private $defaultperpage = 30;
|
||||
|
||||
/**
|
||||
* Array of positions in which to display download controls.
|
||||
*/
|
||||
@@ -1507,6 +1515,24 @@ class flexible_table {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default per page.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_default_per_page(): int {
|
||||
return $this->defaultperpage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default per page.
|
||||
*
|
||||
* @param int $defaultperpage
|
||||
*/
|
||||
public function set_default_per_page(int $defaultperpage): void {
|
||||
$this->defaultperpage = $defaultperpage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the preferred first name initial in an initials bar.
|
||||
*
|
||||
@@ -1678,6 +1704,7 @@ class flexible_table {
|
||||
'data-table-last-initial' => $this->prefs['i_last'],
|
||||
'data-table-page-number' => $this->currpage + 1,
|
||||
'data-table-page-size' => $this->pagesize,
|
||||
'data-table-default-per-page' => $this->get_default_per_page(),
|
||||
'data-table-hidden-columns' => json_encode(array_keys($this->prefs['collapse'])),
|
||||
'data-table-total-rows' => $this->totalrows,
|
||||
]);
|
||||
@@ -1696,8 +1723,33 @@ class flexible_table {
|
||||
global $PAGE;
|
||||
|
||||
if (is_a($this, \core_table\dynamic::class)) {
|
||||
$output = '';
|
||||
|
||||
$perpageurl = new moodle_url($PAGE->url);
|
||||
|
||||
// Generate "Show all/Show per page" link.
|
||||
if ($this->pagesize == TABLE_SHOW_ALL_PAGE_SIZE && $this->totalrows > $this->get_default_per_page()) {
|
||||
$perpagesize = $this->get_default_per_page();
|
||||
$perpagestring = get_string('showperpage', '', $this->get_default_per_page());
|
||||
} else if ($this->pagesize < $this->totalrows) {
|
||||
$perpagesize = TABLE_SHOW_ALL_PAGE_SIZE;
|
||||
$perpagestring = get_string('showall', '', $this->totalrows);
|
||||
}
|
||||
if (isset($perpagesize) && isset($perpagestring)) {
|
||||
$perpageurl->param('perpage', $perpagesize);
|
||||
$output .= html_writer::link(
|
||||
$perpageurl,
|
||||
$perpagestring,
|
||||
[
|
||||
'data-action' => 'showcount',
|
||||
'data-target-page-size' => $perpagesize,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
$PAGE->requires->js_call_amd('core_table/dynamic', 'init');
|
||||
return html_writer::end_tag('div');
|
||||
$output .= html_writer::end_tag('div');
|
||||
return $output;
|
||||
}
|
||||
|
||||
return '';
|
||||
|
||||
Reference in New Issue
Block a user