Bug 23389: Add 'All' option to report dropdowns

This patch optionally adds an 'all' option to report dropdowns

Note you will need to use 'LIKE' instead of '=' to allow 'All' to work

To test:
 1 - Write a report:
     SELECT branchname FROM branches WHERE branchcode LIKE <<Branch|branches>>
 2 - Run it
 3 - Select a branch
 4 - You get one branch info
 5 - Note you cannot select all
 6 - Apply patch
 7 - Run report
 8 - No change
 9 - Update report like:
     SELECT branchname FROM branches WHERE branchcode LIKE <<Branch|branches:all>>
10 - Run report
11 - Select 'All'
12 - You get all branches
13 - Select one branch
14 - You get one branch
15 - Test with other authorised categories (itemtypes, YES_NO, etc.)
16 - Confirm it works as expected
17 - Prove -v t/db_dependent/Reports/Guided.t

Signed-off-by: Lisette Scheer <lisetteslatah@gmail.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
(cherry picked from commit 7c97f5263d)
Signed-off-by: Hayley Mapley <hayleymapley@catalyst.net.nz>
This commit is contained in:
Nick Clemens 2019-07-30 15:20:27 +00:00 committed by Hayley Mapley
parent b3e737f96a
commit 3e714ce305
4 changed files with 12 additions and 7 deletions

View File

@ -914,6 +914,7 @@ sub GetParametersFromSQL {
for ( my $i = 0; $i < ($#split/2) ; $i++ ) { for ( my $i = 0; $i < ($#split/2) ; $i++ ) {
my ($name,$authval) = split(/\|/,$split[$i*2+1]); my ($name,$authval) = split(/\|/,$split[$i*2+1]);
$authval =~ s/\:all$// if $authval;
push @sql_parameters, { 'name' => $name, 'authval' => $authval }; push @sql_parameters, { 'name' => $name, 'authval' => $authval };
} }

View File

@ -681,6 +681,7 @@ canned reports and writing custom SQL reports.</p>
[% ELSE %] [% ELSE %]
<li><label for="sql_params_[% sql_param.labelid | html %]">[% sql_param.entry | html %]:</label> <li><label for="sql_params_[% sql_param.labelid | html %]">[% sql_param.entry | html %]:</label>
<select name="[%- sql_param.input.name | html -%]" tabindex="1" size="1" id="[%- sql_param.input.id | html -%]"> <select name="[%- sql_param.input.name | html -%]" tabindex="1" size="1" id="[%- sql_param.input.id | html -%]">
[% IF (sql_param.include_all) %]<option value="%">All</option>[% END %]
[% FOREACH value IN sql_param.input.values %] [% FOREACH value IN sql_param.input.values %]
<option value="[%- value | html -%]">[%- sql_param.input.labels.$value | html -%]</option> <option value="[%- value | html -%]">[%- sql_param.input.labels.$value | html -%]</option>
[% END %] [% END %]

View File

@ -701,11 +701,12 @@ elsif ($phase eq 'Run this report'){
my @authval_errors; my @authval_errors;
my %uniq_params; my %uniq_params;
for(my $i=0;$i<($#split/2);$i++) { for(my $i=0;$i<($#split/2);$i++) {
my ($text,$authorised_value) = split /\|/,$split[$i*2+1]; my ($text,$authorised_value_all) = split /\|/,$split[$i*2+1];
my $sep = $authorised_value ? "|" : ""; my $sep = $authorised_value_all ? "|" : "";
if( defined $uniq_params{$text.$sep.$authorised_value} ){ if( defined $uniq_params{$text.$sep.$authorised_value_all} ){
next; next;
} else { $uniq_params{$text.$sep.$authorised_value} = "$i"; } } else { $uniq_params{$text.$sep.$authorised_value_all} = "$i"; }
my ($authorised_value, $all) = split /:/, $authorised_value_all;
my $input; my $input;
my $labelid; my $labelid;
if ( not defined $authorised_value ) { if ( not defined $authorised_value ) {
@ -797,7 +798,7 @@ elsif ($phase eq 'Run this report'){
}; };
} }
push @tmpl_parameters, {'entry' => $text, 'input' => $input, 'labelid' => $labelid, 'name' => $text.$sep.$authorised_value }; push @tmpl_parameters, {'entry' => $text, 'input' => $input, 'labelid' => $labelid, 'name' => $text.$sep.$authorised_value_all, 'include_all' => $all };
} }
$template->param('sql' => $sql, $template->param('sql' => $sql,
'name' => $name, 'name' => $name,

View File

@ -145,13 +145,15 @@ subtest 'GetParametersFromSQL+ValidateSQLParameters' => sub {
FROM old_issues FROM old_issues
WHERE YEAR(timestamp) = <<Year|custom_list>> AND WHERE YEAR(timestamp) = <<Year|custom_list>> AND
branchcode = <<Branch|branches>> AND branchcode = <<Branch|branches>> AND
borrowernumber = <<Borrower>> borrowernumber = <<Borrower>> AND
itemtype = <<Item type|itemtypes:all>>
"; ";
my @test_parameters_with_custom_list = ( my @test_parameters_with_custom_list = (
{ 'name' => 'Year', 'authval' => 'custom_list' }, { 'name' => 'Year', 'authval' => 'custom_list' },
{ 'name' => 'Branch', 'authval' => 'branches' }, { 'name' => 'Branch', 'authval' => 'branches' },
{ 'name' => 'Borrower', 'authval' => undef } { 'name' => 'Borrower', 'authval' => undef },
{ 'name' => 'Item type', 'authval' => 'itemtypes' }
); );
is_deeply( GetParametersFromSQL($test_query_1), \@test_parameters_with_custom_list, is_deeply( GetParametersFromSQL($test_query_1), \@test_parameters_with_custom_list,