From 90d658ae56fcd2ad0da8ed7ab2f37e48b038ef9a Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 12 Aug 2021 15:28:40 +0000 Subject: [PATCH] Bug 22605: Add ability to edit a search on staff interface This patch adds the ability to parse the current search and populate the advanced search page on the staff side accordingly. When searching you will now have an 'Edit this search' link underneath your current search terms A few notes: 1 - Previous selected items appear with a checkbox, unchecking 'disables' them and removes from the search 2 - Facets and unrecognized limits will appear at the end of the form under 'Other limits' - there could be future enhancement to parse there better, but I believe this is sufficient for now 3 - Previously selected branch or group selections will populate the dropdowns, only one is allowed To test: 1 - Perform a variety of search on the staff interface 2 - Confirm the 'edit search' button appear below your search 3 - Confirm that options are retained and correctly parsed 4 - Test with library groups - you should be able to combine groups after initial search, or remove individual libraries when editing 5 - Test that selecting a goup disables the individual libraries options QA note: Missing filters on deletion of keys form hash are false positives https://bugs.koha-community.org/show_bug.cgi?id=26605 Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Katrin Fischer Signed-off-by: Fridolin Somers --- catalogue/search.pl | 90 +++++----- .../prog/en/includes/subtype_limits.inc | 49 ++++++ .../prog/en/modules/catalogue/advsearch.tt | 154 ++++++++++++++---- .../prog/en/modules/catalogue/results.tt | 3 +- 4 files changed, 217 insertions(+), 79 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/subtype_limits.inc diff --git a/catalogue/search.pl b/catalogue/search.pl index 9892429631..ef7f49088f 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -168,8 +168,15 @@ my $cgi = CGI->new; # decide which template to use my $template_name; my $template_type; -my @params = $cgi->multi_param("limit"); -if ((@params>=1) || (defined $cgi->param("q") && $cgi->param("q") ne "" ) || ($cgi->param('multibranchlimit')) || ($cgi->param('limit-yr')) ) { +# limits are used to limit to results to a pre-defined category such as branch or language +my @limits = map uri_unescape($_), $cgi->multi_param("limit"); +my @nolimits = map uri_unescape($_), $cgi->multi_param('nolimit'); +my %is_nolimit = map { $_ => 1 } @nolimits; +@limits = grep { not $is_nolimit{$_} } @limits; +if ( + !$cgi->param('edit_search') && + ( (@limits>=1) || (defined $cgi->param("q") && $cgi->param("q") ne "" ) || ($cgi->param('limit-yr')) ) + ) { $template_name = 'catalogue/results.tt'; $template_type = 'results'; } @@ -248,6 +255,32 @@ $template->param( searchid => scalar $cgi->param('searchid'), ); # The following should only be loaded if we're bringing up the advanced search template if ( $template_type eq 'advsearch' ) { + my $expanded = $cgi->param('expanded_options'); + if( $cgi->param('edit_search') ){ + my @operators = $cgi->multi_param('op'); + my @indexes = $cgi->multi_param('idx'); + my %limit_hash; + foreach my $limit (@limits){ + if ( $limit eq 'available' ){ + $template->param( limit_available => 1 ); + } else { + my ($index,$value) = split(':',$limit); + $value =~ s/"//g; + if ( $index =~ /mc-/ ){ + $limit_hash{$index . "_" . $value} = 1; + } else { + push @{$limit_hash{$index}}, $value; + } + } + }; + $expanded = 1 if scalar @operators || scalar @limits; + $template->param( operators => \@operators ); + $template->param( limits => \%limit_hash ); + $template->param( + indexes => \@indexes, + sort => $cgi->param('sort_by'), + ); + } # load the servers (used for searching -- to do federated searching, etc.) my $primary_servers_loop;# = displayPrimaryServers(); $template->param(outer_servers_loop => $primary_servers_loop,); @@ -264,44 +297,21 @@ if ( $template_type eq 'advsearch' ) { $template->param( sort_by => $default_sort_by ); } - # determine what to display next to the search boxes (ie, boolean option - # shouldn't appear on the first one, scan indexes should, adding a new - # box should only appear on the last, etc. - my @search_boxes_array; - my $search_boxes_count = 3; # begin with 3 boxes - # FIXME: all this junk can be done in TMPL using __first__ and __last__ - for (my $i=1;$i<=$search_boxes_count;$i++) { - # if it's the first one, don't display boolean option, but show scan indexes - if ($i==1) { - push @search_boxes_array, {scan_index => 1}; - } - # if it's the last one, show the 'add field' box - elsif ($i==$search_boxes_count) { - push @search_boxes_array, - { - boolean => 1, - add_field => 1, - }; - } - else { - push @search_boxes_array, - { - boolean => 1, - }; - } - + # determine what to display next to the search boxes + my @queries = $cgi->multi_param('q'); + while( scalar @queries < 3 ){ + push @queries, ""; } - $template->param(uc(C4::Context->preference("marcflavour")) => 1, - search_boxes_loop => \@search_boxes_array); + $template->param(uc(C4::Context->preference("marcflavour")) =>1 ); # load the language limits (for search) my $languages_limit_loop = getLanguages($lang, 1); $template->param(search_languages_loop => $languages_limit_loop,); + $template->param( queries => \@queries ); # Expanded search options in advanced search: # use the global setting by default, but let the user override it { - my $expanded = $cgi->param('expanded_options'); $expanded = C4::Context->preference("expandedSearchOption") || 0 if !defined($expanded) || $expanded !~ /^0|1$/; $template->param( expanded_options => $expanded ); @@ -372,12 +382,6 @@ if ($operands[0] && !$operands[1]) { $template->param(ms_value => $ms_query); } -# limits are use to limit to results to a pre-defined category such as branch or language -my @limits = map uri_unescape($_), $cgi->multi_param('limit'); -my @nolimits = map uri_unescape($_), $cgi->multi_param('nolimit'); -my %is_nolimit = map { $_ => 1 } @nolimits; -@limits = grep { not $is_nolimit{$_} } @limits; - my $available; foreach my $limit(@limits) { if ($limit =~/available/) { @@ -391,7 +395,7 @@ my $limit_yr; my $limit_yr_value; if ($params->{'limit-yr'}) { if ($params->{'limit-yr'} =~ /\d{4}/) { - $limit_yr = "yr,st-numeric=$params->{'limit-yr'}"; + $limit_yr = "yr,st-numeric:$params->{'limit-yr'}"; $limit_yr_value = $params->{'limit-yr'}; } push @limits,$limit_yr; @@ -570,6 +574,11 @@ for (my $i=0;$i<@servers;$i++) { # set up parameters if user wishes to re-run the search # as a Z39.50 search $template->param (z3950_search_params => C4::Search::z3950_search_args($z3950par || $query_desc)); + $template->param(limit_cgi => $limit_cgi); + $template->param(query_cgi => $query_cgi); + $template->param(query_desc => $query_desc); + $template->param(limit_desc => $limit_desc); + $template->param(offset => $offset); if ($hits) { $template->param(total => $hits); @@ -578,11 +587,6 @@ for (my $i=0;$i<@servers;$i++) { $limit_cgi_not_availablity =~ s/&limit=available//g; $template->param(limit_cgi_not_availablity => $limit_cgi_not_availablity); } - $template->param(limit_cgi => $limit_cgi); - $template->param(query_cgi => $query_cgi); - $template->param(query_desc => $query_desc); - $template->param(limit_desc => $limit_desc); - $template->param(offset => $offset); $template->param(DisplayMultiPlaceHold => $DisplayMultiPlaceHold); if ($query_desc || $limit_desc) { $template->param(searchdesc => 1); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/subtype_limits.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/subtype_limits.inc new file mode 100644 index 0000000000..1ac57b4ff2 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/subtype_limits.inc @@ -0,0 +1,49 @@ +[%- BLOCK subtype_limits_description -%] + [%- SWITCH subtype_limit -%] + [%- CASE 'aud:a' -%]Preschool + [%- CASE 'aud:b' -%]Primary + [%- CASE 'aud:c' -%]Pre-adolescent + [%- CASE 'aud:d' -%]Adolescent + [%- CASE 'aud:e' -%]Adult + [%- CASE 'aud:f' -%]Specialized + [%- CASE 'aud:g' -%]General + [%- CASE 'aud:j' -%]Juvenile + [%- CASE 'fic:1' -%]Fiction + [%- CASE 'fic:0' -%]Non-fiction + [%- CASE 'bio:b' -%]Biography + [%- CASE 'mus:j' -%]Musical recording + [%- CASE 'mus:i' -%]Non-musical recording + [%- CASE 'l-format:ta' -%]Regular print + [%- CASE 'l-format:tb' -%]Large print + [%- CASE 'l-format:tc or l-format:fb' -%]Braille + [%- CASE '' -%]----------- + [%- CASE 'l-format:sd' -%]CD audio + [%- CASE 'l-format:ss' -%]Cassette recording + [%- CASE 'l-format:vf' -%]VHS tape / Videocassette + [%- CASE 'l-format:vd' -%]DVD video / Videodisc + [%- CASE 'l-format:co' -%]CD software + [%- CASE 'l-format:cr' -%]Website + [%- CASE 'ctype:a' -%]Abstracts / Summaries + [%- CASE 'ctype:b' -%]Bibliographies + [%- CASE 'ctype:c' -%]Catalogs + [%- CASE 'ctype:d' -%]Dictionaries + [%- CASE 'ctype:e' -%]Encyclopedias + [%- CASE 'ctype:f' -%]Handbooks + [%- CASE 'ctype:g' -%]Legal articles + [%- CASE 'ctype:i' -%]Indexes + [%- CASE 'ctype:j' -%]Patent document + [%- CASE 'ctype:k' -%]Discographies + [%- CASE 'ctype:l' -%]Legislation + [%- CASE 'ctype:m' -%]Theses + [%- CASE 'ctype:n' -%]Surveys + [%- CASE 'ctype:o' -%]Reviews + [%- CASE 'ctype:p' -%]Programmed texts + [%- CASE 'ctype:q' -%]Filmographies + [%- CASE 'ctype:r' -%]Directories + [%- CASE 'ctype:s' -%]Statistics + [%- CASE 'ctype:t' -%]Technical reports + [%- CASE 'ctype:v' -%]Legal cases and case notes + [%- CASE 'ctype:w' -%]Law reports and digests + [%- CASE 'ctype:z' -%]Treaties + [%- END -%] +[%- END -%] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt index db8a8f6156..762c624056 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt @@ -12,7 +12,7 @@ - - - - - [% END %] - [% END %] - [% INCLUDE 'search_indexes.inc' %] - - [% IF ( expanded_options ) %] - [% IF ( search_box.add_field ) %] - [+] - [% END %] - [% IF ( search_box.scan_index ) %] - - [% END %] + [% SET opindex = loop.index - 1 %] + + [% ELSE %] +
+ [% END %] + [% SET preselect = 'ms_' _ indexes.${loop.index}.replace(',','comma') %] + [% INCLUDE 'search_indexes.inc' %] + + [% IF ( expanded_options ) %] + [+] + [% IF ( loop.first ) %] + + [% END %] + [% END %]
[% END %] [% IF Koha.Preference('SearchEngine') == 'Elasticsearch' %] @@ -171,9 +177,32 @@ [% FOREACH itemtypeloo IN advsearchloo.code_loop %] - - [% IF ( loop.last ) %][% ELSE %][% UNLESS ( loop.count % 5 ) %][% END %][% END %] + + [% IF ( loop.last ) %] + + [% ELSE %] + [% UNLESS ( loop.count % 5 ) %] + + + [% END %] + [% END %] [% END %]
+ [% SET limit_key = 'mc-' _ itemtypeloo.ccl _ "_" _ itemtypeloo.code %] + [% IF limits.$limit_key.defined %] + [% limits.delete( limit_key ) %] + + [% ELSE %] + + [% END %] + +
@@ -186,16 +215,22 @@

