From 331983c7ff9bbec8571676a18373e9efa2aca59e Mon Sep 17 00:00:00 2001 From: Thomas Berezansky Date: Tue, 22 Jul 2014 11:15:11 -0400 Subject: [PATCH] LP#1347793: Teach TPac to load AC by Bib ID So that we may get more than just jackets Signed-off-by: Thomas Berezansky Signed-off-by: Ben Shum --- .../lib/OpenILS/WWW/EGCatLoader/Record.pm | 82 +++++-------------- Open-ILS/src/templates/opac/parts/acjs.tt2 | 70 ++++++++-------- 2 files changed, 57 insertions(+), 95 deletions(-) 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 e3722678be..8170b6d141 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm @@ -486,8 +486,6 @@ sub added_content_stage1 { my $rec_id = shift; my $ctx = $self->ctx; my $sel_type = $self->cgi->param('ac') || ''; - my $key = $self->get_ac_key($rec_id); - ($key = $key->{value}) =~ s/^\s+//g if $key; # Connect to this machine's IP address, using the same # Host with which our caller used to connect to us. @@ -503,31 +501,29 @@ sub added_content_stage1 { for my $type (@$ac_types) { last if $ac_failed; $ctx->{added_content}->{$type} = {content => ''}; - $ctx->{added_content}->{$type}->{status} = $key ? 3 : 2; - - if ($key) { - $logger->debug("tpac: starting added content request for $key => $type"); - - # Net::HTTP::NB is non-blocking /after/ the initial connect() - # Passing Timeout=>1 ensures we wait no longer than 1 second to - # connect to the local Evergreen instance (i.e. ourself). - # Connecting to oneself should either be very fast (normal) - # or very slow (routing problems). - - my $req = Net::HTTP::NB->new(Host => $ac_addr, Timeout => 1); - if (!$req) { - $logger->warn("Unable to connect to $ac_addr / $ac_host". - " for added content lookup for $key: $@"); - $ac_failed = 1; - next; - } + $ctx->{added_content}->{$type}->{status} = 3; + + $logger->debug("tpac: starting added content request for $rec_id => $type"); + + # Net::HTTP::NB is non-blocking /after/ the initial connect() + # Passing Timeout=>1 ensures we wait no longer than 1 second to + # connect to the local Evergreen instance (i.e. ourself). + # Connecting to oneself should either be very fast (normal) + # or very slow (routing problems). + + my $req = Net::HTTP::NB->new(Host => $ac_addr, Timeout => 1); + if (!$req) { + $logger->warn("Unable to connect to $ac_addr / $ac_host". + " for added content lookup for $rec_id: $@"); + $ac_failed = 1; + next; + } - $req->host($self->apache->hostname); + $req->host($self->apache->hostname); - my $http_type = ($type eq $sel_type) ? 'GET' : 'HEAD'; - $req->write_request($http_type => "/opac/extras/ac/$type/html/" . uri_escape_utf8($key)); - $ctx->{added_content}->{$type}->{request} = $req; - } + my $http_type = ($type eq $sel_type) ? 'GET' : 'HEAD'; + $req->write_request($http_type => "/opac/extras/ac/$type/html/r/" . $rec_id); + $ctx->{added_content}->{$type}->{request} = $req; } } @@ -572,40 +568,4 @@ sub added_content_stage2 { } } -# XXX this is copied directly from AddedContent.pm in -# working/user/jeff/ac_by_record_id_rebase. When Jeff's -# branch is merged and Evergreen gets added content -# lookup by ID, this can be removed. -# returns [{tag => $tag, value => $value}, {tag => $tag2, value => $value2}] -sub get_ac_key { - my $self = shift; - my $rec_id = shift; - my $key_data = $self->editor->json_query({ - select => {mfr => ['tag', 'value']}, - from => 'mfr', - where => { - record => $rec_id, - '-or' => [ - { - '-and' => [ - {tag => '020'}, - {subfield => 'a'} - ] - }, { - '-and' => [ - {tag => '024'}, - {subfield => 'a'}, - {ind1 => 1} - ] - } - ] - } - }); - - return ( - grep {$_->{tag} eq '020'} @$key_data, - grep {$_->{tag} eq '024'} @$key_data - )[0]; -} - 1; diff --git a/Open-ILS/src/templates/opac/parts/acjs.tt2 b/Open-ILS/src/templates/opac/parts/acjs.tt2 index 3b057dcdb2..dd48374a10 100644 --- a/Open-ILS/src/templates/opac/parts/acjs.tt2 +++ b/Open-ILS/src/templates/opac/parts/acjs.tt2 @@ -3,52 +3,54 @@ /* Checks to see if a given type of added content has data to show. * The first arg to callback() is boolean indicating the presence of data */ - function acIsAvailable(ident, type, callback) { - var url = '/opac/extras/ac/' + type + '/html/' + ident; + function acIsAvailable(bre_id, type, callback) { + var url = '/opac/extras/ac/' + type + '/html/r/' + bre_id; dojo.xhr('HEAD', { - url : url, + url : url, failOk : true, // http://bugs.dojotoolkit.org/ticket/11568 - error : function(err) { callback(false, ident, type); }, - load : function(result) { callback(true, ident, type); } + error : function(err) { callback(false, bre_id, type); }, + load : function(result) { callback(true, bre_id, type); } }); } - [%- # XXX revisit when ident=ctx.bre_id - ident = ctx.record_attrs.isbn_clean || ctx.record_attrs.upc; - IF ident; - FOR type IN ctx.added_content.keys; - IF ctx.added_content.$type.status == '3' # status unknown %] + [%- + FOR type IN ctx.added_content.keys; + IF ctx.added_content.$type.status == '3' # status unknown %] - dojo.addOnLoad(function() { - var ident = '[% ident %]'; - var type = '[% type %]'; + dojo.addOnLoad(function() { + var bre_id = '[% ctx.bre_id %]'; + var type = '[% type %]'; - acIsAvailable(ident, type, function(avail, ident, type) { - if (avail) { + acIsAvailable(bre_id, type, function(avail, bre_id, type) { + if (avail) { - [% IF CGI.param('expand') == 'addedcontent' %] + [% IF CGI.param('expand') == 'addedcontent' %] - // if the content is available, un-hide the tab - dojo.removeClass(dojo.byId('ac:' + type), 'hidden'); + // if the content is available, un-hide the tab + dojo.removeClass(dojo.byId('ac:' + type), 'hidden'); - [% ELSE %] - // if no default type is selected on the main tab link - // set one here, since we have available content + [% ELSE %] + // if no default type is selected on the main tab link + // set one here, since we have available content - var link = dojo.query('[name=addedcontent]')[0]; - var href = link.getAttribute('href'); - if (!href.match('[\&;]ac=')) { - href = href.replace('#addedcontent', ';ac=' + type + '#addedcontent'); - dojo.attr(link, 'href', href); - dojo.attr(dojo.query('[name=addedcontent_lbl]')[0], 'href', href); - } + var link = dojo.query('[name=addedcontent]')[0]; + var href = link.getAttribute('href'); + if (!href.match('[\&;]ac=')) { + href = href.replace('#addedcontent', ';ac=' + type + '#addedcontent'); + dojo.attr(link, 'href', href); + dojo.attr(dojo.query('[name=addedcontent_lbl]')[0], 'href', href); + } - [% END %] - } - }); + [% END %] + } }); - [% END; # IF status unknown - END %] + }); + [% END; # IF status unknown + END; # FOR type + + ident = ctx.record_attrs.isbn_clean || ctx.record_attrs.upc; + IF ident; + -%] [%- IF ENV.OILS_NOVELIST_URL -%] /* Load novelist content */ @@ -57,7 +59,7 @@ ClientIdentifier : '[% ident %]', ISBN : '[% ident %]', version : '2.1' - }, + }, '[% ENV.OILS_NOVELIST_PROFILE %]', '[% ENV.OILS_NOVELIST_PASSWORD %]', function(d){ -- 2.43.2