From 7c3e78ca3c9e6713a96ff40b31df26e6b70554a3 Mon Sep 17 00:00:00 2001 From: Nathan Nguyen Date: Tue, 12 Jul 2022 20:59:37 +1000 Subject: [PATCH] MDL-67685 core_admin: use autocomplete filter in task log --- admin/classes/local/entities/task_log.php | 21 +++++++++++++++++++-- admin/tasklogs.php | 3 +-- admin/tests/behat/task_logs.feature | 7 +++---- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/admin/classes/local/entities/task_log.php b/admin/classes/local/entities/task_log.php index 41e7dc26f10..403c54ddfd5 100644 --- a/admin/classes/local/entities/task_log.php +++ b/admin/classes/local/entities/task_log.php @@ -20,12 +20,14 @@ use core_reportbuilder\local\filters\date; use core_reportbuilder\local\filters\duration; use core_reportbuilder\local\filters\select; use core_reportbuilder\local\filters\text; +use core_reportbuilder\local\filters\autocomplete; use core_reportbuilder\local\helpers\format; use lang_string; use core_reportbuilder\local\entities\base; use core_reportbuilder\local\report\column; use core_reportbuilder\local\report\filter; use stdClass; +use core_collator; /** * Task log entity class implementation @@ -241,13 +243,28 @@ class task_log extends base { // Name filter (Filter by classname). $filters[] = (new filter( - text::class, + autocomplete::class, 'name', new lang_string('classname', 'tool_task'), $this->get_entity_name(), "{$tablealias}.classname" )) - ->add_joins($this->get_joins()); + ->add_joins($this->get_joins()) + ->set_options_callback(static function(): array { + global $DB; + $classnames = $DB->get_fieldset_sql('SELECT DISTINCT classname FROM {task_log} ORDER BY classname ASC'); + + $options = []; + foreach ($classnames as $classname) { + if (class_exists($classname)) { + $task = new $classname; + $options[$classname] = $task->get_name(); + } + } + + core_collator::asort($options); + return $options; + }); // Type filter. $filters[] = (new filter( diff --git a/admin/tasklogs.php b/admin/tasklogs.php index 046aaafdcfb..f93814fb397 100644 --- a/admin/tasklogs.php +++ b/admin/tasklogs.php @@ -60,8 +60,7 @@ $report = system_report_factory::create(task_logs::class, context_system::instan if (!empty($filter)) { $report->set_filter_values([ - 'task_log:name_operator' => \core_reportbuilder\local\filters\text::IS_EQUAL_TO, - 'task_log:name_value' => $filter, + 'task_log:name_values' => $filter, ]); } diff --git a/admin/tests/behat/task_logs.feature b/admin/tests/behat/task_logs.feature index f7e4e182504..21ab247ffbe 100644 --- a/admin/tests/behat/task_logs.feature +++ b/admin/tests/behat/task_logs.feature @@ -15,7 +15,6 @@ Feature: View task logs report and use its filters And I navigate to "Server > Tasks > Task logs" in site administration When I click on "Filters" "button" And I set the following fields in the "Class name" "core_reportbuilder > Filter" to these values: - | Class name operator | Contains | | Class name value | | And I click on "Apply" "button" in the "[data-region='report-filters']" "css_element" Then I should see "Filters applied" @@ -27,9 +26,9 @@ Feature: View task logs report and use its filters | Type | Name | | Scheduled | | Examples: - | name | match | nonmatch | - | task\\clean_events | Cleanup event monitor events | Incoming email pickup | - | task\\pickup_task | Incoming email pickup | Cleanup event monitor events | + | name | match | nonmatch | + | Cleanup event monitor events | Cleanup event monitor events | Incoming email pickup | + | Incoming email pickup | Incoming email pickup | Cleanup event monitor events | @javascript # Task duration is dependent on many factors, we are asserting here that no task has a duration >2 minutes.