Skip to content

Commit

Permalink
MDL-82683 mod_assign: Move the quick grading checkbox to the action bar
Browse files Browse the repository at this point in the history
  • Loading branch information
rezaies committed Aug 29, 2024
1 parent 8ec84f4 commit 8b1d81c
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 48 deletions.
6 changes: 0 additions & 6 deletions mod/assign/classes/form/grading_options_temp_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ public function definition() {
$markingfilter = get_string('markerfilter', 'assign');
$mform->addElement('select', 'markerfilter', $markingfilter, $instance['markingallocationopt']);
}
// Quickgrading.
if ($instance['showquickgrading']) {
$mform->addElement('checkbox', 'quickgrading', get_string('quickgrading', 'assign'));
$mform->addHelpButton('quickgrading', 'quickgrading', 'assign');
$mform->setDefault('quickgrading', $instance['quickgrading']);
}

// Show active/suspended user option.
if ($instance['showonlyactiveenrolopt']) {
Expand Down
20 changes: 20 additions & 0 deletions mod/assign/classes/output/grading_actionmenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,26 @@ public function export_for_template(\renderer_base $output): array {
$data['graderurl'] = $url->out(false);
}

$gradingmanager = get_grading_manager($this->assign->get_context(), 'mod_assign', 'submissions');
$controller = $gradingmanager->get_active_controller();
$showquickgrading = empty($controller) && $this->assign->can_grade();
if ($showquickgrading) {
$quickgradingbaseurl = new moodle_url('/mod/assign/view.php', [
'id' => $this->assign->get_course_module()->id,
'action' => 'grading',
]);
if ($userid) {
$quickgradingbaseurl->param('userid', $userid);
} else if ($usersearch) {
$quickgradingbaseurl->param('search', $usersearch);
}

$data['quickgrading'] = [
'baseurl' => $quickgradingbaseurl->out(false),
'enabled' => get_user_preferences('assign_quickgrading', false),
];
}

$actions = $this->get_actions();
if ($actions) {
$menu = new \action_menu();
Expand Down
56 changes: 27 additions & 29 deletions mod/assign/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4490,6 +4490,11 @@ protected function view_grading_table() {
set_user_preference('assign_filter', $submittedfilter);
}

$submittedquickgrading = optional_param('quickgrading', null, PARAM_BOOL);
if (isset($submittedquickgrading)) {
set_user_preference('assign_quickgrading', $submittedquickgrading);
}

$o = '';
$cmid = $this->get_course_module()->id;

Expand Down Expand Up @@ -4535,17 +4540,17 @@ protected function view_grading_table() {
$markingworkflowoptions = $this->get_marking_workflow_filters();

// Print options for changing the filter and changing the number of results per page.
$gradingoptionsformparams = array('cm'=>$cmid,
'contextid'=>$this->context->id,
'userid'=>$USER->id,
'submissionsenabled'=>$this->is_any_submission_plugin_enabled(),
'showquickgrading'=>$showquickgrading,
'quickgrading'=>$quickgrading,
'markingworkflowopt'=>$markingworkflowoptions,
'markingallocationopt'=>$markingallocationoptions,
'showonlyactiveenrolopt'=>$showonlyactiveenrolopt,
'showonlyactiveenrol' => $this->show_only_active_users(),
'downloadasfolders' => $downloadasfolders);
$gradingoptionsformparams = [
'cm' => $cmid,
'contextid' => $this->context->id,
'userid' => $USER->id,
'submissionsenabled' => $this->is_any_submission_plugin_enabled(),
'markingworkflowopt' => $markingworkflowoptions,
'markingallocationopt' => $markingallocationoptions,
'showonlyactiveenrolopt' => $showonlyactiveenrolopt,
'showonlyactiveenrol' => $this->show_only_active_users(),
'downloadasfolders' => $downloadasfolders,
];

$classoptions = array('class'=>'gradingoptionsform');
$gradingoptionsform = new \mod_assign\form\grading_options_temp_form(null,
Expand Down Expand Up @@ -7378,10 +7383,6 @@ protected function process_save_grading_options() {
$this->require_view_grades();
require_sesskey();

// Is advanced grading enabled?
$gradingmanager = get_grading_manager($this->get_context(), 'mod_assign', 'submissions');
$controller = $gradingmanager->get_active_controller();
$showquickgrading = empty($controller);
if (!is_null($this->context)) {
$showonlyactiveenrolopt = has_capability('moodle/course:viewsuspendedusers', $this->context);
} else {
Expand All @@ -7407,26 +7408,23 @@ protected function process_save_grading_options() {
// Get marking states to show in form.
$markingworkflowoptions = $this->get_marking_workflow_filters();

$gradingoptionsparams = array('cm'=>$this->get_course_module()->id,
'contextid'=>$this->context->id,
'userid'=>$USER->id,
'submissionsenabled'=>$this->is_any_submission_plugin_enabled(),
'showquickgrading'=>$showquickgrading,
'quickgrading'=>false,
'markingworkflowopt' => $markingworkflowoptions,
'markingallocationopt' => $markingallocationoptions,
'showonlyactiveenrolopt'=>$showonlyactiveenrolopt,
'showonlyactiveenrol' => $this->show_only_active_users(),
'downloadasfolders' => get_user_preferences('assign_downloadasfolders', 1));
$gradingoptionsparams = [
'cm' => $this->get_course_module()->id,
'contextid' => $this->context->id,
'userid' => $USER->id,
'submissionsenabled' => $this->is_any_submission_plugin_enabled(),
'markingworkflowopt' => $markingworkflowoptions,
'markingallocationopt' => $markingallocationoptions,
'showonlyactiveenrolopt' => $showonlyactiveenrolopt,
'showonlyactiveenrol' => $this->show_only_active_users(),
'downloadasfolders' => get_user_preferences('assign_downloadasfolders', 1),
];
$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);
}
if ($showquickgrading) {
set_user_preference('assign_quickgrading', isset($formdata->quickgrading));
}
if (isset($formdata->downloadasfolders)) {
set_user_preference('assign_downloadasfolders', 1); // Enabled.
} else {
Expand Down
6 changes: 0 additions & 6 deletions mod/assign/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,6 @@ M.mod_assign.init_grading_options = function(Y) {
Y.one('form.gradingoptionsform').submit();
});
}
var quickgradingelement = Y.one('#id_quickgrading');
if (quickgradingelement) {
quickgradingelement.on('change', function(e) {
Y.one('form.gradingoptionsform').submit();
});
}
var showonlyactiveenrolelement = Y.one('#id_showonlyactiveenrol');
if (showonlyactiveenrolelement) {
showonlyactiveenrolelement.on('change', function(e) {
Expand Down
40 changes: 33 additions & 7 deletions mod/assign/templates/grading_actionmenu.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
* groupselector - (optional) HTML that outputs the group selector
* statusselector - (optional) The data object containing the required properties to render the status selector
* extrafiltersdropdown - HTML that outputs the extra filters dropdown
* pagereset - (optional) URL to reset the page
* graderurl - (optional) URL to the grader page
* quickgrading - (optional) Includes the baseurl and enabled properties for the quick grading checkbox
* actions - (optional) HTML that outputs the bulk action menu
Example context (json):
Expand All @@ -49,6 +52,11 @@
},
"extrafiltersdropdown": "<div class='dropdown extrafilters'></div>",
"pagereset": "http://moodle.local/mod/assign/view.php?id=2&action=grading&group=0",
"graderurl": "http://moodle.local/mod/assign/view.php?id=2&action=grader",
"quickgrading": {
"baseurl": "http://moodle.local/mod/assign/view.php?id=2&action=grading",
"enabled": true
},
"actions": "<div class='action-menu'></div>"
}

Expand Down Expand Up @@ -95,14 +103,32 @@
<div class="navitem-divider"></div>
{{/pagereset}}
{{#graderurl}}
<div class="navitem ms-sm-auto align-self-center">
<a class="btn btn-primary" href="{{graderurl}}">{{#str}}viewgrader, mod_assign{{/str}}</a>
</div>
<div class="navitem ms-sm-auto align-self-center">
<a class="btn btn-primary" href="{{graderurl}}">{{#str}}viewgrader, mod_assign{{/str}}</a>
</div>
{{/graderurl}}
</div>
</div>
<div class="row">
{{#actions}}
<div class="d-flex ml-auto me-3">{{{actions}}}</div>
{{/actions}}
<div class="container-fluid tertiary-navigation pt-0">
<div class="row pb-2">
{{#quickgrading}}
<div class="navitem m-0 ml-auto">
<div class="form-check align-self-center">
<input class="form-check-input" type="checkbox" id="quickgrading-{{uniqid}}" {{#enabled}}checked{{/enabled}}/>
<label class="form-check-label" for="quickgrading-{{uniqid}}" >{{#str}}quickgrading, mod_assign{{/str}}</label>
</div>
</div>
<div class="navitem-divider m-0"></div>
{{#js}}
document.querySelector('#quickgrading-{{uniqid}}').addEventListener('change', function(e) {
var url = new URL('{{{baseurl}}}');
url.searchParams.set('quickgrading', e.target.checked ? 1 : 0);
window.location.href = url;
});
{{/js}}
{{/quickgrading}}
{{#actions}}
<div class="navitem m-0">{{{actions}}}</div>
{{/actions}}
</div>
</div>

0 comments on commit 8b1d81c

Please sign in to comment.