Use in-db unapi to display record summaries user/dbs/in-db-unapi-circ-due-date
authorDan Scott <dscott@laurentian.ca>
Fri, 9 Dec 2011 01:29:23 +0000 (20:29 -0500)
committerDan Scott <dscott@laurentian.ca>
Mon, 12 Dec 2011 18:57:23 +0000 (13:57 -0500)
Now that we're pulling copy/location/volume/status attributes from in-db
unAPI rather than mk_copy_query's massive JSON query, populate the
holdings hash with the required attributes and cut over to the
corresponding attributes in the record summary table.

We are approaching uniform access to copy info between search results
and record summaries.

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm
Open-ILS/src/templates/opac/parts/misc_util.tt2
Open-ILS/src/templates/opac/parts/record/summary.tt2

index 0f714c9..00287f0 100644 (file)
@@ -15,6 +15,7 @@ sub load_record {
     $ctx->{page} = 'record';  
 
     my $org = $self->cgi->param('loc') || $ctx->{aou_tree}->()->id;
+    my $site = $ctx->{get_aou}->($org)->shortname;
     my $depth = $self->cgi->param('depth') || 0;
     my $copy_limit = int($self->cgi->param('copy_limit') || 10);
     my $copy_offset = int($self->cgi->param('copy_offset') || 0);
@@ -29,19 +30,13 @@ sub load_record {
 
     $self->fetch_related_search_info($rec_id);
 
-    # run copy retrieval in parallel to bib retrieval
-    # XXX unapi
-    my $cstore = OpenSRF::AppSession->create('open-ils.cstore');
-    my $copy_rec = $cstore->request(
-        'open-ils.cstore.json_query.atomic', 
-        $self->mk_copy_query($rec_id, $org, $depth, $copy_limit, $copy_offset)
+    my (undef, @rec_data) = $self->get_records_and_facets(
+        [$rec_id], undef, {flesh => '{holdings_xml,mra,acp,acnp,acns,circ}'},
+        $site, $depth, $copy_limit, $copy_offset
     );
-
-    my (undef, @rec_data) = $self->get_records_and_facets([$rec_id], undef, {flesh => '{holdings_xml,mra,acp}'});
     $ctx->{bre_id} = $rec_data[0]->{id};
     $ctx->{marc_xml} = $rec_data[0]->{marc_xml};
 
-    $ctx->{copies} = $copy_rec->gather(1);
     $ctx->{copy_limit} = $copy_limit;
     $ctx->{copy_offset} = $copy_offset;
 
@@ -49,8 +44,6 @@ sub load_record {
     $ctx->{have_mfhd_to_show} = 0;
     $self->get_hold_copy_summary($rec_id, $org);
 
-    $cstore->kill_me;
-
     if (
         $ctx->{get_org_setting}->
             ($org, "opac.fully_compressed_serial_holdings")
index 1199d9a..f1607c5 100644 (file)
@@ -165,12 +165,13 @@ sub generic_redirect {
 }
 
 sub get_records_and_facets {
-    my ($self, $rec_ids, $facet_key, $unapi_args) = @_;
+    my ($self, $rec_ids, $facet_key, $unapi_args, $org, $depth, $copy_limit, $copy_offset) = @_;
 
     $unapi_args ||= {};
-    $unapi_args->{site} ||= $self->ctx->{aou_tree}->()->shortname;
-    $unapi_args->{depth} ||= $self->ctx->{aou_tree}->()->ou_type->depth;
-    $unapi_args->{flesh_depth} ||= 5;
+    $unapi_args->{site} = $org || $self->ctx->{aou_tree}->()->shortname;
+    $unapi_args->{depth} = $depth || $self->ctx->{aou_tree}->()->ou_type->depth;
+    $copy_limit ||= 5;
+    $copy_offset ||= 0;
 
     my @data;
     my $ses = OpenSRF::MultiSession->new(
@@ -200,7 +201,7 @@ sub get_records_and_facets {
             $unapi_args->{flesh}, 
             $unapi_args->{site}, 
             $unapi_args->{depth}, 
-            $unapi_args->{flesh_depth}, 
+            $copy_limit, $copy_offset
         ]}
     ) for @$rec_ids;
 
index db30d6b..e4677f3 100644 (file)
                     loc = copy.findnodes('./*[local-name()="location"]');
                     circlib = copy.findnodes('./*[local-name()="circlib"]');
                     status = copy.findnodes('./*[local-name()="status"]');
+                    circ = copy.findnodes('./*[local-name()="circ"]');
 
                     holding = {
+                        age_protect => copy.getAttribute('age_protect'),
+                        barcode => copy.getAttribute('barcode'),
+                        copy_id => copy.getAttribute('copy_id'),
+                        create_date => copy.getAttribute('create_date'),
+                        due_date = circ.getAttribute('due_date')
+                        holdable => copy.getAttribute('holdable'),
+                        id => copy.getAttribute('id'),
                         label => vol.label,
-                        location => loc.textContent,
                         library => circlib.textContent,
-                        status => status.textContent
-                        barcode => copy.getAttribute('barcode')
+                        location => loc.textContent,
+                        loc_holdable => loc.getAttribute('holdable'),
+                        status_holdable => status.getAttribute('holdable'),
+                        status => status.textContent,
+                        vol_id => vol.getAttribute('vol_id')
                     };
                     args.holdings.push(holding);
                 END;
index 540c30d..c6a7164 100644 (file)
@@ -117,51 +117,46 @@ IF num_uris > 0;
     </thead>
     <tbody class="copy_details_table">
         [%- last_cn = 0;
-        FOR copy_info IN ctx.copies;
-            NEXT IF copy_info.call_number_label == '##URI##' %]
+        FOR copy IN args.holdings;
+            NEXT IF copy.label == '##URI##' %]
         <tr>
-            <td header='copy_header_library'>
-            [%-
-                org_name = ctx.get_aou(copy_info.circ_lib).name;
-                org_name | html
-            -%]
-            </td>
-            <td header='copy_header_callnumber'>[% copy_info.call_number_label | html %]</td>
-            <td header='copy_header_barcode'>[% copy_info.barcode | html %]</td>
-            <td header='copy_header_shelfloc'>[% copy_info.copy_location | html %]</td>
+            <td header='copy_header_library'>[% copy.library | html -%]</td>
+            <td header='copy_header_callnumber'>[% copy.label | html %]</td>
+            <td header='copy_header_barcode'>[% copy.barcode | html %]</td>
+            <td header='copy_header_shelfloc'>[% copy.location | html %]</td>
             [%- IF ctx.is_staff %]
             <td header='copy_header_age_hold'>
-                [% copy_info.age_protect ?
-                    ctx.get_crahp(copy_info.age_protect).name : l('None') | html %]
+                [% copy.age_protect ?
+                    ctx.get_crahp(copy.age_protect).name : l('None') | html %]
             </td>
             <td header='copy_header_date_format'>[% date.format(
-                ctx.parse_datetime(copy_info.create_date),
+                ctx.parse_datetime(copy.create_date),
                 DATE_FORMAT
             ) %]</td>
             <td header='copy_header_holdable'>[%  # Show copy/volume hold links to staff (without
                     # checking whether they have permissions to do those).
-                    overall_holdable = (copy_info.holdable == 't' AND
-                        copy_info.location_holdable == 't' AND
-                        copy_info.status_holdable == 't');
+                    overall_holdable = (copy.holdable == 't' AND
+                        copy.loc_holdable == 't' AND
+                        copy.status_holdable == 't');
                     IF overall_holdable;
                         l("Place on"); %]
                 <a href="[% mkurl(ctx.opac_root _ '/place_hold', 
-                    {hold_target => copy_info.id, hold_type => 'C', hold_source_page => mkurl()}) %]">[% l("copy") %]</a>
-                [%-      IF copy_info.call_number != last_cn;
-                            last_cn = copy_info.call_number;
+                    {hold_target => copy.copy_id, hold_type => 'C', hold_source_page => mkurl()}) %]">[% l("copy") %]</a>
+                [%-      IF copy.vol_id != last_cn;
+                            last_cn = copy.vol_id;
                             l(" / "); %]
                 <a href="[% mkurl(ctx.opac_root _ '/place_hold', 
-                    {hold_target => copy_info.call_number, hold_type => 'V', hold_source_page => mkurl()}) %]">[% l("volume") %]</a>
+                    {hold_target => copy.vol_id, hold_type => 'V', hold_source_page => mkurl()}) %]">[% l("volume") %]</a>
                 [%-      END;
                     ELSE;
                         l("No");
                     END %]</td>
             [%- END %]
-            <td header='copy_header_status'>[% copy_info.copy_status | html %]</td>
+            <td header='copy_header_status'>[% copy.status | html %]</td>
             <td header='due_date'>[%
-                IF copy_info.due_date;
+                IF copy.due_date;
                     date.format(
-                        ctx.parse_datetime(copy_info.due_date),
+                        ctx.parse_datetime(copy.due_date),
                         DATE_FORMAT
                     );
                 ELSE;