This commit is contained in:
Andrew Nicols 2025-03-11 22:32:15 +08:00
commit b85b7a61ad
No known key found for this signature in database
GPG Key ID: 6D1E3157C8CFBF14
2 changed files with 55 additions and 31 deletions

View File

@ -232,7 +232,7 @@ abstract class base_report_table extends table_sql implements dynamic, renderabl
*/
public function get_sql_sort() {
$columnsbyalias = $this->report->get_active_columns_by_alias();
$columnsortby = $columnsortbyalias = [];
$columnsortby = [];
// First pass over sorted columns, to extract all the fullname fields from table_sql.
$sortedcolumns = $this->get_sort_columns();
@ -245,32 +245,30 @@ abstract class base_report_table extends table_sql implements dynamic, renderabl
$column = $columnsbyalias[$alias] ?? null;
// If the column is not being aggregated and defines custom sort fields, then use them.
if ($column && !$column->get_aggregation() &&
($sortfields = $column->get_sort_fields())) {
if ($column && !$column->get_aggregation() && ($sortfields = $column->get_sort_fields())) {
foreach ($sortfields as $sortfield) {
$columnsortby[$sortfield] = $order;
if (!array_key_exists($sortfield, $columnsortby)) {
$columnsortby[$sortfield] = $order;
}
}
} else if (array_key_exists($alias, $sortedcolumnsfullname)) {
// Ensure that magic fullname sorted columns refer to correct alias.
foreach ($columnsbyalias as $column) {
$sortfieldalias = array_filter(
$column->get_sort_fields(),
fn(string $key) => preg_match("/^c[\d]+_{$alias}$/", $key),
);
if (count($sortfieldalias) > 0) {
$columnsortby[reset($sortfieldalias)] = $order;
break;
}
}
} else {
$columnsortby[$alias] = $order;
}
}
// Now ensure that any fullname sorted columns have duplicated aliases removed.
foreach ($columnsortby as $sortfield => $dir) {
if (array_key_exists($sortfield, $sortedcolumnsfullname)) {
$sortfieldalias = array_filter(
$columnsortby,
fn(string $key) => preg_match("/^c[\d]+_{$sortfield}$/", $key),
ARRAY_FILTER_USE_KEY,
);
$columnsortbyalias[array_key_first($sortfieldalias)] = $dir;
} else if (!array_key_exists($sortfield, $columnsortbyalias)) {
$columnsortbyalias[$sortfield] = $dir;
}
}
return static::construct_order_by($columnsortbyalias);
return static::construct_order_by($columnsortby);
}
/**

View File

@ -1,4 +1,4 @@
@core @core_tag
@core @core_tag @core_reportbuilder
Feature: Users can edit tags to add description or rename
In order to use tags
As a manager
@ -8,9 +8,10 @@ Feature: Users can edit tags to add description or rename
Given the following "users" exist:
| username | firstname | lastname | email | interests |
| manager1 | Manager | 1 | manager1@example.com | |
| user1 | User | 1 | user1@example.com | Cat,Dog,Turtle |
| user1 | User | One | user1@example.com | Cat,Dog,Turtle |
| user2 | User | Two | user2@example.com | |
| editor1 | Editor | 1 | editor1@example.com | |
Given the following "roles" exist:
And the following "roles" exist:
| name | shortname |
| Tag editor | tageditor |
And the following "system role assigns" exist:
@ -37,7 +38,7 @@ Feature: Users can edit tags to add description or rename
And I click on "Site pages" "list_item" in the "Navigation" "block"
And I click on "Tags" "link" in the "Navigation" "block"
And I follow "Turtle"
And I follow "User 1"
And I follow "User One"
And I follow "Cat"
And I follow "Edit this tag"
And I should not see "Tag name"
@ -64,7 +65,7 @@ Feature: Users can edit tags to add description or rename
And I click on "Site pages" "list_item" in the "Navigation" "block"
And I click on "Tags" "link" in the "Navigation" "block"
And I follow "Turtle"
And I follow "User 1"
And I follow "User One"
And I follow "Cat"
And I follow "Edit this tag"
And I set the following fields to these values:
@ -98,7 +99,7 @@ Feature: Users can edit tags to add description or rename
And I add the "Navigation" block if not present
And I click on "Tags" "link" in the "Navigation" "block"
And I follow "Turtle"
And I follow "User 1"
And I follow "User One"
And I follow "Cat"
And I follow "Edit this tag"
And I set the following fields to these values:
@ -160,7 +161,7 @@ Feature: Users can edit tags to add description or rename
And I follow "Default collection"
# Renaming tag to a valid name
And I set the field "Edit tag name" in the "Cat" "table_row" to "Kitten"
Then the following should not exist in the "reportbuilder-table" table:
Then the following should not exist in the "Tags" table:
| First name | Tag name |
| Admin User | Cat |
And I reload the page
@ -222,6 +223,27 @@ Feature: Users can edit tags to add description or rename
And I should see "Turtle"
And I should not see "Neverusedtag"
@javascript
Scenario: Sorting tags
When I log in as "user2"
And I open my profile in edit mode
And I expand all fieldsets
And I set the field "List of interests" to "Goat"
And I press "Update profile"
And I log out
And I log in as "manager1"
And I navigate to "Appearance > Manage tags" in site administration
And I follow "Default collection"
# Sort by users name.
And I click on "Last name" "link" in the "Tags" "table"
Then "Admin User" "table_row" should appear before "User Two" "table_row"
And I click on "Last name" "link" in the "Tags" "table"
And "User Two" "table_row" should appear before "Admin User" "table_row"
And I click on "First name" "link" in the "Tags" "table"
And "Admin User" "table_row" should appear before "User Two" "table_row"
And I click on "First name" "link" in the "Tags" "table"
And "User Two" "table_row" should appear before "Admin User" "table_row"
@javascript
Scenario: Filtering tags
When I log in as "manager1"
@ -232,7 +254,11 @@ Feature: Users can edit tags to add description or rename
| Tag name operator | Is equal to |
| Tag name value | Cat,Dog |
And I click on "Apply" "button" in the "[data-region='report-filters']" "css_element"
Then I should see "Cat" in the "reportbuilder-table" "table"
And I should see "Dog" in the "reportbuilder-table" "table"
And I should not see "Turtle" in the "reportbuilder-table" "table"
And I should not see "Neverusedtag" in the "reportbuilder-table" "table"
Then the following should exist in the "Tags" table:
| Tag name |
| Cat |
| Dog |
And the following should not exist in the "Tags" table:
| Tag name |
| Turtle |
| Neverusedtag |