Bugzilla – Attachment 78649 Details for
Bug 12460
Search history: Combine to start a new search
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 12460: Simplify interface to combine queries
Bug-12460-Simplify-interface-to-combine-queries.patch (text/plain), 14.08 KB, created by
Julian Maurice
on 2018-09-14 12:38:26 UTC
(
hide
)
Description:
Bug 12460: Simplify interface to combine queries
Filename:
MIME Type:
Creator:
Julian Maurice
Created:
2018-09-14 12:38:26 UTC
Size:
14.08 KB
patch
obsolete
>From b004a4187598a513866a29dbbc57135bff868395 Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Thu, 22 Feb 2018 16:48:23 +0100 >Subject: [PATCH] Bug 12460: Simplify interface to combine queries > >The complicated interface using 'Match any/Match all', checkboxes and >'NOT' selectors is replaced by a simple textbox which expects queries >like this: > > (#1 or #3) and #6 > >where 1, 3 and 6 are IDs in search_history table. > >A new column in the table show these ids. >--- > C4/Search/History.pm | 32 +++++++++ > catalogue/search-history.pl | 32 ++------- > .../en/modules/catalogue/search-history.tt | 70 ++++--------------- > .../en/modules/opac-search-history.tt | 58 +++------------ > opac/opac-search-history.pl | 43 ++---------- > 5 files changed, 64 insertions(+), 171 deletions(-) > >diff --git a/C4/Search/History.pm b/C4/Search/History.pm >index 7463a65684..277d81b2b6 100644 >--- a/C4/Search/History.pm >+++ b/C4/Search/History.pm >@@ -228,6 +228,38 @@ sub set_to_session { > uri_escape( encode_json($search_history) ) ); > } > >+sub get_query { >+ my ($id, $borrowernumber, $lang, $default) = @_; >+ >+ my $searches = C4::Search::History::get({ >+ type => 'biblio', >+ userid => $borrowernumber, >+ id => $id, >+ }); >+ >+ if (ref $searches eq 'ARRAY' && scalar @$searches > 0) { >+ my $search = $searches->[0]; >+ my $scgi = new CGI($search->{query_cgi}); >+ my @operators = map uri_unescape($_), $scgi->multi_param('op'); >+ my @indexes = map uri_unescape($_), $scgi->multi_param('idx'); >+ my @operands = map uri_unescape($_), $scgi->multi_param('q'); >+ my @limits = map uri_unescape($_), $scgi->multi_param('limit'); >+ my @sort_by = $scgi->multi_param('sort_by'); >+ my $scan = $scgi->param('scan'); >+ >+ require C4::Search; >+ my ( undef, $query ) = >+ C4::Search::buildQuery( \@operators, \@operands, \@indexes, \@limits, \@sort_by, >+ $scan, $lang ); >+ >+ return "($query)"; >+ } >+ >+ # Default if not found >+ return "allrecords,alwaysmatches=''"; >+} >+ >+ > 1; > > __END__ >diff --git a/catalogue/search-history.pl b/catalogue/search-history.pl >index 411ebe169c..6ec282a314 100755 >--- a/catalogue/search-history.pl >+++ b/catalogue/search-history.pl >@@ -44,34 +44,10 @@ my $action = $cgi->param('action') || q{list}; > if ( $action eq 'search' ) { > # Start a new search > >- my @ids = $cgi->multi_param('id'); >- my @nots = $cgi->multi_param('not'); >- my $searches = C4::Search::History::get({ >- userid => $loggedinuser, >- id => \@ids, >- }); >- my @ccl_queries; >- foreach my $search (@$searches) { >- my $scgi = new CGI($search->{query_cgi}); >- my @operators = map uri_unescape($_), $scgi->multi_param('op'); >- my @indexes = map uri_unescape($_), $scgi->multi_param('idx'); >- my @operands = map uri_unescape($_), $scgi->multi_param('q'); >- my @limits = map uri_unescape($_), $scgi->multi_param('limit'); >- my @sort_by = $scgi->param('sort_by'); >- my $scan = $scgi->param('scan'); >- my $lang = C4::Languages::getlanguage($cgi); >- my ( $error, $query ) = >- buildQuery( \@operators, \@operands, \@indexes, \@limits, \@sort_by, >- $scan, $lang ); >- >- if (grep {$_ == $search->{id}} @nots) { >- $query = "allrecords,alwaysmatches='' not ($query)"; >- } >- >- push @ccl_queries, $query; >- } >- my $join = ($cgi->param('join') eq 'or') ? 'or' : 'and'; >- my $query = 'ccl=(' . join(") $join (", @ccl_queries) . ')'; >+ my $lang = C4::Languages::getlanguage($cgi); >+ my $search = $cgi->param('search'); >+ $search =~ s|#(\d+)|C4::Search::History::get_query($1, $loggedinuser, $lang)|eg; >+ my $query = "ccl=$search"; > print $cgi->redirect("/cgi-bin/koha/catalogue/search.pl?q=$query"); > exit; > } elsif ( $action eq 'delete' ) { >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/search-history.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/search-history.tt >index 4238ca8ac0..d4748015ca 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/search-history.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/search-history.tt >@@ -6,22 +6,8 @@ > [% USE date %] > > [% BLOCK search_history_table %] >- <form action="/cgi-bin/koha/catalogue/search-history.pl" method="get"> >+ <form action="/cgi-bin/koha/catalogue/search-history.pl" method="get" class="datatable"> > [%# Search from multiple lines is only enabled for biblios %] >- [% IF type == 'biblio' %] >- <div> >- <a href="#" class="action_search">Start a new search</a> >- <span class='search_options'> >- <span>New search:</span> >- <select name='join'> >- <option value="or" selected="selected">match any of selected searches</option> >- <option value="and">match all of selected searches</option> >- </select> >- <button type="submit">Go</button> >- <a href="#" class="action_search_cancel">Cancel</a> >- </span> >- </div> >- [% END %] > <div class="selections-toolbar"> > <a class="CheckAll" href="#"><i class="fa fa-check"></i> Select all visible rows</a> > <span class="sep">|</span> >@@ -37,7 +23,7 @@ > <thead> > <tr> > <th></th> >- <th class="not">Not</th> >+ <th>Id</th> > <th>Session date</th> > <th>Date</th> > <th>Search</th> >@@ -48,12 +34,7 @@ > [% FOREACH s IN searches %] > <tr> > <td><input type="checkbox" name="id" value="[% s.id %]" /></td> >- <td class="not"> >- <select name="not"> >- <option value=""></option> >- <option value="[% s.id %]" title="Search for the opposite of the criteria on this row">NOT</option> >- </select> >- </td> >+ <td>#[% s.id %]</td> > <td> > [% IF s.session %] > [% session_ctime = date.format(s.session.session_ctime, '%Y-%m-%d %H:%M:%S') %] >@@ -83,6 +64,14 @@ > </tbody> > </table> > </form> >+ >+ [% IF type == 'biblio' %] >+ <form method="post"> >+ <input type="hidden" name="action" value="search"/> >+ <input type="text" name="search" placeholder="(#1 or #3) and #6"/> >+ <button type="submit">Combine queries</button> >+ </form> >+ [% END %] > [% END %] > > [% INCLUDE 'doc-head-open.inc' %] >@@ -145,8 +134,7 @@ > "aaSorting": [[ 3, "desc" ]], > "aoColumnDefs": [ > { "aTargets": [ 0, 1 ], "bSortable": false, "bSearchable": false }, >- { "aTargets": [ 2, 3 ], "sType": "title-string" }, >- { "aTargets": [ 1 ], "bVisible": false } >+ { "aTargets": [ 2, 3 ], "sType": "title-string" } > ], > "sPaginationType": "full_numbers" > })); >@@ -156,7 +144,7 @@ > // DataTables removes hidden rows from the DOM, so we can't expect a > // "regular" submit to work and we need to build another form containing > // all form elements, and then submit this form. >- $('#tabs form').submit(function(e) { >+ $('#tabs form.datatable').submit(function(e) { > e.preventDefault(); > > var form = $(this); >@@ -218,38 +206,6 @@ > return false; > }); > >- $(".action_search").click(function() { >- var $form = $(this).parents('form'); >- var table = $form.find('table').dataTable(); >- var $checked = table.$('input:checkbox:checked'); >- $(this).hide(); >- $('.search_options').show(); >- table.fnSetColumnVis(1, true); >- return false; >- }); >- >- $('.search_options button[type="submit"]').click(function() { >- var $form = $(this).parents('form'); >- var table = $form.find('table').dataTable(); >- var $checked = table.$('input:checkbox:checked'); >- if ($checked.length) { >- $form.find('input[name="action"]').val('search'); >- $form.submit(); >- } else { >- alert(_("You have to select searches first")); >- } >- return false; >- }); >- >- $('.action_search_cancel').click(function() { >- var form = $(this).parents('form').first(); >- var table = form.find('table').dataTable(); >- $('.action_search').show(); >- $('.search_options').hide(); >- table.fnSetColumnVis(1, false); >- return false; >- }).click(); >- > $('#tabs form').each(function() { > enableCheckboxActions($(this)); > }); >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-search-history.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-search-history.tt >index 9ba19a98d3..fda42c9d3e 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-search-history.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-search-history.tt >@@ -5,21 +5,8 @@ > [% USE date %] > > [% BLOCK search_history_table %] >- <form action="/cgi-bin/koha/opac-search-history.pl" method="get"> >+ <form action="/cgi-bin/koha/opac-search-history.pl" method="get" class="datatable"> > <div> >- [% IF type == 'biblio' %] >- <a href="#" class="action_search">Start a new search</a> >- <span class='search_options form-inline'> >- <span>New search:</span> >- <select name='join'> >- <option value="or" selected="selected">match any of selected searches</option> >- <option value="and">match all of selected searches</option> >- </select> >- <button type="submit">Go</button> >- <a href="#" class="action_search_cancel">Cancel</a> >- </span> >- >- [% END %] > </div> > <div class="selections-toolbar toolbar"> > <a class="CheckAll" href="#">Select all</a> >@@ -35,7 +22,7 @@ > <thead> > <tr> > <th></th> >- <th class="not">Not</th> >+ <th>Id</th> > [% IF hide_session_column %] > <th class="hide">Session date</th> > [% ELSE %] >@@ -50,12 +37,7 @@ > [% FOREACH s IN searches %] > <tr> > <td><input type="checkbox" name="id" value="[% s.id %]" /></td> >- <td class="not"> >- <select name="not"> >- <option value=""></option> >- <option value="[% s.id %]" title="Search for the opposite of the criteria on this row">NOT</option> >- </select> >- </td> >+ <td>#[% s.id %]</td> > [% IF hide_session_column %] > <td class="hide"> > [% ELSE %] >@@ -96,6 +78,14 @@ > </table> > <input type="submit" class="btn btn-danger remove-selected" value="Remove selected searches"> > </form> >+ >+ [% IF type == 'biblio' %] >+ <form method="post" class="form-inline"> >+ <input type="hidden" name="action" value="search"/> >+ <input type="text" name="search" placeholder="(#1 or #3) and #6"/> >+ <button type="submit" class="btn btn-default">Combine queries</button> >+ </form> >+ [% END %] > [% END %] > > [% INCLUDE 'doc-head-open.inc' %] >@@ -214,32 +204,6 @@ > } > return false; > }); >- $(".action_search").click(function() { >- var $form = $(this).parents('form'); >- $(this).hide(); >- $('.search_options').show(); >- $('.not').show(); >- return false; >- }); >- >- $('.search_options button[type="submit"]').click(function() { >- var $form = $(this).parents('form'); >- var $checked = $form.find('input:checkbox:checked'); >- if ($checked.length ) { >- $form.find('input[name="action"]').val('search'); >- $form.submit(); >- } else { >- alert(_("You have to select searches first")); >- } >- return false; >- }); >- >- $('.action_search_cancel').click(function() { >- $('.action_search').show(); >- $('.search_options').hide(); >- $('.not').hide(); >- return false; >- }).click(); > > $('form').each(function() { > enableCheckboxActions(this); >diff --git a/opac/opac-search-history.pl b/opac/opac-search-history.pl >index 07830c67ce..479f115d60 100755 >--- a/opac/opac-search-history.pl >+++ b/opac/opac-search-history.pl >@@ -57,45 +57,10 @@ my $action = $cgi->param('action') || q{}; > if ( $action eq 'search' ) { > # Start a new search > >- my @ids = $cgi->multi_param('id'); >- my @nots = $cgi->multi_param('not'); >- my @searches; >- if ($loggedinuser) { >- @searches = @{ C4::Search::History::get({ >- userid => $loggedinuser, >- id => \@ids, >- }) }; >- } else { >- @searches = C4::Search::History::get_from_session({ cgi => $cgi }); >- if ( @ids ) { >- @searches = map { >- my $search = $_; >- ( grep {/^$search->{id}$/} @ids ) ? $_ : () >- } @searches; >- } >- } >- my @ccl_queries; >- foreach my $search (@searches) { >- my $scgi = new CGI($search->{query_cgi}); >- my @operators = map uri_unescape($_), $scgi->multi_param('op'); >- my @indexes = map uri_unescape($_), $scgi->multi_param('idx'); >- my @operands = map uri_unescape($_), $scgi->multi_param('q'); >- my @limits = map uri_unescape($_), $scgi->multi_param('limit'); >- my @sort_by = $scgi->multi_param('sort_by'); >- my $scan = $scgi->param('scan'); >- my $lang = C4::Languages::getlanguage($cgi); >- my ( $error, $query ) = >- buildQuery( \@operators, \@operands, \@indexes, \@limits, \@sort_by, >- $scan, $lang ); >- >- if (grep {$_ == $search->{id}} @nots) { >- $query = "allrecords,alwaysmatches='' not ($query)"; >- } >- >- push @ccl_queries, $query; >- } >- my $join = ($cgi->param('join') eq 'or') ? 'or' : 'and'; >- my $query = 'ccl=(' . join(") $join (", @ccl_queries) . ')'; >+ my $lang = C4::Languages::getlanguage($cgi); >+ my $search = $cgi->param('search'); >+ $search =~ s|#(\d+)|C4::Search::History::get_query($1, $loggedinuser, $lang)|eg; >+ my $query = "ccl=$search"; > print $cgi->redirect("/cgi-bin/koha/opac-search.pl?q=$query"); > exit; > } elsif ( $action eq 'delete' ) { >-- >2.17.1
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 12460
:
29102
|
35699
|
41782
|
42450
|
59384
|
72091
|
72092
|
78648
| 78649 |
78650