Show series in results display
authorJosh Stompro <stompro@stompro.org>
Tue, 23 Jun 2020 20:31:01 +0000 (15:31 -0500)
committerJosh Stompro <stompro@stompro.org>
Tue, 23 Jun 2020 20:31:01 +0000 (15:31 -0500)
One way to show series info on the results page in the catalog.

Thank you to Anna Goben for sharing this with me and Jason Boyer for
creating the example.

Signed-off-by: Josh Stompro <stompro@stompro.org>
Open-ILS/src/templates/opac/parts/result/series.tt2 [new file with mode: 0644]
Open-ILS/src/templates/opac/parts/result/table.tt2

diff --git a/Open-ILS/src/templates/opac/parts/result/series.tt2 b/Open-ILS/src/templates/opac/parts/result/series.tt2
new file mode 100644 (file)
index 0000000..d83ed80
--- /dev/null
@@ -0,0 +1,54 @@
+[%- 
+    series_tags = ['440', '490', '800', '810', '811', '830', '694']; 
+    loc = ctx.search_ou;
+
+BLOCK render_series;
+    results = [];
+        FOR tag IN series_tags;
+            FOR node IN attrs.marc_xml.findnodes('//*[@tag="' _ tag _ '"]');
+                all_terms = [];
+                graphics = [];
+                series = '';
+                cur_tag = node.getAttribute('tag');
+                NEXT IF cur_tag == '490' && node.getAttribute('ind1') == '1';
+                FOR subfield IN node.childNodes;
+                    NEXT UNLESS subfield.nodeName == "subfield";
+                    code = subfield.getAttribute('code');
+                    IF code == '6';
+                       linked_fields = [subfield.textContent()];
+                       target_field = node.getAttribute('tag');
+                       get_linked_880s;
+                    END;
+                    NEXT IF cur_tag == '490' && !code.match('[av]');
+                    NEXT IF cur_tag == '800' && !code.match('[tv]');
+                    NEXT IF cur_tag == '810' && !code.match('[tv]');
+                    NEXT IF cur_tag == '811' && !code.match('[tv]');
+                    NEXT IF cur_tag == '830' && !code.match('[av]');
+
+                    # at this point, we actually have a partial term to use. 
+                    single_term = subfield.textContent | html;
+                    all_terms.push(subfield.textContent.replace('[#"^$\+\-,\.:;&|\[\]()]', ' '));
+                    total_term = all_terms.join(" ").replace('\s+$', '');
+    
+                    url = mkurl(ctx.opac_root _ '/results',
+                        { qtype=>'series', query=>total_term }, stop_parms.merge(expert_search_parms, general_search_parms, browse_search_parms, facet_search_parms)
+                    );
+                    series = series _ '<a href="' _ url _ '">' _ single_term _ '</a> ';
+                END;
+                FOREACH link880 IN graphics;
+                    link = link880.value | html;
+                    series = series _ '<div class="graphic880"' _ link880.dir _ '>' _ link _ '</div>';
+                END;
+                results.push(series);
+            END;
+        END; 
+   entries = results.join(" -- ");
+-%]
+
+[%- entries -%]
+[%- END %]
+
+[%- series_anchors = PROCESS render_series;
+    IF series_anchors.length > 0; %]
+<div><strong>Series:</strong> [% series_anchors %]</div>
+[%- END %]
index de5e443..ed3abb2 100644 (file)
@@ -181,6 +181,7 @@ END;
 -%]
 
                                                     </div>
+                                                    [% INCLUDE "opac/parts/result/series.tt2" %]
                                                     <div class='result_table_title_cell'>
                                                     [%- IF attrs.format_label; %]
                                                         [% FOR format IN attrs.all_formats %]