Bugzilla – Attachment 161247 Details for
Bug 35746
Multiple selections for parameters used in the IN function
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35746: Add multiselect to report dropdowns
Bug-35746-Add-multiselect-to-report-dropdowns.patch (text/plain), 7.78 KB, created by
Brendan Lawlor
on 2024-01-22 15:17:14 UTC
(
hide
)
Description:
Bug 35746: Add multiselect to report dropdowns
Filename:
MIME Type:
Creator:
Brendan Lawlor
Created:
2024-01-22 15:17:14 UTC
Size:
7.78 KB
patch
obsolete
>From 37ae37f89291117ed0194ee39318128ccf083f4d Mon Sep 17 00:00:00 2001 >From: Brendan Lawlor <blawlor@clamsnet.org> >Date: Fri, 19 Jan 2024 21:25:34 +0000 >Subject: [PATCH] Bug 35746: Add multiselect to report dropdowns > >This work in progress patch adds the ability to use multi select in report dropdowns. > >It uses syntax similar to using a list and when using the :all option >WHERE i.homebranch in <<Select libraries|brnaches:in>> > >Currently this works but fails qa scripts because of some forbidden regex > >Test plan: >1. Create an SQL report with with new syntax for multi select > SELECT > i.homebranch, > count(*) > FROM items i > WHERE i.homebranch in <<Select libraries|branches:in>> > GROUP BY i.homebranch >2. Save the report >3. Note that you get the error > The authorized value category (branches:in) you selected does not exist. >4. Apply the patch and repeat steps 1 and 2 >5. Note the report saves successfully >6. Run the report >7. Note the select dropdown is now a multiselect >8. Run the report with multiple selections >10. Click show SQL and note that multi select parameters get inserted into the query like: > WHERE i.homebranch in ('CPL', 'FFL', 'FPL') >11. Test other types of queries with multiple multi selects and lists etc >--- > C4/Reports/Guided.pm | 14 ++--------- > Koha/Report.pm | 2 +- > .../modules/reports/guided_reports_start.tt | 24 +++++++++++++++++-- > reports/guided_reports.pl | 11 +++++++-- > 4 files changed, 34 insertions(+), 17 deletions(-) > >diff --git a/C4/Reports/Guided.pm b/C4/Reports/Guided.pm >index a55cd17743..6e450ea8af 100644 >--- a/C4/Reports/Guided.pm >+++ b/C4/Reports/Guided.pm >@@ -574,17 +574,7 @@ sub execute_query { > my ( $is_sql_valid, $errors ) = Koha::Report->new({ savedsql => $sql })->is_sql_valid; > return (undef, @{$errors}[0]) unless $is_sql_valid; > >- foreach my $sql_param ( @$sql_params ){ >- if ( $sql_param =~ m/\n/ ){ >- my @list = split /\n/, $sql_param; >- my @quoted_list; >- foreach my $item ( @list ){ >- $item =~ s/\r//; >- push @quoted_list, C4::Context->dbh->quote($item); >- } >- $sql_param = "(".join(",",@quoted_list).")"; >- } >- } >+ > > my ($useroffset, $userlimit); > >@@ -974,7 +964,7 @@ sub GetParametersFromSQL { > > for ( my $i = 0; $i < ($#split/2) ; $i++ ) { > my ($name,$authval) = split(/\|/,$split[$i*2+1]); >- $authval =~ s/\:all$// if $authval; >+ $authval =~ s/\:all$|\:in$// if $authval; > push @sql_parameters, { 'name' => $name, 'authval' => $authval }; > } > >diff --git a/Koha/Report.pm b/Koha/Report.pm >index 55daece836..c99e8f60fc 100644 >--- a/Koha/Report.pm >+++ b/Koha/Report.pm >@@ -169,7 +169,7 @@ sub prep_report { > # } > # ) if $quoted; > #} >- unless ( $split[ $i * 2 + 1 ] =~ /\|\s*list\s*$/ && $quoted ) { >+ unless ( $split[ $i * 2 + 1 ] =~ /\|\s*list\s*$\|\s*\:in\s*$/ && $quoted ) { > $quoted = C4::Context->dbh->quote($quoted); > } > else { >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt >index 74d9315a4e..21e6bdc125 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt >@@ -842,7 +842,7 @@ > [% END # /IF ( warn_authval_problem )%] > > [% IF ( enter_params ) %] >- <form action='/cgi-bin/koha/reports/guided_reports.pl'> >+ <form action='/cgi-bin/koha/reports/guided_reports.pl' id='report_param_form'> > <input type='hidden' name='reports' value="[% reports | html %]" /> > [% IF ( auth_val_error ) %] > <input type='hidden' name='phase' value='Edit SQL' /> >@@ -883,10 +883,13 @@ > [% ELSE %] > <li> > <label for="sql_params_[% sql_param.labelid | html %]">[% sql_param.entry | html %]:</label> >- <select name="[%- sql_param.input.name | html -%]" tabindex="1" id="[%- sql_param.input.id | html -%]"> >+ <select name="[%- sql_param.input.name | html -%]" tabindex="1" id="[%- sql_param.input.id | html -%]" [%- sql_param.select_multiple | html -%]> > [% IF (sql_param.include_all) %] > <option value="%">All</option> > [% END %] >+ [% IF (sql_param.select_multiple) %] >+ <option value="null" hidden></option> >+ [% END %] > [% FOREACH value IN sql_param.input.values %] > <option value="[%- value | html -%]">[%- sql_param.input.labels.$value | html -%]</option> > [% END %] >@@ -1535,6 +1538,23 @@ > > <script> > >+ // if the report param form has multiselects overide default form submission >+ if( $('#report_param_form').find('select[multiple]').length ) { >+ $('#report_param_form').find('select[multiple]').each( function (i) { >+ $(this).on('change', function() { >+ var $selected = $(this).val().join('\n'); >+ $(this).find('option:first').val($selected); >+ }); >+ }); >+ >+ $('#report_param_form').on('submit', function(e) { >+ $('#report_param_form').find('select[multiple]').each( function (i) { >+ var $selected = $('option:first', this).val(); >+ $(this).val($selected); >+ }); >+ }); >+ } >+ > function hide_bar_element() { > $('#chart-column-horizontal').hide() > $('.chart-column-group').each(function( index ) { >diff --git a/reports/guided_reports.pl b/reports/guided_reports.pl >index 85b42c4efb..a04489e3ea 100755 >--- a/reports/guided_reports.pl >+++ b/reports/guided_reports.pl >@@ -710,7 +710,14 @@ elsif ($phase eq 'Run this report'){ > if( defined $uniq_params{$text.$sep.$authorised_value_all} ){ > next; > } else { $uniq_params{$text.$sep.$authorised_value_all} = "$i"; } >- my ($authorised_value, $all) = split /:/, $authorised_value_all; >+ my ($authorised_value, $param_options) = split /:/, $authorised_value_all; >+ my $all; >+ my $multiple; >+ if ($param_options eq "all") { >+ $all = "all"; >+ } elsif ($param_options eq "in") { >+ $multiple = "multiple"; >+ } > my $input; > my $labelid; > if ( not defined $authorised_value ) { >@@ -829,7 +836,7 @@ elsif ($phase eq 'Run this report'){ > }; > } > >- push @tmpl_parameters, {'entry' => $text, 'input' => $input, 'labelid' => $labelid, 'name' => $text.$sep.$authorised_value_all, 'include_all' => $all }; >+ push @tmpl_parameters, {'entry' => $text, 'input' => $input, 'labelid' => $labelid, 'name' => $text.$sep.$authorised_value_all, 'include_all' => $all, 'select_multiple' => $multiple}; > } > $template->param('sql' => $sql, > 'name' => $name, >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 35746
:
160880
|
160995
|
161224
|
161247
|
161248
|
162300
|
162303
|
163875
|
163920
|
163921
|
165276
|
165333
|
165334
|
165345
|
165659
|
165660