forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-81714 grades: Display "Run now" button for admins in task indicator
- Loading branch information
1 parent
4eb6a4d
commit 91cdc95
Showing
7 changed files
with
96 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,7 @@ Feature: Asynchronous regrade on a large course | |
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 not see "Run now" | ||
And I should see "0.0%" | ||
And "user-grades" "table" should not exist | ||
When I run all adhoc tasks | ||
|
@@ -100,3 +101,17 @@ Feature: Asynchronous regrade on a large course | |
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 that disappears once the task starts running | ||
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 "Run now" | ||
And I should see "0.0%" | ||
And "user-grades" "table" should not exist | ||
When I run all adhoc tasks | ||
# Progress bar should update. | ||
Then I should not see "Task pending" | ||
And I should not see "Run now" | ||
And I should see "Recalculating grades" | ||
And I should see "100%" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,9 +16,11 @@ | |
|
||
namespace core\output; | ||
|
||
use core\plugin_manager; | ||
use core\task\adhoc_task; | ||
use core\task\stored_progress_task_trait; | ||
use core\url; | ||
use core\context\system; | ||
use renderer_base; | ||
use stdClass; | ||
use renderable; | ||
|
@@ -27,6 +29,11 @@ | |
/** | ||
* Indicator for displaying status and progress of a background task | ||
* | ||
* This will display a section containing an icon, heading and message describing the background task being performed, | ||
* as well as a progress bar that is updated as the task progresses. Optionally, it will redirect to a given URL (or reload | ||
* the current one) when the task completes. If the task is still waiting in the queue, an admin viewing the indicator | ||
* will also see a "Run now" button. | ||
* | ||
* @package core | ||
* @copyright 2024 onwards Catalyst IT EU {@link https://catalyst-eu.net} | ||
* @author Mark Johnson <[email protected]> | ||
|
@@ -39,6 +46,12 @@ class task_indicator implements renderable, templatable { | |
/** @var ?stored_progress_bar $progressbar */ | ||
protected ?stored_progress_bar $progressbar; | ||
|
||
/** @var ?url $runurl The URL to manually run the task. */ | ||
protected ?url $runurl = null; | ||
|
||
/** @var string $runlabel Label for the link to run the task. */ | ||
protected string $runlabel = ''; | ||
|
||
/** | ||
* Find the task record, and get the progress bar object. | ||
* | ||
|
@@ -83,6 +96,16 @@ protected function setup_task_data(): void { | |
$this->task->set_id($this->taskrecord->id); | ||
$idnumber = stored_progress_bar::convert_to_idnumber($this->task::class, $this->task->get_id()); | ||
$this->progressbar = stored_progress_bar::get_by_idnumber($idnumber); | ||
// As long as the tool_task plugin hasn't been removed, | ||
// allow admins to trigger the task manually if it's not running yet. | ||
if ( | ||
array_key_exists('task', plugin_manager::instance()->get_present_plugins('tool')) | ||
&& is_null($this->taskrecord->timestarted) | ||
&& has_capability('moodle/site:config', system::instance()) | ||
) { | ||
$this->runurl = new url('/admin/tool/task/run_adhoctasks.php', ['id' => $this->taskrecord->id]); | ||
$this->runlabel = get_string('runnow', 'tool_task'); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -106,8 +129,10 @@ public function export_for_template(renderer_base $output): array { | |
$export['message'] = $this->message; | ||
$export['progress'] = $this->progressbar->export_for_template($output); | ||
$export['icon'] = $this->icon ? $this->icon->export_for_template($output) : ''; | ||
$export['redirecturl'] = $this->redirecturl->out(); | ||
$export['redirecturl'] = $this->redirecturl?->out(); | ||
$export['extraclasses'] = implode(' ', $this->extraclasses); | ||
$export['runurl'] = $this->runurl?->out(); | ||
$export['runlabel'] = $this->runlabel; | ||
$this->progressbar->init_js(); | ||
} | ||
return $export; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters