MDL-80912 reportbuilder: output table caption when rendering reports.

Move the `get_name` method to the base report class, so that it can be
implemented by all report types. Provide a default implementation for
system reports based on the name of the class.

Use the name of the report as the caption. Target via Behat selectors.
This commit is contained in:
Paul Holden 2024-02-16 14:56:52 +00:00
parent d3ad77e476
commit 1acca870d9
No known key found for this signature in database
GPG Key ID: A81A96D6045F6164
7 changed files with 49 additions and 31 deletions

View File

@ -47,13 +47,6 @@ abstract class datasource extends base {
/** @var array $activeconditions */
private $activeconditions;
/**
* Return user friendly name of the datasource
*
* @return string
*/
abstract public static function get_name(): string;
/**
* Add columns from the given entity name to be available to use in a custom report
*

View File

@ -116,6 +116,13 @@ abstract class base {
return $this->report;
}
/**
* Return user friendly name of the report
*
* @return string
*/
abstract public static function get_name(): string;
/**
* Initialise report. Specify which columns, filters, etc should be present
*
@ -732,11 +739,11 @@ abstract class base {
* Set if the report can be downloaded.
*
* @param bool $downloadable
* @param string $downloadfilename If the report is downloadable, then a filename should be provided here
* @param string|null $downloadfilename If downloadable, then the name of the file (defaults to the name of the current report)
*/
final public function set_downloadable(bool $downloadable, string $downloadfilename = 'export'): void {
final public function set_downloadable(bool $downloadable, ?string $downloadfilename = null): void {
$this->downloadable = $downloadable;
$this->downloadfilename = $downloadfilename;
$this->downloadfilename = $downloadfilename ?? static::get_name();
}
/**

View File

@ -70,6 +70,19 @@ abstract class system_report extends base {
parent::__construct($report);
}
/**
* Provide default implementation of the report name. Extending classes can implement this method to provide their own name
*
* @return string
*/
public static function get_name(): string {
$classparts = explode('\\', get_called_class());
$classname = end($classparts);
// Try to make human readable, capitalized and with spaces.
return ucfirst(str_replace('_', ' ', $classname));
}
/**
* Validates access to view this report
*

View File

@ -273,7 +273,9 @@ abstract class base_report_table extends table_sql implements dynamic, renderabl
$this->wrap_html_start();
$this->set_caption($this->report::get_name(), ['class' => 'sr-only']);
echo html_writer::start_tag('div');
echo html_writer::start_tag('table', $this->attributes);
echo html_writer::start_tag('table', $this->attributes) . $this->render_caption();
}
}

View File

@ -20,18 +20,18 @@ Feature: Manage custom reports
And I click on "Save" "button" in the "New report" "dialogue"
Then I should see "My report"
# Confirm we see the default columns in the report.
And I should see "Full name" in the "reportbuilder-table" "table"
And I should see "Username" in the "reportbuilder-table" "table"
And I should see "Email address" in the "reportbuilder-table" "table"
And I should see "Full name" in the "Users" "table"
And I should see "Username" in the "Users" "table"
And I should see "Email address" in the "Users" "table"
# Confirm we see the default sorting in the report
And "Admin User" "table_row" should appear before "User 2" "table_row"
And I click on "Show/hide 'Sorting'" "button"
And "Disable initial sorting for column 'Full name'" "checkbox" should exist in the "#settingssorting" "css_element"
And I click on "Show/hide 'Sorting'" "button"
# Confirm we only see not suspended users in the report.
And I should see "Admin User" in the "reportbuilder-table" "table"
And I should see "User 2" in the "reportbuilder-table" "table"
And I should not see "User 1" in the "reportbuilder-table" "table"
And I should see "Admin User" in the "Users" "table"
And I should see "User 2" in the "Users" "table"
And I should not see "User 1" in the "Users" "table"
# Confirm we see the default conditions in the report.
And I click on "Show/hide 'Conditions'" "button"
Then I should see "Full name" in the "[data-region='settings-conditions']" "css_element"
@ -47,7 +47,7 @@ Feature: Manage custom reports
Then I should see "Username" in the "[data-region='report-filters']" "css_element"
Then I should see "Email address" in the "[data-region='report-filters']" "css_element"
And I click on "Close 'My report' editor" "button"
And the following should exist in the "reportbuilder-table" table:
And the following should exist in the "Reports list" table:
| Name | Report source | Modified by |
| My report | Users | Admin User |
@ -67,7 +67,7 @@ Feature: Manage custom reports
Then I should see "My report"
And I should see "Nothing to display"
And I click on "Close 'My report' editor" "button"
And the following should exist in the "reportbuilder-table" table:
And the following should exist in the "Reports list" table:
| Name | Report source |
| My report | Users |
@ -110,7 +110,7 @@ Feature: Manage custom reports
And I set the field "Edit report name" in the "My report" "table_row" to " "
And I set the field "Edit report name" in the "My report" "table_row" to "My renamed report"
And I reload the page
Then the following should exist in the "reportbuilder-table" table:
Then the following should exist in the "Reports list" table:
| Name | Report source |
| My renamed report | Users |
@ -124,8 +124,8 @@ Feature: Manage custom reports
When I navigate to "Reports > Report builder > Custom reports" in site administration
And I set the field "Edit report name" in the "My report" "table_row" to "<span class=\"multilang\" lang=\"en\">English</span><span class=\"multilang\" lang=\"es\">Spanish</span>"
And I reload the page
Then I should see "English" in the "reportbuilder-table" "table"
And I should not see "Spanish" in the "reportbuilder-table" "table"
Then I should see "English" in the "Reports list" "table"
And I should not see "Spanish" in the "Reports list" "table"
# Confirm report name is correctly shown in action.
And I press "Delete report" action in the "English" report row
And I should see "Are you sure you want to delete the report 'English' and all associated data?" in the "Delete report" "dialogue"
@ -142,7 +142,7 @@ Feature: Manage custom reports
| Name | My renamed report |
And I click on "Save" "button" in the "Edit report details" "dialogue"
Then I should see "Report updated"
And the following should exist in the "reportbuilder-table" table:
And the following should exist in the "Reports list" table:
| Name | Report source |
| My renamed report | Users |
@ -158,7 +158,7 @@ Feature: Manage custom reports
| <filter> value | <value> |
And I click on "Apply" "button" in the "[data-region='report-filters']" "css_element"
Then I should see "Filters applied"
And I should see "My users" in the "reportbuilder-table" "table"
And I should see "My users" in the "Reports list" "table"
Examples:
| filter | value |
| Name | My users |
@ -247,10 +247,10 @@ Feature: Manage custom reports
When I am on the "Report users" "reportbuilder > Editor" page logged in as "admin"
Then I should see "Viewing of report data while editing is disabled by the site administrator. Switch to preview mode to view the report." in the "[data-region='core_table/dynamic']" "css_element"
And I click on "Switch to preview mode" "button"
And I should see "admin" in the "reportbuilder-table" "table"
And I should see "admin" in the "Users" "table"
And I click on "Close 'Report users' editor" "button"
And I press "View" action in the "Report users" report row
And I should see "admin" in the "reportbuilder-table" "table"
And I should see "admin" in the "Users" "table"
Scenario Outline: Download custom report in different formats
Given the following "users" exist:

View File

@ -40,7 +40,7 @@ Feature: Manage custom report schedules
And I set the field "Manually added users: User One, User Two" to "1"
And I click on "Save" "button" in the "New schedule" "dialogue"
Then I should see "Schedule created"
And the following should exist in the "reportbuilder-table" table:
And the following should exist in the "Report schedules" table:
| Name | Starting from | Time last sent | Modified by |
| My schedule | ##tomorrow 11:00##%A, %d %B %Y, %H:%M## | Never | Admin User |
@ -64,7 +64,7 @@ Feature: Manage custom report schedules
And I click on the "Schedules" dynamic tab
When I set the field "Edit schedule name" in the "My schedule" "table_row" to "My renamed schedule"
And I reload the page
Then I should see "My renamed schedule" in the "reportbuilder-table" "table"
Then I should see "My renamed schedule" in the "Report schedules" "table"
Scenario: Rename report schedule using filters
Given the "multilang" filter is "on"
@ -76,8 +76,8 @@ Feature: Manage custom report schedules
And I click on the "Schedules" dynamic tab
When I set the field "Edit schedule name" in the "My schedule" "table_row" to "<span class=\"multilang\" lang=\"en\">English</span><span class=\"multilang\" lang=\"es\">Spanish</span>"
And I reload the page
Then I should see "English" in the "reportbuilder-table" "table"
And I should not see "Spanish" in the "reportbuilder-table" "table"
Then I should see "English" in the "Report schedules" "table"
And I should not see "Spanish" in the "Report schedules" "table"
# Confirm schedule name is correctly shown in actions.
And I press "Send schedule" action in the "English" report row
And I should see "Are you sure you want to queue the schedule 'English' for sending immediately?" in the "Send schedule" "dialogue"
@ -109,7 +109,7 @@ Feature: Manage custom report schedules
| All users: All site users | 1 |
And I click on "Save" "button" in the "Edit schedule details" "dialogue"
Then I should see "Schedule updated"
And the following should exist in the "reportbuilder-table" table:
And the following should exist in the "Report schedules" table:
| Name | Starting from |
| My updated schedule | ##tomorrow 11:00##%A, %d %B %Y, %H:%M## |

View File

@ -9,6 +9,9 @@ Information provided here is intended especially for developers.
* New method `get_table_aliases` in base entity class, for retrieving all table aliases in a single call
* The database helper `generate_alias[es]` and `generate_param_name[s]` methods now accept an optional `$suffix` argument for
appending additional string to the generated value
* The `get_name` method has been moved to the base report class and can now be implemented for both custom and system reports, it
will be used as the caption when rendering tables (which can also be targeted in Behat scenarios)
* The default value for the filename when calling `set_downloadable` is now taken from calling `get_name` on the current report
* The base datasource `add_all_from_entity` method accepts additional parameters to limit which columns, filters and conditions
are added. The `add_[columns|filters|conditions]_from_entity` class methods also now support wildcard matching in both `$include`
and `$exclude` parameters