Skip to content

Commit

Permalink
MDL-78477 qbank_history: Fix and improve UI for edit menu delete option
Browse files Browse the repository at this point in the history
Changes done to fix the warnings thrown in the history view when the
last version of a question is deleted and improved UI to display the
message and a Continue button, to navigate back to the Question bank.
  • Loading branch information
AnupamaSarjoshi committed Jun 21, 2023
1 parent 64b7011 commit e954482
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
22 changes: 14 additions & 8 deletions question/bank/history/classes/question_history_view.php
Expand Up @@ -175,7 +175,7 @@ protected function build_query(): void {
* Display the header for the question bank in the history page to include question name and type.
*/
public function display_question_bank_header(): void {
global $PAGE, $DB;
global $PAGE, $DB, $OUTPUT;
$sql = 'SELECT q.*
FROM {question} q
JOIN {question_versions} qv ON qv.questionid = q.id
Expand All @@ -187,13 +187,19 @@ public function display_question_bank_header(): void {
WHERE be.id = qbe.id)
AND qbe.id = ?';
$latestquestiondata = $DB->get_record_sql($sql, [$this->entryid]);
$historydata = [
'questionname' => $latestquestiondata->name,
'returnurl' => $this->basereturnurl,
'questionicon' => print_question_icon($latestquestiondata)
];
// Header for the page before the actual form from the api.
echo $PAGE->get_renderer('qbank_history')->render_history_header($historydata);
if ($latestquestiondata) {
$historydata = [
'questionname' => $latestquestiondata->name,
'returnurl' => $this->basereturnurl,
'questionicon' => print_question_icon($latestquestiondata)
];
// Header for the page before the actual form from the api.
echo $PAGE->get_renderer('qbank_history')->render_history_header($historydata);
} else {
// Continue when all the question versions are deleted.
echo $OUTPUT->notification(get_string('allquestionversionsdeleted', 'qbank_history'), 'notifysuccess');
echo $OUTPUT->continue_button($this->basereturnurl);
}
}

public function is_listing_specific_versions(): bool {
Expand Down
1 change: 1 addition & 0 deletions question/bank/history/lang/en/qbank_history.php
Expand Up @@ -23,6 +23,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

$string['allquestionversionsdeleted'] = 'All versions of this question have been deleted.';
$string['close_history'] = 'Close';
$string['history_action'] = 'History';
$string['history_header'] = 'Question history';
Expand Down
12 changes: 12 additions & 0 deletions question/bank/history/tests/behat/question_history_action.feature
Expand Up @@ -43,3 +43,15 @@ Feature: Use the qbank plugin manager page for question history
And the "History" action should not exist for the "First question" question in the question bank
And I click on "#qbank-history-close" "css_element"
And the "History" action should exist for the "First question" question in the question bank

@javascript
Scenario: Delete question from the history using Edit question menu
Given I am on the "Test quiz" "mod_quiz > question bank" page logged in as "admin"
And I choose "History" action for "First question" in the question bank
When I choose "Delete" action for "First question" in the question bank
And I press "Delete"
And I should not see "First question"
Then I should see "All versions of this question have been deleted."
And I click on "Continue" "button"
And I should see "Question bank"
And I should not see "First question"

0 comments on commit e954482

Please sign in to comment.