mirror of
https://github.com/moodle/moodle.git
synced 2025-03-22 00:20:37 +01:00
Merge branch 'MDL-70871-master' of git://github.com/roland04/moodle
This commit is contained in:
commit
23543fd552
2
lib/table/amd/build/dynamic.min.js
vendored
2
lib/table/amd/build/dynamic.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -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 <simey@moodle.com>\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 <simey@moodle.com>\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"]',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
@ -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 '';
|
||||
|
2
user/amd/build/participants.min.js
vendored
2
user/amd/build/participants.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -109,23 +109,19 @@ export const init = ({
|
||||
});
|
||||
|
||||
root.addEventListener('click', e => {
|
||||
// Handle clicking of the "Show [all|count]" and "Select all" actions.
|
||||
const showCountLink = root.querySelector(Selectors.showCountToggle);
|
||||
// Handle clicking of the "Select all" actions.
|
||||
const checkCountButton = root.querySelector(Selectors.checkCountButton);
|
||||
|
||||
const showCountLinkClicked = showCountLink && showCountLink.contains(e.target);
|
||||
const checkCountButtonClicked = checkCountButton && checkCountButton.contains(e.target);
|
||||
|
||||
if (showCountLinkClicked || checkCountButtonClicked) {
|
||||
if (checkCountButtonClicked) {
|
||||
e.preventDefault();
|
||||
|
||||
const tableRoot = getTableFromUniqueId(uniqueid);
|
||||
|
||||
DynamicTable.setPageSize(tableRoot, showCountLink.dataset.targetPageSize)
|
||||
DynamicTable.setPageSize(tableRoot, checkCountButton.dataset.targetPageSize)
|
||||
.then(tableRoot => {
|
||||
// Always update the toggle state.
|
||||
// This ensures that the bulk actions are disabled after changing the page size.
|
||||
CheckboxToggleAll.setGroupState(root, 'participants-table', checkCountButtonClicked);
|
||||
// Update the toggle state.
|
||||
CheckboxToggleAll.setGroupState(root, 'participants-table', true);
|
||||
|
||||
return tableRoot;
|
||||
})
|
||||
@ -135,12 +131,11 @@ export const init = ({
|
||||
|
||||
// When the content is refreshed, update the row counts in various places.
|
||||
root.addEventListener(DynamicTable.Events.tableContentRefreshed, e => {
|
||||
const showCountLink = root.querySelector(Selectors.showCountToggle);
|
||||
const checkCountButton = root.querySelector(Selectors.checkCountButton);
|
||||
|
||||
const tableRoot = e.target;
|
||||
|
||||
const defaultPageSize = parseInt(root.dataset.tableDefaultPerPage, 10);
|
||||
const defaultPageSize = parseInt(tableRoot.dataset.tableDefaultPerPage, 10);
|
||||
const currentPageSize = parseInt(tableRoot.dataset.tablePageSize, 10);
|
||||
const totalRowCount = parseInt(tableRoot.dataset.tableTotalRows, 10);
|
||||
|
||||
@ -154,67 +149,39 @@ export const init = ({
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
if (totalRowCount <= defaultPageSize) {
|
||||
// There are fewer than the default page count numbers of rows.
|
||||
showCountLink.classList.add('hidden');
|
||||
|
||||
if (checkCountButton) {
|
||||
checkCountButton.classList.add('hidden');
|
||||
}
|
||||
} else if (totalRowCount <= currentPageSize) {
|
||||
// The are fewer than the current page size.
|
||||
pageCountStrings.push({
|
||||
key: 'showperpage',
|
||||
component: 'core',
|
||||
param: defaultPageSize,
|
||||
});
|
||||
|
||||
pageCountStrings.push({
|
||||
key: 'selectalluserswithcount',
|
||||
component: 'core',
|
||||
param: defaultPageSize,
|
||||
});
|
||||
|
||||
// Show the 'Show [x]' link.
|
||||
showCountLink.classList.remove('hidden');
|
||||
showCountLink.dataset.targetPageSize = defaultPageSize;
|
||||
|
||||
if (checkCountButton) {
|
||||
// The 'Check all [x]' button is only visible when there are values to set.
|
||||
checkCountButton.classList.add('hidden');
|
||||
}
|
||||
} else {
|
||||
pageCountStrings.push({
|
||||
key: 'showall',
|
||||
component: 'core',
|
||||
param: totalRowCount,
|
||||
});
|
||||
|
||||
pageCountStrings.push({
|
||||
key: 'selectalluserswithcount',
|
||||
component: 'core',
|
||||
param: totalRowCount,
|
||||
});
|
||||
|
||||
// Show both the 'Show [x]' link, and the 'Check all [x]' button.
|
||||
showCountLink.classList.remove('hidden');
|
||||
showCountLink.dataset.targetPageSize = totalRowCount;
|
||||
|
||||
if (checkCountButton) {
|
||||
checkCountButton.classList.remove('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
Str.get_strings(pageCountStrings)
|
||||
.then(([showingParticipantCountString, showCountString, selectCountString]) => {
|
||||
.then(([showingParticipantCountString, selectCountString]) => {
|
||||
const showingParticipantCount = root.querySelector(Selectors.showCountText);
|
||||
showingParticipantCount.innerHTML = showingParticipantCountString;
|
||||
|
||||
if (showCountString) {
|
||||
showCountLink.innerHTML = showCountString;
|
||||
}
|
||||
|
||||
if (selectCountString && checkCountButton) {
|
||||
checkCountButton.value = selectCountString;
|
||||
}
|
||||
|
@ -195,6 +195,8 @@ class participants extends \table_sql implements dynamic_table {
|
||||
$this->no_sorting('groups');
|
||||
}
|
||||
|
||||
$this->set_default_per_page(20);
|
||||
|
||||
$this->set_attribute('id', 'participants');
|
||||
|
||||
$this->countries = get_string_manager()->get_list_of_countries(true);
|
||||
|
@ -35,7 +35,6 @@ use core_table\local\filter\integer_filter;
|
||||
use core_table\local\filter\string_filter;
|
||||
|
||||
define('DEFAULT_PAGE_SIZE', 20);
|
||||
define('SHOW_ALL_PAGE_SIZE', 5000);
|
||||
|
||||
$page = optional_param('page', 0, PARAM_INT); // Which page to show.
|
||||
$perpage = optional_param('perpage', DEFAULT_PAGE_SIZE, PARAM_INT); // How many per page.
|
||||
@ -189,7 +188,6 @@ echo html_writer::start_tag('form', [
|
||||
'id' => 'participantsform',
|
||||
'data-course-id' => $course->id,
|
||||
'data-table-unique-id' => $participanttable->uniqueid,
|
||||
'data-table-default-per-page' => ($perpage < DEFAULT_PAGE_SIZE) ? $perpage : DEFAULT_PAGE_SIZE,
|
||||
]);
|
||||
echo '<div>';
|
||||
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
|
||||
@ -205,40 +203,6 @@ echo html_writer::tag(
|
||||
|
||||
echo $participanttablehtml;
|
||||
|
||||
$perpageurl = new moodle_url('/user/index.php', [
|
||||
'contextid' => $context->id,
|
||||
'id' => $course->id,
|
||||
]);
|
||||
$perpagesize = DEFAULT_PAGE_SIZE;
|
||||
$perpagevisible = false;
|
||||
$perpagestring = '';
|
||||
|
||||
if ($perpage == SHOW_ALL_PAGE_SIZE && $participanttable->totalrows > DEFAULT_PAGE_SIZE) {
|
||||
$perpageurl->param('perpage', $participanttable->totalrows);
|
||||
$perpagesize = SHOW_ALL_PAGE_SIZE;
|
||||
$perpagevisible = true;
|
||||
$perpagestring = get_string('showperpage', '', DEFAULT_PAGE_SIZE);
|
||||
} else if ($participanttable->get_page_size() < $participanttable->totalrows) {
|
||||
$perpageurl->param('perpage', SHOW_ALL_PAGE_SIZE);
|
||||
$perpagesize = SHOW_ALL_PAGE_SIZE;
|
||||
$perpagevisible = true;
|
||||
$perpagestring = get_string('showall', '', $participanttable->totalrows);
|
||||
}
|
||||
|
||||
$perpageclasses = '';
|
||||
if (!$perpagevisible) {
|
||||
$perpageclasses = 'hidden';
|
||||
}
|
||||
echo $OUTPUT->container(html_writer::link(
|
||||
$perpageurl,
|
||||
$perpagestring,
|
||||
[
|
||||
'data-action' => 'showcount',
|
||||
'data-target-page-size' => $perpagesize,
|
||||
'class' => $perpageclasses,
|
||||
]
|
||||
), [], 'showall');
|
||||
|
||||
$bulkoptions = (object) [
|
||||
'uniqueid' => $participanttable->uniqueid,
|
||||
];
|
||||
@ -256,7 +220,7 @@ if ($bulkoperations) {
|
||||
'id' => 'checkall',
|
||||
'class' => 'btn btn-secondary',
|
||||
'value' => $label,
|
||||
'data-target-page-size' => $participanttable->totalrows,
|
||||
'data-target-page-size' => TABLE_SHOW_ALL_PAGE_SIZE,
|
||||
]);
|
||||
}
|
||||
echo html_writer::end_tag('div');
|
||||
|
Loading…
x
Reference in New Issue
Block a user