MDL-68256 task admin: usability improvements

In the table that lists the scheduled tasks:

1. There are badges to show which components are disabled.
2. The plugin name (e.g. auth_ldap) is shown as well as the
   human-readable name (e.g. LDAP server).
3. Where a time column has a non-default value, it is highlighted
   and the default is shown.
4. If the fail-delay is non-zero, the cell is highlighted.
4. If you just interacted with a task (looked at or edited the settings,
   did Run now, or cleared the fail delay) that row is highlighted,
   and scrolled into view when the page loads.

To support this, some of the methods for loading the default tasks
have been extended with an optional argument to leave 'R' as 'R'
rather than replacing with a random number.

Also, mixed into this commit are a bunch of coding style improvements.
Sorry I did not separate them out, but ultimately this makes the
Moodle code better.
This commit is contained in:
Tim Hunt
2020-03-28 18:40:51 +00:00
parent d939d6e769
commit 6fdc0f8796
12 changed files with 157 additions and 78 deletions
+17 -10
View File
@@ -40,9 +40,11 @@ class manager {
* Given a component name, will load the list of tasks in the db/tasks.php file for that component.
*
* @param string $componentname - The name of the component to fetch the tasks for.
* @param bool $expandr - if true (default) an 'R' value in a time is expanded to an appropriate int.
* If false, they are left as 'R'
* @return \core\task\scheduled_task[] - List of scheduled tasks for this component.
*/
public static function load_default_scheduled_tasks_for_component($componentname) {
public static function load_default_scheduled_tasks_for_component($componentname, $expandr = true) {
$dir = \core_component::get_component_directory($componentname);
if (!$dir) {
@@ -65,7 +67,7 @@ class manager {
foreach ($tasks as $task) {
$record = (object) $task;
$scheduledtask = self::scheduled_task_from_record($record);
$scheduledtask = self::scheduled_task_from_record($record, $expandr);
// Safety check in case the task in the DB does not match a real class (maybe something was uninstalled).
if ($scheduledtask) {
$scheduledtask->set_component($componentname);
@@ -318,9 +320,11 @@ class manager {
* Utility method to create a task from a DB record.
*
* @param \stdClass $record
* @return \core\task\scheduled_task
* @param bool $expandr - if true (default) an 'R' value in a time is expanded to an appropriate int.
* If false, they are left as 'R'
* @return \core\task\scheduled_task|false
*/
public static function scheduled_task_from_record($record) {
public static function scheduled_task_from_record($record, $expandr = true) {
$classname = self::get_canonical_class_name($record->classname);
if (!class_exists($classname)) {
debugging("Failed to load task: " . $classname, DEBUG_DEVELOPER);
@@ -342,10 +346,10 @@ class manager {
}
$task->set_blocking(!empty($record->blocking));
if (isset($record->minute)) {
$task->set_minute($record->minute);
$task->set_minute($record->minute, $expandr);
}
if (isset($record->hour)) {
$task->set_hour($record->hour);
$task->set_hour($record->hour, $expandr);
}
if (isset($record->day)) {
$task->set_day($record->day);
@@ -354,7 +358,7 @@ class manager {
$task->set_month($record->month);
}
if (isset($record->dayofweek)) {
$task->set_day_of_week($record->dayofweek);
$task->set_day_of_week($record->dayofweek, $expandr);
}
if (isset($record->faildelay)) {
$task->set_fail_delay($record->faildelay);
@@ -429,15 +433,18 @@ class manager {
* This function load the default scheduled task details for a given classname.
*
* @param string $classname
* @return \core\task\scheduled_task or false
* @param bool $expandr - if true (default) an 'R' value in a time is expanded to an appropriate int.
* If false, they are left as 'R'
* @return \core\task\scheduled_task|false
*/
public static function get_default_scheduled_task($classname) {
public static function get_default_scheduled_task($classname, $expandr = true) {
$task = self::get_scheduled_task($classname);
$componenttasks = array();
// Safety check in case no task was found for the given classname.
if ($task) {
$componenttasks = self::load_default_scheduled_tasks_for_component($task->get_component());
$componenttasks = self::load_default_scheduled_tasks_for_component(
$task->get_component(), $expandr);
}
foreach ($componenttasks as $componenttask) {