Skip to content

Commit

Permalink
MDL-75729 reportbuilder: improve handling of card toggle button.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulholden committed Sep 14, 2022
1 parent 8febbe3 commit 4bd6777
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 10 deletions.
1 change: 1 addition & 0 deletions lang/en/reportbuilder.php
Expand Up @@ -247,6 +247,7 @@
$string['sendschedule'] = 'Send schedule';
$string['sendscheduleconfirm'] = 'Are you sure you want to queue the schedule \'{$a}\' for sending immediately?';
$string['showhide'] = 'Show/hide \'{$a}\'';
$string['showhidecard'] = 'Show/hide card';
$string['sorting'] = 'Sorting';
$string['sorting_help'] = 'Sorting defines the initial sort order of columns in the report. The order can be reversed by toggling the Up/down icon. Users can then define their own sort order by clicking on a column name.';
$string['switchedit'] = 'Switch to edit mode';
Expand Down
14 changes: 10 additions & 4 deletions reportbuilder/classes/table/custom_report_table.php
Expand Up @@ -302,14 +302,20 @@ public function get_row_cells_html(string $rowid, array $row, ?array $suppressla
$visiblecolumns = $this->report->get_settings_values()['cardview_visiblecolumns'] ?? 1;
if ($visiblecolumns < count($this->columns)) {
$buttonicon = html_writer::tag('i', '', ['class' => 'fa fa-angle-down']);
$buttonatttributes = [

// We need a cleaned version (without tags/entities) of the first row column to use as toggle button.
$rowfirstcolumn = strip_tags(reset($row));
$buttontitle = $rowfirstcolumn !== ''
? get_string('showhide', 'core_reportbuilder', html_entity_decode($rowfirstcolumn))
: get_string('showhidecard', 'core_reportbuilder');

$button = html_writer::tag('button', $buttonicon, [
'type' => 'button',
'class' => 'btn collapsed',
'title' => get_string('showhide', 'core_reportbuilder', reset($row)),
'title' => $buttontitle,
'data-toggle' => 'collapse',
'data-action' => 'toggle-card'
];
$button = html_writer::tag('button', $buttonicon, $buttonatttributes);
]);
$html .= html_writer::tag('td', $button, ['class' => 'card-toggle d-none']);
}
return $html;
Expand Down
44 changes: 38 additions & 6 deletions reportbuilder/tests/behat/cardview.feature
Expand Up @@ -12,10 +12,10 @@ Feature: Manage card view settings in the report editor
| report | uniqueidentifier |
| My report | user:fullname |
| My report | user:email |
| My report | user:city |
| My report | user:city |
And the following "users" exist:
| username | firstname | lastname | email | city |
| l.smith | Lionel | Smith | lionel@smith.com | Bilbao |
| l.smith | Lionel | Smith | lionel@example.com | Bilbao |

Scenario: Edit card view settings form
When I am on the "My report" "reportbuilder > Editor" page logged in as "admin"
Expand Down Expand Up @@ -50,9 +50,11 @@ Feature: Manage card view settings in the report editor
And I change window size to "530x812"
# Card view should just show user fullname while collapsed with default settings.
And I should see "Lionel Smith" in the "reportbuilder-table" "table"
And I should not see "lionel@smith.com" in the "reportbuilder-table" "table"
And I press "Show/hide 'Lionel Smith'"
And I should see "lionel@smith.com" in the "reportbuilder-table" "table"
And I should not see "lionel@example.com" in the "reportbuilder-table" "table"
And I should not see "Bilbao" in the "reportbuilder-table" "table"
And I click on "Show/hide 'Lionel Smith'" "button" in the "reportbuilder-table" "table"
And I should see "Lionel Smith" in the "reportbuilder-table" "table"
And I should see "lionel@example.com" in the "reportbuilder-table" "table"
And I should see "Bilbao" in the "reportbuilder-table" "table"
# Card view do not show first column title with default settings.
And "[data-cardtitle=\"Full name\"]" "css_element" should not exist in the "reportbuilder-table" "table"
Expand All @@ -70,9 +72,39 @@ Feature: Manage card view settings in the report editor
And I press "Switch to preview mode"
And I change window size to "530x812"
And I should see "Lionel Smith" in the "reportbuilder-table" "table"
And I should see "lionel@smith.com" in the "reportbuilder-table" "table"
And I should see "lionel@example.com" in the "reportbuilder-table" "table"
And I should see "Bilbao" in the "reportbuilder-table" "table"
And "[data-cardtitle=\"Full name\"]" "css_element" should exist in the "reportbuilder-table" "table"
And "[data-cardtitle=\"Email address\"]" "css_element" should exist in the "reportbuilder-table" "table"
And "[data-cardtitle=\"City/town\"]" "css_element" should exist in the "reportbuilder-table" "table"
And "Show/hide 'Lionel Smith'" "button" should not exist

Scenario Outline: Toggle card view according to content of first column
Given the following "core_reportbuilder > Reports" exist:
| name | source | default |
| New report | core_user\reportbuilder\datasource\users | 0 |
And the following "core_reportbuilder > Columns" exist:
| report | uniqueidentifier |
| New report | <firstcolumn> |
| New report | user:email |
And the following "core_reportbuilder > Conditions" exist:
| report | uniqueidentifier |
| New report | user:username |
When I am on the "New report" "reportbuilder > Editor" page logged in as "admin"
And I click on "Show/hide 'Conditions'" "button"
# Make sure we're only viewing our test user in the report.
And I set the following fields in the "Username" "core_reportbuilder > Condition" to these values:
| Username operator | Is equal to |
| Username value | l.smith |
And I click on "Apply" "button" in the "[data-region='settings-conditions']" "css_element"
# Now use the card show/hide toggle.
And I change window size to "530x812"
And I press "Switch to preview mode"
And I should not see "lionel@example.com" in the "reportbuilder-table" "table"
And I click on "<togglebutton>" "button" in the "reportbuilder-table" "table"
Then I should see "lionel@example.com" in the "reportbuilder-table" "table"
Examples:
| firstcolumn | togglebutton |
| user:fullnamewithlink | Show/hide 'Lionel Smith' |
| user:firstname | Show/hide 'Lionel' |
| user:idnumber | Show/hide card |

0 comments on commit 4bd6777

Please sign in to comment.