-   (format: yyyy-yyyy)

+ [% SET year_limit_key = 'yr,st-numeric' %] +   (format: yyyy-yyyy)

+ [% IF limits.$year_limit_key.defined %] + [% limits.delete(year_limit_key) %] + [% END %]

- [% PROCESS language_limit_select ln_loop=search_languages_loop ln_id='language-limit' ln_index='ln' %] + [% PROCESS language_limit_select ln_loop=search_languages_loop ln_id='language-limit' ln_index='ln' selected = limits.${'ln,rtrn'}.0 %] + [% limits.delete( 'ln,rtrn' ) %] - [% PROCESS language_limit_select ln_loop=search_languages_loop ln_id='language-original-limit' ln_index='language-original' %] + [% PROCESS language_limit_select ln_loop=search_languages_loop ln_id='language-original-limit' ln_index='language-original' selected = limits.${'language-original,rtrn'}.0 %] + [% limits.delete( 'language-original,rtrn' ) %]

@@ -207,10 +242,24 @@ [% IF ( UNIMARC ) %] [% INCLUDE 'subtypes_unimarc.inc' %] [% ELSE %] +[% PROCESS 'subtype_limits.inc' %]
Subtype limits

- + +

Current subtype limits + [% FOREACH subtype IN ['aud','fic','bio','ctype','l-format'] %] + [% FOREACH limit IN limits.$subtype %] + + + + + + [% END %] + [% limits.delete( subtype ) %] + [% END %] +
+

