Staff saved searches when browsing catalog in staff client ttopac-staff-saved-searches
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Tue, 30 Aug 2011 17:11:48 +0000 (13:11 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Wed, 31 Aug 2011 18:33:44 +0000 (14:33 -0400)
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>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Container.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm
Open-ILS/src/sql/Pg/upgrade/XYXY.data.opac_staff_saved_search_size.sql [new file with mode: 0644]
Open-ILS/web/css/skin/default/opac/style.css
Open-ILS/web/templates/default/opac/parts/qtype_selector.tt2
Open-ILS/web/templates/default/opac/parts/staff_saved_searches.tt2 [new file with mode: 0644]
Open-ILS/web/templates/default/opac/record.tt2
Open-ILS/web/templates/default/opac/results.tt2

index a9d0565..73edf64 100644 (file)
@@ -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) = @_;
 
index be45ffc..e65d59e 100644 (file)
@@ -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'
index b1c91d0..22f20a4 100644 (file)
@@ -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');
index d15c722..b5d282e 100644 (file)
@@ -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 (file)
index 0000000..5792644
--- /dev/null
@@ -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;
index 72a5566..6411d00 100644 (file)
@@ -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;
index 4b91a47..f643cc9 100644 (file)
@@ -9,7 +9,7 @@
 <select name="qtype">
     [%  query_type = query_type || CGI.param('qtype');
         FOR qt IN query_types -%]
-    <option value='[% qt.value | uri %]'[%
+    <option value='[% qt.value %]'[%
         query_type == qt.value ? ' selected="selected"' : ''
     %]>[% qt.label | html %]</option>
     [% END -%]
diff --git a/Open-ILS/web/templates/default/opac/parts/staff_saved_searches.tt2 b/Open-ILS/web/templates/default/opac/parts/staff_saved_searches.tt2
new file mode 100644 (file)
index 0000000..fb8ce21
--- /dev/null
@@ -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 %]&amp;_adv=1">[% s | html %]</a></li>
+    </ul>
+    [% END %]
+[% END %]
index 0149bf1..82def90 100644 (file)
@@ -6,10 +6,19 @@
         [% INCLUDE "default/opac/parts/printnav.tt2" %]
         [% INCLUDE "default/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 "default/opac/parts/staff_saved_searches.tt2" %]
+            </div>
+        </div>
+        [% END %]
+        <div id="[% ctx.staff_saved_search_size ? 'main-content-after-bar' : 'main-content' %]">
             [% INCLUDE "default/opac/parts/record/body.tt2" %]
             <div class="common-full-pad"></div>        
         </div>
+        <br class="clear-both" />
     </div>
 [% END %]
index bfe9633..9b8311c 100644 (file)
         </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 "default/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 = "default/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 %]