From: senator Date: Mon, 21 Feb 2011 19:42:38 +0000 (-0500) Subject: big ol' commit making advanced search work, albeit with issues X-Git-Tag: opac-tt-poc-demo2~7 X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=684a218db75389d169abf50cc882fb7cb4ab9370;p=evergreen%2Fequinox.git big ol' commit making advanced search work, albeit with issues most obvious issue is that advanced search leads to a result page that renders with a basic search form filled out in a silly-looking way I'm thinking it'd be best when showing results from an advanced search to *not* show that basic search form, but instead have a hidden version of the advanced search form, prepopulated, revealable by a button labeled "refine your search" or something. That way we'd not have to worry about reversing query parser syntax back into broken-out widget values. make sense? --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm index 2d826cd30d..e294aab279 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm @@ -8,6 +8,85 @@ use OpenILS::Application::AppUtils; my $U = 'OpenILS::Application::AppUtils'; +sub _prepare_biblio_search_basics { + my ($cgi) = @_; + + my %parts; + my @part_names = qw/class contains query/; + $parts{$_} = [ $cgi->param($_) ] for (@part_names); + + my @chunks = (); + for (my $i = 0; $i < scalar @{$parts{'class'}}; $i++) { + my ($class, $contains, $query) = map { $parts{$_}->[$i] } @part_names; + + push(@chunks, $class . ':') unless $class eq 'keyword' and $i == 0; + + # This stuff probably will need refined or rethought to better handle + # the weird things Real Users will surely type in. + if ($contains eq 'nocontains') { + $query =~ s/"//g; + $query = ('"' . $query . '"') if index $query, ' '; + $query = '-' . $query; + } elsif ($contains eq 'exact') { + $query =~ s/"//g; + $query = ('"' . $query . '"') if index $query, ' '; + } + push @chunks, $query; + } + + return join(' ', @chunks); +} + +sub _prepare_biblio_search { + my ($cgi, $ctx) = @_; + + my $query = _prepare_biblio_search_basics($cgi); + my $args = {}; + + $args->{'org_unit'} = $cgi->param('loc') || $ctx->{aou_tree}->()->id; + $args->{'depth'} = defined $cgi->param('depth') ? + $cgi->param('depth') : + $ctx->{find_aou}->($args->{'org_unit'})->ou_type->depth; + + if ($cgi->param('available')) { + $query = '#available ' . $query; + } + + if ($cgi->param('format')) { + $args->{'format'} = join('', $cgi->param('format')); + } + + if ($cgi->param('lang')) { + # XXX TODO find out how to build query with multiple langs, if that + # even needs to be a feature of adv search. + $query .= ' lang:' . $cgi->param('lang'); + } + + if ($cgi->param('audience')) { + $query .= ' audience(' . $cgi->param('audience') . ')'; + } + + if (defined $cgi->param('sort')) { + my $sort = $cgi->param('sort'); + my $sort_order = $cgi->param('sort_order'); + $query .= " sort($sort)"; + $query .= '#' . $sort_order if $sort_order and $sort ne 'rel'; + } + + if ($cgi->param('pubyear_how') && $cgi->param('pubyear1')) { + if ($cgi->param('pubyear_how') eq 'between') { + $query .= ' between(' . $cgi->param('pubyear1'); + $query .= ',' . $cgi->param('pubyear2') if $cgi->param('pubyear2'); + $query .= ')'; + } else { + $query .= ' ' . $cgi->param('pubyear_how') . + '(' . $cgi->param('pubyear1') . ')'; + } + } + + return ($args, $query); +} + # context additions: # page_size # hit_count @@ -20,25 +99,19 @@ sub load_rresults { $ctx->{page} = 'rresult'; my $page = $cgi->param('page') || 0; - my $item_type = $cgi->param('item_type'); my $facet = $cgi->param('facet'); - my $query = $cgi->param('query'); - my $search_class = $cgi->param('class'); my $limit = $cgi->param('limit') || 10; # TODO user settings - my $loc = $cgi->param('loc') || $ctx->{aou_tree}->()->id; - my $depth = defined $cgi->param('depth') ? - $cgi->param('depth') : $ctx->{find_aou}->($loc)->ou_type->depth; + my ($args, $query) = _prepare_biblio_search($cgi, $ctx); - my $args = { - limit => $limit, offset => $page * $limit, - org_unit => $loc, depth => $depth, $item_type ? (item_type => [$item_type]) : () - }; + # Stuff these into the TT context so that templates can use them in redrawing forms + $ctx->{processed_search_query} = $query; + $ctx->{processed_search_args} = $args; + + $args->{'limit'} = $limit; + $args->{'offset'} = $page * $limit; $query = "$query $facet" if $facet; # TODO - # XXX Since open-ils.search is a public service, it is responsible for - # being wary of injection/bad input, not us, right? - $query = $search_class . ':' . $query if $search_class; my $results; diff --git a/Open-ILS/web/css/skin/default/opac/semiauto.css b/Open-ILS/web/css/skin/default/opac/semiauto.css index 550669f04c..68edb5e686 100644 --- a/Open-ILS/web/css/skin/default/opac/semiauto.css +++ b/Open-ILS/web/css/skin/default/opac/semiauto.css @@ -136,11 +136,11 @@ .opac-auto-149 { position: relative; top: 5px; left: 25px; } #util_print_btn { position: relative; top: 5px; left: 30px; } .opac-auto-151 { position: relative; top: 75px; } -.opac-auto-152 { position: relative; top: -9px; } +#adv_reset { position: relative; top: -9px; } .opac-auto-153 { position: relative; z-index: 100; } .text-center { text-align: center; } .opac-auto-156 { text-align: center; font-weight: bold; } -.opac-auto-157 { text-align: center; margin-top: 20px; width: 400px; } +#adv_quick_search_sidebar { text-align: center; margin-top: 20px; width: 400px; } .opac-auto-158 { text-align: center; margin-top: 6px; margin-bottom: 6px } .opac-auto-159 { text-align: center; padding: 20px; width: 100% } .opac-auto-160 { text-align: center; padding-bottom: 8px; } diff --git a/Open-ILS/web/images/adv_row_close_btn.png b/Open-ILS/web/images/adv_row_close_btn.png new file mode 100644 index 0000000000..edccf374d6 Binary files /dev/null and b/Open-ILS/web/images/adv_row_close_btn.png differ diff --git a/Open-ILS/web/js/opac/simple.js b/Open-ILS/web/js/opac/simple.js new file mode 100644 index 0000000000..7124d039db --- /dev/null +++ b/Open-ILS/web/js/opac/simple.js @@ -0,0 +1,29 @@ +/* Keep this dead simple. No dojo. Call nothing via onload. */ +function $(s) { return document.getElementById(s); } +function removeClass(node, cls) { + if (!node || !node.className) return; + node.className = + node.className.replace(new RegExp("\\b" + cls + "\\b", "g"), ""); +} +function addClass(node, cls) { + if (!node) return; + removeClass(node, cls); + if (!node.className) node.className = cls; + else node.className += ' ' + cls; +} +function unHideMe(node) { removeClass(node, "hide_me"); } +function hideMe(node) { addClass(node, "hide_me"); } + +var _search_row_template; +function addSearchRow() { + if (!_search_row_template) { + t = $("adv_global_row").cloneNode(true); + t.id = null; + _search_row_template = t; + } + + $("adv_global_tbody").insertBefore( + _search_row_template.cloneNode(true), + $("adv_global_addrow") + ); +} diff --git a/Open-ILS/web/templates/default/opac/parts/advanced/global_row.tt2 b/Open-ILS/web/templates/default/opac/parts/advanced/global_row.tt2 index 941cf7cc73..6d65c689ec 100644 --- a/Open-ILS/web/templates/default/opac/parts/advanced/global_row.tt2 +++ b/Open-ILS/web/templates/default/opac/parts/advanced/global_row.tt2 @@ -1,4 +1,4 @@ - + @@ -11,7 +11,11 @@ - + + diff --git a/Open-ILS/web/templates/default/opac/parts/advanced/search.tt2 b/Open-ILS/web/templates/default/opac/parts/advanced/search.tt2 index c4fde3ada6..0fb4ab1f12 100644 --- a/Open-ILS/web/templates/default/opac/parts/advanced/search.tt2 +++ b/Open-ILS/web/templates/default/opac/parts/advanced/search.tt2 @@ -1,3 +1,4 @@ +
@@ -17,8 +18,7 @@ @@ -38,14 +38,15 @@ - @@ -198,20 +198,18 @@ - - - [% l('Search') %] -       - - Reset Form + +       + [% l('Reset Form') %] - - -