From 71a7537edd7e1067b545b1fe53a62b75b586a5ef Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Mon, 12 Sep 2022 20:34:19 +0100 Subject: [PATCH] MDL-75729 reportbuilder: improve handling of card toggle button. --- lang/en/reportbuilder.php | 1 + .../classes/table/custom_report_table.php | 14 ++++-- reportbuilder/tests/behat/cardview.feature | 44 ++++++++++++++++--- 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/lang/en/reportbuilder.php b/lang/en/reportbuilder.php index 69e828f669a..b648ecf4bf0 100644 --- a/lang/en/reportbuilder.php +++ b/lang/en/reportbuilder.php @@ -254,6 +254,7 @@ $string['selectareportsource'] = 'Select a report source'; $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'; diff --git a/reportbuilder/classes/table/custom_report_table.php b/reportbuilder/classes/table/custom_report_table.php index ac915fb5ecc..20eb7112e69 100644 --- a/reportbuilder/classes/table/custom_report_table.php +++ b/reportbuilder/classes/table/custom_report_table.php @@ -313,14 +313,20 @@ class custom_report_table extends base_report_table { $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; diff --git a/reportbuilder/tests/behat/cardview.feature b/reportbuilder/tests/behat/cardview.feature index 8dd39164f7b..a2ccbe6a2d3 100644 --- a/reportbuilder/tests/behat/cardview.feature +++ b/reportbuilder/tests/behat/cardview.feature @@ -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" @@ -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" @@ -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 | | + | 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 "" "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 |