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>
This commit is contained in:
Nick Clemens 2019-07-30 15:20:27 +00:00 committed by Martin Renvoize
parent e26ab5d790
commit 7c97f5263d
Signed by: martin.renvoize
GPG key ID: 422B469130441A0F
4 changed files with 12 additions and 7 deletions

View file

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

View file

@ -701,6 +701,7 @@ canned reports and writing custom SQL reports.</p>
[% ELSE %]
<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 -%]">
[% IF (sql_param.include_all) %]<option value="%">All</option>[% END %]
[% FOREACH value IN sql_param.input.values %]
<option value="[%- value | html -%]">[%- sql_param.input.labels.$value | html -%]</option>
[% END %]

View file

@ -719,11 +719,12 @@ elsif ($phase eq 'Run this report'){
my @authval_errors;
my %uniq_params;
for(my $i=0;$i<($#split/2);$i++) {
my ($text,$authorised_value) = split /\|/,$split[$i*2+1];
my $sep = $authorised_value ? "|" : "";
if( defined $uniq_params{$text.$sep.$authorised_value} ){
my ($text,$authorised_value_all) = split /\|/,$split[$i*2+1];
my $sep = $authorised_value_all ? "|" : "";
if( defined $uniq_params{$text.$sep.$authorised_value_all} ){
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 $labelid;
if ( not defined $authorised_value ) {
@ -815,7 +816,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,
'name' => $name,

View file

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