Skip to content

Commit

Permalink
fixup! MDL-81714 grades: Display "Run now" button for admins in task …
Browse files Browse the repository at this point in the history
…indicator
  • Loading branch information
marxjohnson committed Nov 15, 2024
1 parent 468236e commit 023c769
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,12 @@ if ($taskindicator->has_task_record()) {

{{< /php >}}

When the task begins running and the progress is updated, the progress bar will automatically be displayed.

If the optional `redirecturl` parameter is set when creating the indicator, the page will automatically reload or redirect to
this URL when the progress bar completes.

While the task is still queued, admins will see a "Run now" button below the progress bar. This is designed for convenience if
While the task is still queued, admins will see a "Run now" button below the indicator. This is designed for convenience if
a user is blocked on a job and needs the task run immediately. It will run the specific instance of the task tracked by the
indicator.

Expand All @@ -110,6 +112,7 @@ indicator.
"id": "progressbar_test",
"message": "Task pending",
"idnumber": "progressbar_test",
"class": "stored-progress-bar stored-progress-notstarted",
"width": "500",
"value": "0"
},
Expand Down
41 changes: 17 additions & 24 deletions grade/tests/behat/grade_async_regrade.feature
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,10 @@ Feature: Asynchronous regrade on a large course

Scenario Outline: Task indicator displays on all grade reports when a calculation is pending
Given I am on the "Test course 2" "<report>" page logged in as "<user>"
Then I should not see "Grades are being recalculated due to recent changes."
Then I should not see "The report will update automatically. You don't need to do anything."
And <element> should exist
When I am on the "Test course 1" "<report>" page logged in as "<user>"
Then I should see "Grades are being recalculated due to recent changes."
And I should see "Task pending"
And I should see "0.0%"
Then I should see "The report will update automatically. You don't need to do anything."
And <element> should not exist

Examples:
Expand All @@ -78,10 +76,10 @@ Feature: Asynchronous regrade on a large course
Scenario Outline: Gradebook settings can be accessed when a regrade is pending
Given I am on the "Test course 2" "<page>" page logged in as "teacher1"
Then I should see "<text>"
And I should not see "Grades are being recalculated due to recent changes."
And I should not see "The report will update automatically. You don't need to do anything."
Given I am on the "Test course 1" "<page>" page logged in as "teacher1"
Then I should see "<text>"
And I should not see "Grades are being recalculated due to recent changes."
And I should not see "The report will update automatically. You don't need to do anything."

Examples:
| page | text |
Expand All @@ -93,37 +91,32 @@ Feature: Asynchronous regrade on a large course
When I follow "Grades" in the user menu
And I follow "Test course 2"
Then "table.user-grade" "css_element" should exist
Then I should not see "Grades are being recalculated due to recent changes."
Then I should not see "The report will update automatically. You don't need to do anything."
When I follow "Grades" in the user menu
And I follow "Test course 1"
Then "table.user-grade" "css_element" should not exist
Then I should see "Grades are being recalculated due to recent changes."
Then I should see "The report will update automatically. You don't need to do anything."

Scenario: Task indicator progresses and redirects when the task is run.
When I am on the "Test course 1" "grades > Grader report > View" page logged in as teacher1
And I should see "Grades are being recalculated due to recent changes."
And I should see "Task pending"
And I should see "The report will update automatically. You don't need to do anything."
And I should not see "Run now"
And I should see "0.0%"
And I should not see "0.0%"
And "user-grades" "table" should not exist
When I run all adhoc tasks
And I run all adhoc tasks
# Progress bar should update.
# Manual wait is a bit of a fudge, but we need the progress bar to poll for an update.
And I wait "1" seconds
Then I should not see "Task pending"
And I should see "Recalculating grades"
And I wait until "Recalculating grades" "text" exists
And I should see "100%"
When I wait "2" seconds
# The page should reload after a short delay.
Then I should not see "Grades are being recalculated due to recent changes."
Then I wait until "Recalculating grades" "text" does not exist
And I set the field "Search users" to "Student 1"
And "user-grades" "table" should exist
And "40.00" "text" should exist in the "[email protected]" "table_row"

Scenario: Admin should see a "Run now" button in the task indicator
When I am on the "Test course 1" "grades > Grader report > View" page logged in as admin
And I should see "Grades are being recalculated due to recent changes."
And I should see "Task pending"
And I should see "The report will update automatically. You don't need to do anything."
And I should not see "0.0%"
And I should see "Run now"

Scenario: Making changes on course with less than 100 grades performs the regrade synchronously, no indicator is shown.
Expand All @@ -133,17 +126,17 @@ Feature: Asynchronous regrade on a large course
And I set the field "Maximum grade" to "50"
And I press "Save and return to course"
When I am on the "Test course 2" "grades > Grader report > View" page
Then I should not see "Grades are being recalculated due to recent changes."
Then I should not see "The report will update automatically. You don't need to do anything."
And "user-grades" "table" should exist

Scenario: Editing weights triggers a regrade, but further edits are possible
Given I run all adhoc tasks
And I am on the "Test course 1" "grades > Grader report > View" page logged in as "teacher1"
And I should not see "Grades are being recalculated due to recent changes."
And I should not see "The report will update automatically. You don't need to do anything."
And I am on the "Test course 1" "grades > Gradebook setup" page
When I set the field "Override weight of Test assignment 1" to "1"
And I press "Save changes"
And I am on the "Test course 1" "grades > Grader report > View" page
And I should see "Grades are being recalculated due to recent changes."
And I should see "The report will update automatically. You don't need to do anything."
And I am on the "Test course 1" "grades > Gradebook setup" page
And I should not see "Grades are being recalculated due to recent changes."
And I should not see "The report will update automatically. You don't need to do anything."
2 changes: 1 addition & 1 deletion lib/amd/build/task_indicator.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 lib/amd/build/task_indicator.min.js.map

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

14 changes: 9 additions & 5 deletions lib/amd/src/task_indicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ export default class {
* @param {String} redirectUrl
*/
static init(id, redirectUrl) {
document.getElementById(id).addEventListener('update', (event) => {
// Once progress has started, remove the run link.
const runlink = document.querySelector(`.runlink[data-idnumber=${id}]`);
if (runlink && event.detail.percent > 0) {
runlink.remove();
const bar = document.getElementById(id);
bar.addEventListener('update', (event) => {
if (event.detail.percent > 0) {
// Once progress starts, display the progress bar and remove the run link.
bar.classList.remove('stored-progress-notstarted');
const runlink = document.querySelector(`.runlink[data-idnumber=${id}]`);
if (runlink && event.detail.percent > 0) {
runlink.remove();
}
}
// Once the progress bar completes, redirect the page.
if (redirectUrl !== '' && event.detail.percent === 100) {
Expand Down
8 changes: 5 additions & 3 deletions lib/templates/task_indicator.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"id": "progressbar_test",
"message": "Recalculating grades",
"idnumber": "progressbar_test",
"class": "stored-progress-bar",
"width": "500",
"value": "50"
}
Expand All @@ -48,14 +49,15 @@
<h3>{{heading}}</h3>
<p>{{message}}</p>
</div>
{{#progress}}
{{>core/progress_bar}}
{{/progress}}
{{#runurl}}
<p class="text-center">
<a class="runlink btn btn-primary" href="{{runurl}}" data-idnumber="{{progress.idnumber}}">{{runlabel}}</a>
</p>
{{/runurl}}
{{#progress}}
{{>core/progress_bar}}
{{/progress}}


</div>

Expand Down

0 comments on commit 023c769

Please sign in to comment.