From 3a5a8d6c944e8c9161ceab73f62dd8fd09f26412 Mon Sep 17 00:00:00 2001 From: Lebbeous Fogle-Weekley Date: Tue, 30 Aug 2011 13:11:48 -0400 Subject: [PATCH] Staff saved searches when browsing catalog in staff client By default, show a user's ten most recent searches to them on the left side of the results and record details pages. Configurable by org unit setting 'opac.staff_saved_searches.size' Signed-off-by: Lebbeous Fogle-Weekley --- .../src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm | 4 ++ .../lib/OpenILS/WWW/EGCatLoader/Container.pm | 15 ++-- .../perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm | 5 ++ .../perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm | 80 ++++++++++++++++++++++ .../XYXY.data.opac_staff_saved_search_size.sql | 17 +++++ Open-ILS/web/css/skin/default/opac/style.css | 4 ++ .../default/opac/parts/qtype_selector.tt2 | 2 +- .../default/opac/parts/staff_saved_searches.tt2 | 8 +++ Open-ILS/web/templates/default/opac/record.tt2 | 11 ++- Open-ILS/web/templates/default/opac/results.tt2 | 14 +++- 10 files changed, 147 insertions(+), 13 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/XYXY.data.opac_staff_saved_search_size.sql create mode 100644 Open-ILS/web/templates/default/opac/parts/staff_saved_searches.tt2 diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm index a9d0565757..73edf6425b 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm @@ -27,6 +27,10 @@ my $U = 'OpenILS::Application::AppUtils'; use constant COOKIE_SES => 'ses'; use constant COOKIE_ORIG_LOC => 'eg_orig_loc'; +use constant COOKIE_ANON_CACHE => 'anoncache'; +use constant ANON_CACHE_MYLIST => 'mylist'; +use constant ANON_CACHE_STAFF_SEARCH => 'staffsearch'; + sub new { my($class, $apache, $ctx) = @_; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Container.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Container.pm index be45ffc7c7..e65d59e74d 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Container.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Container.pm @@ -7,23 +7,20 @@ use OpenILS::Utils::Fieldmapper; use OpenILS::Application::AppUtils; my $U = 'OpenILS::Application::AppUtils'; -use constant COOKIE_ANON_CACHE => 'anoncache'; -use constant ANON_CACHE_MYLIST => 'mylist'; - # Retrieve the users cached records AKA 'My List' # Returns an empty list if there are no cached records sub fetch_mylist { my ($self, $with_marc_xml) = @_; my $list = []; - my $cache_key = $self->cgi->cookie(COOKIE_ANON_CACHE); + my $cache_key = $self->cgi->cookie((ref $self)->COOKIE_ANON_CACHE); if($cache_key) { $list = $U->simplereq( 'open-ils.actor', 'open-ils.actor.anon_cache.get_value', - $cache_key, ANON_CACHE_MYLIST); + $cache_key, (ref $self)->ANON_CACHE_MYLIST); if(!$list) { $cache_key = undef; @@ -51,7 +48,7 @@ sub load_mylist_add { $cache_key = $U->simplereq( 'open-ils.actor', 'open-ils.actor.anon_cache.set_value', - $cache_key, ANON_CACHE_MYLIST, $list); + $cache_key, (ref $self)->ANON_CACHE_MYLIST, $list); return $self->mylist_action_redirect($cache_key); } @@ -74,7 +71,7 @@ sub load_mylist_move { $cache_key = $U->simplereq( 'open-ils.actor', 'open-ils.actor.anon_cache.set_value', - $cache_key, ANON_CACHE_MYLIST, \@keep + $cache_key, (ref $self)->ANON_CACHE_MYLIST, \@keep ); if ($self->ctx->{user} and $action =~ /^\d+$/) { @@ -97,7 +94,7 @@ sub clear_anon_cache { my $self = shift; my $field = shift; - my $cache_key = $self->cgi->cookie(COOKIE_ANON_CACHE) or return; + my $cache_key = $self->cgi->cookie((ref $self)->COOKIE_ANON_CACHE) or return; $U->simplereq( 'open-ils.actor', @@ -115,7 +112,7 @@ sub mylist_action_redirect { return $self->generic_redirect( undef, $self->cgi->cookie( - -name => COOKIE_ANON_CACHE, + -name => (ref $self)->COOKIE_ANON_CACHE, -path => '/', -value => ($cache_key) ? $cache_key : '', -expires => ($cache_key) ? undef : '-1h' diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm index b1c91d0157..22f20a4449 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm @@ -22,6 +22,11 @@ sub load_record { my $rec_id = $ctx->{page_args}->[0] or return Apache2::Const::HTTP_BAD_REQUEST; + $self->get_staff_search_settings; + if ($ctx->{staff_saved_search_size}) { + $ctx->{saved_searches} = ($self->staff_load_searches)[1]; + } + # run copy retrieval in parallel to bib retrieval # XXX unapi my $cstore = OpenSRF::AppSession->create('open-ils.cstore'); 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 d15c7228f6..b5d282ec20 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm @@ -167,6 +167,23 @@ sub load_rresults { my ($query, $site, $depth) = _prepare_biblio_search($cgi, $ctx); + $self->get_staff_search_settings; + + if ($ctx->{staff_saved_search_size}) { + my ($key, $list) = $self->staff_save_search($query); + if ($key) { + $self->apache->headers_out->add( + "Set-Cookie" => $self->cgi->cookie( + -name => (ref $self)->COOKIE_ANON_CACHE, + -path => "/", + -value => ($key || ''), + -expires => ($key ? undef : "-1h") + ) + ); + $ctx->{saved_searches} = $list; + } + } + if ($metarecord) { # TODO: other limits, like SVF/format, etc. @@ -371,4 +388,67 @@ sub load_cnbrowse { return Apache2::Const::OK; } +sub get_staff_search_settings { + my ($self) = @_; + + unless ($self->ctx->{is_staff}) { + $self->ctx->{staff_saved_search_size} = 0; + return; + } + + my $sss_size = $self->ctx->{get_org_setting}->( + $self->ctx->{orig_loc} || $self->ctx->{aou_tree}->()->id, + "opac.staff_saved_search.size", + ); + + # Sic: 0 is 0 (off), but undefined is 10. + $sss_size = 10 unless defined $sss_size; + + $self->ctx->{staff_saved_search_size} = $sss_size; +} + +sub staff_load_searches { + my ($self) = @_; + + my $cache_key = $self->cgi->cookie((ref $self)->COOKIE_ANON_CACHE); + + my $list = []; + if ($cache_key) { + $list = $U->simplereq( + "open-ils.actor", + "open-ils.actor.anon_cache.get_value", + $cache_key, (ref $self)->ANON_CACHE_STAFF_SEARCH + ); + + unless ($list) { + undef $cache_key; + $list = []; + } + } + + return ($cache_key, $list); +} + +sub staff_save_search { + my ($self, $query) = @_; + + my $sss_size = $self->ctx->{staff_saved_search_size}; + return unless $sss_size > 0; + + my ($cache_key, $list) = $self->staff_load_searches; + my %already = ( map { $_ => 1 } @$list ); + + unshift @$list, $query unless $already{$query}; + + splice @$list, $sss_size; + + $cache_key = $U->simplereq( + "open-ils.actor", + "open-ils.actor.anon_cache.set_value", + $cache_key, (ref $self)->ANON_CACHE_STAFF_SEARCH, $list + ); + + return ($cache_key, $list); +} + 1; diff --git a/Open-ILS/src/sql/Pg/upgrade/XYXY.data.opac_staff_saved_search_size.sql b/Open-ILS/src/sql/Pg/upgrade/XYXY.data.opac_staff_saved_search_size.sql new file mode 100644 index 0000000000..57926449a1 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XYXY.data.opac_staff_saved_search_size.sql @@ -0,0 +1,17 @@ +-- Evergreen DB patch XYXY.data.opac_staff_saved_search_size.sql + +BEGIN; + +SELECT evergreen.upgrade_deps_block_check('XYXY', :eg_version); + +INSERT into config.org_unit_setting_type (name, label, description, datatype) +VALUES ( + 'opac.staff_saved_search.size', + oils_i18n_gettext('opac.staff_saved_search.size', + 'OPAC: Number of staff client saved searches to display on left side of results and record details pages', 'coust', 'label'), + oils_i18n_gettext('opac.staff_saved_search.size', + 'If unset, the OPAC (only when wrapped in the staff client!) will default to showing you your ten most recent searches on the left side of the results and record details pages. If you actually don''t want to see this feature at all, set this value to zero at the top of your organizational tree.', 'coust', 'label'), + 'integer' +); + +COMMIT; diff --git a/Open-ILS/web/css/skin/default/opac/style.css b/Open-ILS/web/css/skin/default/opac/style.css index 72a5566523..6411d0039f 100644 --- a/Open-ILS/web/css/skin/default/opac/style.css +++ b/Open-ILS/web/css/skin/default/opac/style.css @@ -580,6 +580,10 @@ div.select-wrapper:hover { #main-content-home { width: 694px; margin: auto; padding-left: 17px; } #main-content { width: 974px; margin:auto; padding-left: 0px; } +#main-content-after-bar { float: left; width: 700px; margin: auto; padding-left: 4px; } + +#results-side-bar { float: left; width: 274px; background-color: #ddd; color: black; height: 500px; /* XXX to height of container*/ } + #main-content .login_boxes { border: 1px solid #dedede; background:url('/images/login-bg.jpg') top repeat-x; diff --git a/Open-ILS/web/templates/default/opac/parts/qtype_selector.tt2 b/Open-ILS/web/templates/default/opac/parts/qtype_selector.tt2 index 4b91a477bf..f643cc942c 100644 --- a/Open-ILS/web/templates/default/opac/parts/qtype_selector.tt2 +++ b/Open-ILS/web/templates/default/opac/parts/qtype_selector.tt2 @@ -9,7 +9,7 @@