Tpac: better "HTML view" for shared lists under "my lists" user/senator/tpac-bookbag-viewer
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Tue, 15 Nov 2011 06:50:00 +0000 (01:50 -0500)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Tue, 10 Jan 2012 19:19:29 +0000 (14:19 -0500)
From the "my lists" interface, you get a link labeled "HTML View" for
any shared lists, and this link, while meant to be shared, just
gives you a search results page where the only search term is simply "in
the given list."

This commit makes the search results page a little smarter in that case,
in order to
    a) show you the bookbag metadata, including name, description and
        item notes.
    b) allow you to keep searching *within* your list, until you don't
        want to anymore, at which point there's a checkbox you can uncheck.

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm
Open-ILS/src/templates/opac/myopac/lists.tt2
Open-ILS/src/templates/opac/parts/result/lowhits.tt2
Open-ILS/src/templates/opac/parts/result/paginate.tt2
Open-ILS/src/templates/opac/parts/result/table.tt2
Open-ILS/src/templates/opac/parts/searchbar.tt2
Open-ILS/web/css/skin/default/opac/style.css

index 6e74628..bce9cdb 100644 (file)
@@ -82,6 +82,10 @@ sub _prepare_biblio_search {
         }
     }
 
+    if ($cgi->param("bookbag")) {
+        $query .= " container(bre,bookbag," . int($cgi->param("bookbag")) . ")";
+    }
+
     if ($cgi->param('pubdate') && $cgi->param('date1')) {
         if ($cgi->param('pubdate') eq 'between') {
             $query .= ' between(' . $cgi->param('date1');
@@ -170,6 +174,62 @@ sub tag_circed_items {
 
     return 0 unless @$sets;
     return 1;
+
+}
+
+# This only loads the bookbag itself (in support of a record results page)
+# if a "bookbag" CGI parameter is specified and if the bookbag is public
+# or owned by the logged-in user (if any).  Bookbag notes are fetched
+# later if applicable.
+sub load_rresults_bookbag {
+    my ($self) = @_;
+
+    my $bookbag_id = int($self->cgi->param("bookbag"));
+    return if $bookbag_id < 1;
+
+    my %authz = $self->ctx->{"user"} ?
+        ("-or" => {"pub" => "t", "owner" => $self->ctx->{"user"}->id}) :
+        ("pub" => "t");
+
+    my $bbag = $self->editor->search_container_biblio_record_entry_bucket(
+        {"id" => $bookbag_id, "btype" => "bookbag", %authz}
+    );
+
+    if (!$bbag) {
+        $self->apache->log->warn(
+            "error from cstore retrieving bookbag $bookbag_id!"
+        );
+        return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
+    } elsif (@$bbag) {
+        $self->ctx->{"bookbag"} = shift @$bbag;
+    }
+
+    return;
+}
+
+# assumes context has a bookbag we're already authorized to look at, and
+# a list of rec_ids, reasonably sized (from paged search).
+sub load_rresults_bookbag_item_notes {
+    my ($self, $rec_ids) = @_;
+
+    my $items_with_notes =
+        $self->editor->search_container_biblio_record_entry_bucket_item([
+            {"target_biblio_record_entry" => $rec_ids,
+                "bucket" => $self->ctx->{"bookbag"}->id},
+            {"flesh" => 1, "flesh_fields" => {"cbrebi" => ["notes"]},
+                "order_by" => {"cbrebi" => ["id"]}}
+        ]);
+
+    if (!$items_with_notes) {
+        $self->apache->log->warn("error from cstore retrieving cbrebi objects");
+        return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
+    }
+
+    $self->ctx->{"bookbag_items_by_bre_id"} = +{
+        map { $_->target_biblio_record_entry => $_ } @$items_with_notes
+    };
+
+    return;
 }
 
 # context additions: 
@@ -184,6 +244,11 @@ sub load_rresults {
     my $ctx = $self->ctx;
     my $e = $self->editor;
 
+    # load bookbag metadata, if requested.
+    if (my $bbag_err = $self->load_rresults_bookbag) {
+        return $bbag_err;
+    }
+
     $ctx->{page} = 'rresult' unless $internal;
     $ctx->{ids} = [];
     $ctx->{records} = [];
@@ -294,6 +359,8 @@ sub load_rresults {
 
     return Apache2::Const::OK if @$rec_ids == 0 or $internal;
 
+    $self->load_rresults_bookbag_item_notes($rec_ids) if $ctx->{bookbag};
+
     my ($facets, @data) = $self->get_records_and_facets(
         $rec_ids, $results->{facet_key}, 
         {
index 41c77f9..45404e8 100644 (file)
             <div class="bookbag-controls">
                 [% IF bbag.pub == 't'; %]
                 <a href='[%-
-                    mkurl( ctx.opac_root _ '/results', {page => '0', query => 'container(bre,bookbag,' _ bbag.id _ ')'} )
+                    mkurl( ctx.opac_root _ '/results', {page => '0', bookbag => bbag.id} )
                 -%]'>[% l('HTML View') %]</a>
                 [% END %]
             </div>
index db8266a..f6f39b2 100644 (file)
@@ -8,6 +8,11 @@
                 [% IF is_advanced OR is_special; l('your search'); ELSE %]
                 <q>[% CGI.param('query') | html %]</q>
                 [% END %]
+                [% IF ctx.bookbag;
+                    l('within') %]
+                    <span class="lowhits-bookbag-name">[% ctx.bookbag.name | html %]</span>.
+                [% END %]
+
             </p>
         </div>
         <div style="float:right;width:353px;background:#ccc;padding:10px;margin-top:7px;">
index 6582c01..bcce1c8 100644 (file)
@@ -2,7 +2,7 @@
 <div class="results_header_nav1">
     <table cellpadding="0" cellspacing="0" border="0" width="100%">
         <tr>
-            <td class="h1" width="116">[% l('Search Results') %]</td>
+            <td class="h1" width="116">[% ctx.bookbag ? l('List Contents') : l('Search Results') %]</td>
             <td valign="bottom" nowrap="nowrap" class="result_number">
                 [% |l(ctx.result_start, ctx.result_stop, ctx.hit_count) %]
                 Results <strong>[_1]</strong> - <strong>[_2]</strong> of <strong>[_3]</strong>
index 8312379..36a4e76 100644 (file)
 [% ctx.results_count_header = PROCESS results_count_header;
     ctx.results_count_header %]
 
+[% IF ctx.bookbag %]
+<div id="result-bookbag-heading">
+    <div class="result-bookbag-name">[% ctx.bookbag.name | html %]</div>
+    <div class="result-bookbag-description">[% ctx.bookbag.description | html %]</div>
+</div>
+[% END %]
 <div id="result_table_div">
             <div class="facet_sidebar">
                 [% INCLUDE "opac/parts/staff_saved_searches.tt2" %]
                                                         <span>[% l('I have checked this item out before') %]</span>
                                                     </div>
                                                     [% END %]
+                                                    [% IF ctx.bookbag;
+                                                        rec_id = rec.id;
+                                                        FOR note IN ctx.bookbag_items_by_bre_id.$rec_id.notes %]
+                                                    <div class="result-bookbag-item-note">
+                                                        [% note.note | html %]
+                                                    </div>
+                                                        [% END %]
+                                                    [% END %]
                                                 </div>
                                             </td>
 
index 43a9c85..360bd25 100644 (file)
         <img id='search-submit-spinner' src='/opac/images/progressbar_green.gif' style='height:16px;width:16px;' class='hidden' alt=''/>
     </span>
     </div>
+    [% IF ctx.bookbag %]
+    <div id="search-only-bookbag-container">
+        <input type="checkbox" id="search-only-bookbag" name="bookbag"
+            value="[% ctx.bookbag.id | html %]" checked="checked" />
+        <label for="search-only-bookbag">
+            [% l('Search only within the chosen list') %]
+        </label>
+    </div>
+    [% END %]
     [% IF is_advanced || is_special %]
     <div>
         <input type="hidden" name="_adv" value="1" />
index 4fddfe3..9848bba 100644 (file)
@@ -1335,3 +1335,11 @@ table.bookbag-specific {
     top:-3px;
     left:3px;
 }
+
+#search-only-bookbag-container { margin: 2ex 0; font-weight: bold; }
+#result-bookbag-heading { text-align: center; margin: 2ex; }
+
+.result-bookbag-name { font-size: 140%; font-weight: bold; }
+.result-bookbag-description { font-size: 120%; font-style: italic; }
+.result-bookbag-item-note { font-style: italic; }
+.lowhits-bookbag-name { font-weight: bold; }