From 82c66de6c344791863e49bac3dc7eabf6d262f2a Mon Sep 17 00:00:00 2001 From: Lebbeous Fogle-Weekley Date: Wed, 25 Jan 2012 17:38:28 -0500 Subject: [PATCH] TPAC support for AutoSuggest This means introducing Dojo, optionally, into the TPAC. Signed-off-by: Lebbeous Fogle-Weekley --- .../src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm | 1 + .../perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm | 40 +++++++++++++++++++++- Open-ILS/src/templates/opac/parts/base.tt2 | 8 ++++- Open-ILS/src/templates/opac/parts/header.tt2 | 11 ++++++ Open-ILS/src/templates/opac/parts/js.tt2 | 21 ++++++++++++ .../src/templates/opac/parts/qtype_selector.tt2 | 2 +- Open-ILS/src/templates/opac/parts/searchbar.tt2 | 14 +++++--- Open-ILS/web/css/skin/default/opac/style.css | 6 ++++ Open-ILS/web/js/dojo/openils/widget/AutoSuggest.js | 3 ++ 9 files changed, 99 insertions(+), 7 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm index b19b8bc200..97b6787365 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm @@ -254,6 +254,7 @@ sub load_common { $ctx->{search_ou} = $self->_get_search_lib(); $self->staff_saved_searches_set_expansion_state if $ctx->{is_staff}; + $self->load_eg_cache_hash; return Apache2::Const::OK; } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm index 5ea922f596..f10ccb796c 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm @@ -1,6 +1,7 @@ package OpenILS::WWW::EGCatLoader; use strict; use warnings; use Apache2::Const -compile => qw(OK DECLINED FORBIDDEN HTTP_INTERNAL_SERVER_ERROR REDIRECT HTTP_BAD_REQUEST); +use File::Spec; use OpenSRF::Utils::Logger qw/$logger/; use OpenILS::Utils::CStoreEditor qw/:funcs/; use OpenILS::Utils::Fieldmapper; @@ -13,7 +14,8 @@ our %cache = ( # cached data map => {aou => {}}, # others added dynamically as needed list => {}, search => {}, - org_settings => {} + org_settings => {}, + eg_cache_hash => undef ); sub init_ro_object_cache { @@ -302,4 +304,40 @@ sub _get_search_lib { return $self->ctx->{aou_tree}->()->id; } +# This is defensively coded since we don't do much manual reading from the +# file system in this module. +sub load_eg_cache_hash { + my ($self) = @_; + + # just a context helper + $self->ctx->{eg_cache_hash} = sub { return $cache{eg_cache_hash}; }; + + # Need to actually load the value? If already done, move on. + return if defined $cache{eg_cache_hash}; + + # In this way even if we fail, we won't slow things down by ever trying + # again within this Apache process' lifetime. + $cache{eg_cache_hash} = 0; + + my $path = File::Spec->catfile( + $self->apache->document_root, "eg_cache_hash" + ); + + if (not open FH, "<$path") { + $self->apache->log->warn("error opening $path : $!"); + return; + } else { + my $buf; + my $rv = read FH, $buf, 64; # defensive + close FH; + + if (not defined $rv) { # error + $self->apache->log->warn("error reading $path : $!"); + } elsif ($rv > 0) { # no error, something read + chomp $buf; + $cache{eg_cache_hash} = $buf; + } + } +} + 1; diff --git a/Open-ILS/src/templates/opac/parts/base.tt2 b/Open-ILS/src/templates/opac/parts/base.tt2 index 4af9a87084..239ab30bea 100644 --- a/Open-ILS/src/templates/opac/parts/base.tt2 +++ b/Open-ILS/src/templates/opac/parts/base.tt2 @@ -9,9 +9,15 @@ [% l('Catalog - [_1]', ctx.page_title) %] + [% IF want_dojo %] + + [% END %] [% INCLUDE 'opac/parts/goog_analytics.tt2' %] - + [% content %] [% INCLUDE 'opac/parts/footer.tt2' %] [% INCLUDE 'opac/parts/js.tt2' %] diff --git a/Open-ILS/src/templates/opac/parts/header.tt2 b/Open-ILS/src/templates/opac/parts/header.tt2 index ce519006b9..4efaa30e5c 100644 --- a/Open-ILS/src/templates/opac/parts/header.tt2 +++ b/Open-ILS/src/templates/opac/parts/header.tt2 @@ -69,4 +69,15 @@ cgi.url("-path" => 1, "-query" => 1); END; END; + + # Whether we want Dojo or not may one day be a wholly distinct + # concern from whether we want autosuggest, so let's get used to + # defining that separately. + want_dojo = 0; + + use_autosuggest = ctx.get_cgf("opac.use_autosuggest"); + + IF use_autosuggest.enabled == "t"; + want_dojo = 1; + END; %] diff --git a/Open-ILS/src/templates/opac/parts/js.tt2 b/Open-ILS/src/templates/opac/parts/js.tt2 index 35ff2bb590..0b34e5af40 100644 --- a/Open-ILS/src/templates/opac/parts/js.tt2 +++ b/Open-ILS/src/templates/opac/parts/js.tt2 @@ -40,3 +40,24 @@ IF CGI.https; url = url.replace('^http:', 'https:'); END; %] [%- END %] +[%- IF want_dojo; -%] + + + + + +[% IF use_autosuggest.enabled == "t"; %] + +[% END; # use_autosuggest %] + +[%- END; # want_dojo -%] diff --git a/Open-ILS/src/templates/opac/parts/qtype_selector.tt2 b/Open-ILS/src/templates/opac/parts/qtype_selector.tt2 index 50896063fc..98567d4ce6 100644 --- a/Open-ILS/src/templates/opac/parts/qtype_selector.tt2 +++ b/Open-ILS/src/templates/opac/parts/qtype_selector.tt2 @@ -6,7 +6,7 @@ {value => "series", label => l("Series")}, {value => "id|bibcn", label => l("Bib Call Number")} ] %] - [% query_type = query_type || CGI.param('qtype'); FOR qt IN query_types -%]