LP#1230380: optionally show related online resources in OPAC user/jeffdavis/lp1230380-856-related-resource
authorJeff Davis <jdavis@sitka.bclibraries.ca>
Thu, 23 Jul 2020 00:00:30 +0000 (17:00 -0700)
committerJeff Davis <jdavis@sitka.bclibraries.ca>
Thu, 23 Jul 2020 00:00:30 +0000 (17:00 -0700)
Set ctx.show_related_resources to "true" in config.tt2 in order to
display 856 tags with '2' as the second indicator in the record summary
under a "More information" header.

Signed-off-by: Jeff Davis <jdavis@sitka.bclibraries.ca>
Open-ILS/src/templates/opac/parts/config.tt2
Open-ILS/src/templates/opac/parts/misc_util.tt2
Open-ILS/src/templates/opac/parts/record/summary.tt2

index 48b4f0f..1b955ad 100644 (file)
@@ -275,4 +275,9 @@ ctx.max_cart_size = 500;
 ##############################################################################
 ctx.show_reservations_tab = 'false';
 
+##############################################################################
+# Display related resources (856 ind2=2)
+##############################################################################
+ctx.show_related_resources = 'false';
+
 %]
index 609f22d..6372b0f 100644 (file)
         END;
     END;
 
+    MACRO process_856s BLOCK;
+        label = node.findnodes('./*[@code="y"]');
+        notes = node.findnodes('./*[@code="z" or @code="3"]');
+        FOR href IN node.findnodes('./*[@code="u"]');
+            NEXT UNLESS href;
+            # it's possible for multiple $u's to exist within 1 856 tag.
+            # in that case, honor the label/notes data for the first $u, but
+            # leave any subsequent $u's as unadorned href's. 
+            # use href/link/note keys to be consistent with args.uri's
+            uri_array.push({
+                href => href.textContent, 
+                link => (loop.first AND label) ? label.textContent : href.textContent,
+                note => (loop.first) ? notes.textContent : ''
+            });
+        END;
+    END;
+
     BLOCK get_ccvm_icon;
         ctx.media_prefix _ '/images/format_icons/' _ ccvm.ctype _ '/' _ ccvm.code _ '.png' _ ctx.cache_key;
     END;
         args.online_res = [];
         FOR node IN xml.findnodes('//*[@tag="856" and @ind1="4" and (@ind2="0" or @ind2="1")]');
             IF node.findnodes('./*[@code="9" or @code="w" or @code="n"]'); NEXT; END; # asset.uri's
-            label = node.findnodes('./*[@code="y"]');
-            notes = node.findnodes('./*[@code="z" or @code="3"]');
-            FOR href IN node.findnodes('./*[@code="u"]');
-                NEXT UNLESS href;
-                # it's possible for multiple $u's to exist within 1 856 tag.
-                # in that case, honor the label/notes data for the first $u, but
-                # leave any subsequent $u's as unadorned href's. 
-                # use href/link/note keys to be consistent with args.uri's
-                args.online_res.push({
-                    href => href.textContent, 
-                    link => (loop.first AND label) ? label.textContent : href.textContent,
-                    note => (loop.first) ? notes.textContent : ''
-                });
-            END;
+            process_856s(node=node,uri_array=args.online_res);
+        END;
+        args.related_res = [];
+        FOR node IN xml.findnodes('//*[@tag="856" and @ind1="4" and @ind2="2"]');
+            process_856s(node=node,uri_array=args.related_res);
         END;
  
         args.holdings = [];
index fb6f84a..e749f4c 100644 (file)
@@ -239,6 +239,33 @@ IF ebook_api.enabled == 'true';
 END;
 %]
 [%- END %]
+[%- num_related_uris = args.related_res.size;
+IF num_related_uris > 0 AND ctx.show_related_resources == 'true';
+-%]
+<h2 class="rdetail_uris">[% l("More information") %]</h2>
+<div class="rdetail_uris">
+    [%- IF num_related_uris > 1 %]<ul>[% END %]
+    [%- FOR related_uri IN args.related_res %]
+        [%- IF num_related_uris == 1 -%]
+            <p class="rdetail_uri">
+        [%- ELSE -%]
+            <li class="rdetail_uri">
+        [%- END -%]
+        <a href="[% related_uri.href %]" class="uri_link" property="url" target="_blank" rel="noopener">
+        [%- IF related_uri.href != related_uri.link;
+                '<span property="description">' _ related_uri.link _ '</span>';
+            ELSE;
+                related_uri.link;
+            END;
+        -%]
+        </a>
+        [%- ' - <span property="description">' _ related_uri.note _ '</span>' IF related_uri.note %]
+        [%- IF attrs.gtin13; '<meta property="gtin13" content="' _ attrs.gtin13 _ '" />'; END; %]
+        [%- IF num_related_uris == 1 %]</p>[% ELSE %]</li>[% END %]
+    [%- END %]
+    [%- IF num_related_uris > 1 %]</ul>[% END %]
+</div>
+[%- END %]
 <div id="copy_hold_counts">
 [%-
 # Hold/copy summary