From: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com> Date: Fri, 16 Sep 2011 23:13:12 +0000 (-0400) Subject: Staff saved searches when browsing catalog in staff client X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=eef093193ef5d5a0bf21972dca4147c0d0c573be;p=evergreen%2Fmasslnc.git 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 <lebbeous@esilibrary.com> Signed-off-by: Mike Rylander <mrylander@gmail.com> --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm index b6281ce562..60d7e8f052 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 a51ddc5e45..a80549fab2 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); } @@ -66,7 +63,7 @@ sub load_mylist_delete { $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); } @@ -88,7 +85,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+$/) { @@ -111,7 +108,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', @@ -137,7 +134,7 @@ sub mylist_action_redirect { return $self->generic_redirect( $url, $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 533cb7ea8a..bc60edc7ef 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 376b31637c..bed087f2ac 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. @@ -372,4 +389,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/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index 42e029c427..db3afc2ae0 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -4363,6 +4363,15 @@ INSERT into config.org_unit_setting_type 'URL for remote directory containing list column settings. The format and naming convention for the files found in this directory match those in the local settings directory for a given workstation. An administrator could create the desired settings locally and then copy all the tree_columns_for_* files to the remote directory.', 'coust', 'description'), 'string', null) +,( 'opac.staff_saved_search.size', 'opac', + 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', 'description'), + 'integer', null) + ; UPDATE config.org_unit_setting_type 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..410f1ef72b --- /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, grp, label, description, datatype) +VALUES ( + 'opac.staff_saved_search.size', 'opac', + 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', 'description'), + 'integer' +); + +COMMIT; diff --git a/Open-ILS/src/templates/opac/parts/staff_saved_searches.tt2 b/Open-ILS/src/templates/opac/parts/staff_saved_searches.tt2 new file mode 100644 index 0000000000..fb8ce216fe --- /dev/null +++ b/Open-ILS/src/templates/opac/parts/staff_saved_searches.tt2 @@ -0,0 +1,8 @@ +[% IF ctx.saved_searches.size %] + <div class="saved-searches-header big-strong">[% l("Your recent searches:") %]</div> + [% FOR s IN ctx.saved_searches %] + <ul> + <li><a href="[% ctx.opac_root %]/results?query=[% s | uri %]&_adv=1">[% s | html %]</a></li> + </ul> + [% END %] +[% END %] diff --git a/Open-ILS/src/templates/opac/record.tt2 b/Open-ILS/src/templates/opac/record.tt2 index 7434865bfa..5c1e4d8d35 100644 --- a/Open-ILS/src/templates/opac/record.tt2 +++ b/Open-ILS/src/templates/opac/record.tt2 @@ -7,10 +7,19 @@ [% INCLUDE "opac/parts/printnav.tt2" %] [% INCLUDE "opac/parts/searchbar.tt2" %] </div> + <br class="clear-both" /> <div id="content-wrapper" class="content-wrapper-record-page"> - <div id="main-content"> + [% IF ctx.staff_saved_search_size %] + <div id="results-side-bar"> + <div id="staff-saved-search"> + [% INCLUDE "opac/parts/staff_saved_searches.tt2" %] + </div> + </div> + [% END %] + <div id="[% ctx.staff_saved_search_size ? 'main-content-after-bar' : 'main-content' %]"> [% INCLUDE "opac/parts/record/body.tt2" %] <div class="common-full-pad"></div> </div> + <br class="clear-both" /> </div> [% END %] diff --git a/Open-ILS/src/templates/opac/results.tt2 b/Open-ILS/src/templates/opac/results.tt2 index dc7d84cb35..acebea7d3e 100644 --- a/Open-ILS/src/templates/opac/results.tt2 +++ b/Open-ILS/src/templates/opac/results.tt2 @@ -61,14 +61,24 @@ </div> </div> </form> + <br class="clear-both" /> <div id="content-wrapper"> - <div id="main-content"> - <div id="tehResultsPage"> + [% IF ctx.staff_saved_search_size %] + <div id="results-side-bar"> + <div id="staff-saved-search"> + [% INCLUDE "opac/parts/staff_saved_searches.tt2" %] + </div> + <!-- XXX facet display here one day? --> + </div> + [% END %] + <div id="[% ctx.staff_saved_search_size ? 'main-content-after-bar' : 'main-content' %]"> + <div id="results-page"> [% path = "opac/parts/result/" _ (ctx.records.size ? "table.tt2" : "lowhits.tt2"); INCLUDE $path %] </div> <div class="common-full-pad"></div> </div> + <br class="clear-both" /> </div> [% END %] diff --git a/Open-ILS/web/css/skin/default/opac/style.css b/Open-ILS/web/css/skin/default/opac/style.css index 6a0cec6980..e1536a6b9e 100644 --- a/Open-ILS/web/css/skin/default/opac/style.css +++ b/Open-ILS/web/css/skin/default/opac/style.css @@ -551,6 +551,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;