+ [% IF limit_available %] +

+ [% ELSE %] +

+ [% END %]

[% IF search_groups %]

OR

@@ -298,9 +352,14 @@ [% FOREACH sg IN search_groups %] [% UNLESS sg.branchcode %] - + [% IF limits.multibranchlimit.0 == sg.id %] + + [% ELSE %] + + [% END %] [% END %] [% END %] + [% limits.delete('multibranchlimit') %]

[% END %] @@ -308,11 +367,29 @@
+ +[% IF limits.size %] +
Other limits +

+ [% FOREACH key IN limits.keys %] + [% FOREACH limit IN limits.$key %] + + + + + + [% END %] + [% END %] +

+
+[% END %] + +
Sorting

@@ -366,6 +443,13 @@ }); [% END %] + if( $("#current_subtype_limits input").length == 0 ){ + $("#current_subtype_limits").hide(); + } + $(".toggle_limit").on('click',function(){ + $(this).siblings("[type='hidden']").prop('disabled', !this.checked); + }); + [% IF searchid %] browser = KOHA.browser('[% searchid | html %]'); browser.show_back_link(); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt index 7488f2be16..0251cbe792 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt @@ -74,6 +74,7 @@

[% total | html %] result(s) found [% IF ( query_desc ) %]for '[% query_desc | html %]'[% END %][% IF limit_desc %] with limit(s): '[% limit_desc | html %]'[% END %][% IF ( LibraryName ) %] in [% LibraryName | html %] Catalog[% END %].

+ Edit this search
@@ -327,6 +328,7 @@ [% IF CAN_user_acquisition_order_manage && searchtoorder_basketno && searchtoorder_vendorid %][%# Coming from the basket or vendor view %]

View basket

[% END %] + Edit this search [% ELSE %]

You did not specify any search criteria.

[% END %] @@ -729,7 +731,6 @@ query_desc: "[% To.json( query_desc ) | html %]", query_cgi: "[% query_cgi | html %]", limit_cgi: "[% limit_cgi | html %]", - sort_cgi: "[% sort_cgi | html %]", sort_by: "[% sort_by | html %]", gotoPage: "[% gotoPage | html %]", gotoNumber: "[% gotoNumber | html %]", -- 2.39.5