mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 00:42:54 +02:00
MDL-80750 mod_assign: Show sticky footer with pagination on grading page
This commit is contained in:
parent
f6141a67d8
commit
5a5b16d207
@ -51,18 +51,6 @@ class grading_options_temp_form extends \moodleform {
|
||||
$mform->disable_form_change_checker();
|
||||
|
||||
$mform->addElement('header', 'general', get_string('gradingoptions', 'assign'));
|
||||
// Visible elements.
|
||||
$options = array(10 => '10', 20 => '20', 50 => '50', 100 => '100', -1 => get_string('all'));
|
||||
$maxperpage = get_config('assign', 'maxperpage');
|
||||
if (isset($maxperpage) && $maxperpage != -1) {
|
||||
unset($options[-1]);
|
||||
foreach ($options as $val) {
|
||||
if ($val > $maxperpage) {
|
||||
unset($options[$val]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$mform->addElement('select', 'perpage', get_string('assignmentsperpage', 'assign'), $options);
|
||||
if (!empty($instance['markingallocationopt'])) {
|
||||
$markingfilter = get_string('markerfilter', 'assign');
|
||||
$mform->addElement('select', 'markerfilter', $markingfilter, $instance['markingallocationopt']);
|
||||
|
@ -40,6 +40,8 @@ class assign_grading_table extends table_sql implements renderable {
|
||||
private $assignment = null;
|
||||
/** @var int $perpage */
|
||||
private $perpage = 10;
|
||||
/** @var int[] $pagingoptions Available pagination options */
|
||||
private $pagingoptions = [10, 20, 50, 100];
|
||||
/** @var int $rownum (global index of current row in table) */
|
||||
private $rownum = -1;
|
||||
/** @var renderer_base for getting output */
|
||||
@ -1824,4 +1826,57 @@ class assign_grading_table extends table_sql implements renderable {
|
||||
}
|
||||
parent::setup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the html for the paging bar.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_paging_bar(): string {
|
||||
global $OUTPUT;
|
||||
|
||||
if ($this->use_pages) {
|
||||
$pagingbar = new paging_bar($this->totalrows, $this->currpage, $this->pagesize, $this->baseurl);
|
||||
$pagingbar->pagevar = $this->request[TABLE_VAR_PAGE];
|
||||
return $OUTPUT->render($pagingbar);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the html for the paging selector.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_paging_selector(): string {
|
||||
global $OUTPUT;
|
||||
|
||||
if ($this->use_pages) {
|
||||
$pagingoptions = [...$this->pagingoptions, $this->perpage]; // To make sure the actual page size is within the options.
|
||||
$pagingoptions = array_unique($pagingoptions);
|
||||
sort($pagingoptions);
|
||||
$pagingoptions = array_combine($pagingoptions, $pagingoptions);
|
||||
$maxperpage = get_config('assign', 'maxperpage');
|
||||
if (isset($maxperpage) && $maxperpage != -1) {
|
||||
// Remove any options that are greater than the maxperpage.
|
||||
$pagingoptions = array_filter($pagingoptions, fn($value) => $value <= $maxperpage);
|
||||
} else {
|
||||
$pagingoptions[-1] = get_string('all');
|
||||
}
|
||||
|
||||
$data = [
|
||||
'baseurl' => $this->baseurl->out(false),
|
||||
'options' => array_map(fn($key, $name): array => [
|
||||
'name' => $name,
|
||||
'value' => $key,
|
||||
'selected' => $key == $this->perpage,
|
||||
], array_keys($pagingoptions), $pagingoptions),
|
||||
];
|
||||
|
||||
return $OUTPUT->render_from_template('mod_assign/grading_paging_selector', $data);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
@ -4478,7 +4478,7 @@ class assign {
|
||||
* @return string
|
||||
*/
|
||||
protected function view_grading_table() {
|
||||
global $USER, $CFG, $SESSION, $PAGE;
|
||||
global $USER, $CFG, $SESSION, $PAGE, $OUTPUT;
|
||||
|
||||
// Include grading options form.
|
||||
require_once($CFG->dirroot . '/mod/assign/gradingoptionsform.php');
|
||||
@ -4504,6 +4504,11 @@ class assign {
|
||||
set_user_preference('assign_downloadasfolders', $submitteddownloadasfolders);
|
||||
}
|
||||
|
||||
$submittedperpage = optional_param('perpage', null, PARAM_INT);
|
||||
if (isset($submittedperpage)) {
|
||||
set_user_preference('assign_perpage', $submittedperpage);
|
||||
}
|
||||
|
||||
$o = '';
|
||||
$cmid = $this->get_course_module()->id;
|
||||
|
||||
@ -4586,7 +4591,6 @@ class assign {
|
||||
$classoptions);
|
||||
|
||||
$gradingoptionsdata = new stdClass();
|
||||
$gradingoptionsdata->perpage = $perpage;
|
||||
$gradingoptionsdata->markerfilter = $markerfilter;
|
||||
$gradingoptionsform->set_data($gradingoptionsdata);
|
||||
|
||||
@ -4619,10 +4623,18 @@ class assign {
|
||||
}
|
||||
|
||||
// Load and print the table of submissions.
|
||||
if ($showquickgrading && $quickgrading) {
|
||||
$gradingtable = new assign_grading_table($this, $perpage, $filter, 0, true);
|
||||
$gradingtable->responsive = false;
|
||||
$table = $this->get_renderer()->render($gradingtable);
|
||||
$usequickgrading = $showquickgrading && $quickgrading;
|
||||
$gradingtable = new assign_grading_table($this, $perpage, $filter, 0, $usequickgrading);
|
||||
$gradingtable->responsive = false;
|
||||
$table = $this->get_renderer()->render($gradingtable);
|
||||
$footerdata = [
|
||||
'perpage' => $gradingtable->get_paging_selector(),
|
||||
'pagingbar' => $gradingtable->get_paging_bar(),
|
||||
];
|
||||
$footer = new core\output\sticky_footer($OUTPUT->render_from_template('mod_assign/grading_sticky_footer', $footerdata));
|
||||
$table .= $this->get_renderer()->render($footer);
|
||||
|
||||
if ($usequickgrading) {
|
||||
$page = optional_param('page', null, PARAM_INT);
|
||||
$quickformparams = array('cm'=>$this->get_course_module()->id,
|
||||
'gradingtable'=>$table,
|
||||
@ -4632,14 +4644,13 @@ class assign {
|
||||
|
||||
$o .= $this->get_renderer()->render(new assign_form('quickgradingform', $quickgradingform));
|
||||
} else {
|
||||
$gradingtable = new assign_grading_table($this, $perpage, $filter, 0, false);
|
||||
$gradingtable->responsive = false;
|
||||
$o .= $this->get_renderer()->render($gradingtable);
|
||||
$o .= $table;
|
||||
}
|
||||
|
||||
if ($this->can_grade()) {
|
||||
// We need to store the order of uses in the table as the person may wish to grade them.
|
||||
// This is done based on the row number of the user.
|
||||
// Pagination has be added before this because calling get_column_data will reset the pagination.
|
||||
$useridlist = $gradingtable->get_column_data('userid');
|
||||
$SESSION->mod_assign_useridlist[$this->get_useridlist_key()] = $useridlist;
|
||||
}
|
||||
@ -7426,7 +7437,6 @@ class assign {
|
||||
];
|
||||
$mform = new mod_assign\form\grading_options_temp_form(null, $gradingoptionsparams);
|
||||
if ($formdata = $mform->get_data()) {
|
||||
set_user_preference('assign_perpage', $formdata->perpage);
|
||||
if (isset($formdata->markerfilter)) {
|
||||
set_user_preference('assign_markerfilter', $formdata->markerfilter);
|
||||
}
|
||||
|
@ -127,10 +127,6 @@ M.mod_assign.init_grading_table = function(Y) {
|
||||
|
||||
M.mod_assign.init_grading_options = function(Y) {
|
||||
Y.use('node', function(Y) {
|
||||
var paginationelement = Y.one('#id_perpage');
|
||||
paginationelement.on('change', function(e) {
|
||||
Y.one('form.gradingoptionsform').submit();
|
||||
});
|
||||
var markerfilterelement = Y.one('#id_markerfilter');
|
||||
if (markerfilterelement) {
|
||||
markerfilterelement.on('change', function(e) {
|
||||
|
48
mod/assign/templates/grading_paging_selector.mustache
Normal file
48
mod/assign/templates/grading_paging_selector.mustache
Normal file
@ -0,0 +1,48 @@
|
||||
{{!
|
||||
This file is part of Moodle - http://moodle.org/
|
||||
|
||||
Moodle is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Moodle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
}}
|
||||
{{!
|
||||
@template mod_assign/grading_paging_selector
|
||||
|
||||
Template for pagination dropdown on the assignment grading page.
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
"baseurl": "http://example.com/grading.php?id=1",
|
||||
"options": [
|
||||
{"name": "10", "value": "10", "selected": false},
|
||||
{"name": "20", "value": "20", "selected": false},
|
||||
{"name": "50", "value": "50", "selected": true},
|
||||
{"name": "All", "value": "-1", "selected": false}
|
||||
]
|
||||
}
|
||||
}}
|
||||
<label>
|
||||
{{#str}}show{{/str}}
|
||||
<select name="perpage" class="mt-1 custom-select ignoredirty" id="{{uniqid}}-perpage">
|
||||
{{#options}}
|
||||
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
|
||||
{{/options}}
|
||||
</select>
|
||||
</label>
|
||||
{{#js}}
|
||||
document.getElementById('{{uniqid}}-perpage').addEventListener('change', function(e) {
|
||||
var url = new URL('{{{baseurl}}}');
|
||||
url.searchParams.set('perpage', e.target.value);
|
||||
|
||||
window.location.href = url;
|
||||
});
|
||||
{{/js}}
|
37
mod/assign/templates/grading_sticky_footer.mustache
Normal file
37
mod/assign/templates/grading_sticky_footer.mustache
Normal file
@ -0,0 +1,37 @@
|
||||
{{!
|
||||
This file is part of Moodle - http://moodle.org/
|
||||
|
||||
Moodle is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Moodle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
}}
|
||||
{{!
|
||||
@template mod_assign/grading_sticky_footer
|
||||
|
||||
Sticky footer template for the assignment grading page.
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
"perpage": "<label>Show<select name='perpage' class='custom-select'><option value='-1'>All</select></label>",
|
||||
"pagingbar": "<nav class='pagination pagination-centered justify-content-center'><ul class='mt-1 pagination '><li class='page-item active'><a href='#' class='page-link'><span>1</span></a></li></ul></nav>"
|
||||
}
|
||||
}}
|
||||
<div class="col-auto">
|
||||
{{#perpage}}
|
||||
{{{.}}}
|
||||
{{/perpage}}
|
||||
</div>
|
||||
<div class="col">
|
||||
{{#pagingbar}}
|
||||
{{{.}}}
|
||||
{{/pagingbar}}
|
||||
</div>
|
Loading…
x
Reference in New Issue
Block a user