Skip to content

Commit

Permalink
MDL-73376 qbank_comment: Version selection in modal
Browse files Browse the repository at this point in the history
This commit implements version selection in the comment
modal to allow users to change the version of question
using that dropdown.
  • Loading branch information
safatshahin committed Sep 1, 2022
1 parent 952d9e9 commit 497a644
Show file tree
Hide file tree
Showing 17 changed files with 250 additions and 27 deletions.
2 changes: 2 additions & 0 deletions lang/en/question.php
Expand Up @@ -498,6 +498,8 @@
$string['qbanknotfound'] = 'The \'{$a}\' question bank plugin doesn\'t exist or is not recognised.';
$string['noquestionbanks'] = 'No question bank plugin found.';
$string['questionloaderror'] = 'Could not load the question options.';
$string['version_selection'] = 'Version {$a->version}';
$string['question_version'] = 'Question version';

// Deprecated since Moodle 4.0.
$string['notflagged'] = 'Not flagged';
Expand Down
2 changes: 1 addition & 1 deletion question/bank/comment/amd/build/comment.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion question/bank/comment/amd/build/comment.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions question/bank/comment/amd/src/comment.js
Expand Up @@ -39,13 +39,13 @@ import Notification from 'core/notification';
const commentEvent = (questionId, courseID, contextId) => {
let args = {
questionid: questionId,
courseid: courseID
courseid: courseID,
uniqueidentifier: 'question_comment_version_dropdown'
};
let commentFragment = Fragment.loadFragment('qbank_comment', 'question_comment', contextId, args);
ModalFactory.create({
type: ModalFactory.types.SAVE_CANCEL,
title: Str.get_string('commentheader', 'qbank_comment'),
body: commentFragment,
body: Fragment.loadFragment('qbank_comment', 'question_comment', contextId, args),
large: true,
}).then((modal) => {
let root = modal.getRoot();
Expand All @@ -56,6 +56,12 @@ const commentEvent = (questionId, courseID, contextId) => {
submitlink.style.display = 'none';
});

// Version selection event.
root.on('change', '#question_comment_version_dropdown', function(e) {
args.questionid = e.target.value;
modal.setBody(Fragment.loadFragment('qbank_comment', 'question_comment', contextId, args));
});

// Get the required strings and updated the modal button text labels.
Str.get_strings([
{key: 'addcomment', component: 'qbank_comment'},
Expand Down
7 changes: 7 additions & 0 deletions question/bank/comment/lib.php
Expand Up @@ -109,6 +109,9 @@ function qbank_comment_preview_display($question, $courseid): string {
* @return string rendered output
*/
function qbank_comment_output_fragment_question_comment($args): string {
if (!$args['questionid'] || !$args['uniqueidentifier']) {
return '';
}
global $USER, $PAGE, $CFG, $DB;
$displaydata = [];
require_once($CFG->dirroot . '/question/engine/bank.php');
Expand All @@ -133,5 +136,9 @@ function qbank_comment_output_fragment_question_comment($args): string {
$displaydata['commenstdisabled'] = true;
}

$selector = \core_question\output\question_version_selection::make_for_question($args['uniqueidentifier'], $args['questionid']);
$qbankrenderer = $PAGE->get_renderer('core_question', 'bank');
$displaydata['versionselection'] = $selector->export_for_template($qbankrenderer);

return $PAGE->get_renderer('qbank_comment')->render_comment_fragment($displaydata);
}

0 comments on commit 497a644

Please sign in to comment.