LP#1638299: improve display of related headings in browse
authorGalen Charlton <gmc@equinoxinitiative.org>
Thu, 27 Jul 2017 22:31:47 +0000 (22:31 +0000)
committerKathy Lussier <klussier@masslnc.org>
Fri, 1 Sep 2017 19:44:31 +0000 (15:44 -0400)
This patch adds a new global flag to control whether see
alsos are displayed at all; it also allows better labels based
on the heading purpose.

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/WWWW.cgf.sql [new file with mode: 0644]
Open-ILS/src/templates/opac/browse.tt2

index 1d49aa5..4440b15 100644 (file)
@@ -119,6 +119,21 @@ sub find_authority_headings_and_notes {
 
     $self->extract_public_general_notes($record, $row);
 
 
     $self->extract_public_general_notes($record, $row);
 
+    # extract headings from the main authority record along with their
+    # types
+    my $parsed_headings = $self->editor->json_query({
+        from => [ "authority.extract_headings", $row->{marc} ]
+    });
+    my %heading_type_map = ();
+    if ($parsed_headings) {
+        foreach my $h (@$parsed_headings) {
+            $heading_type_map{$h->{normalized_heading}} =
+                $h->{purpose} eq 'variant' ? 'variant' :
+                $h->{purpose} eq 'related' ? $h->{related_type} :
+                '';
+        }
+    }
+
     # By applying grep in this way, we get acsaf objects that *have* and
     # therefore *aren't* main entries, which is what we want.
     foreach my $acsaf (values(%$acsaf_table)) {
     # By applying grep in this way, we get acsaf objects that *have* and
     # therefore *aren't* main entries, which is what we want.
     foreach my $acsaf (values(%$acsaf_table)) {
@@ -130,6 +145,10 @@ sub find_authority_headings_and_notes {
             my $h = { main_entry => ( $acsaf->main_entry ? 0 : 1 ),
                       heading => _get_authority_heading($field, \%sf_lookup), $acsaf->joiner };
 
             my $h = { main_entry => ( $acsaf->main_entry ? 0 : 1 ),
                       heading => _get_authority_heading($field, \%sf_lookup), $acsaf->joiner };
 
+            my $norm = search_normalize($h->{heading});
+            if (exists $heading_type_map{$norm}) {
+                $h->{type} = $heading_type_map{$norm};
+            }
             # XXX I was getting "target" from authority.authority_linking, but
             # that makes no sense: that table can only tell you that one
             # authority record as a whole points at another record.  It does
             # XXX I was getting "target" from authority.authority_linking, but
             # that makes no sense: that table can only tell you that one
             # authority record as a whole points at another record.  It does
index a7cf470..3ff2675 100644 (file)
@@ -16881,6 +16881,17 @@ INSERT INTO config.global_flag (name, label, value, enabled) VALUES (
     TRUE
 );
 
     TRUE
 );
 
+INSERT INTO config.global_flag (name, label, enabled) VALUES (
+    'opac.show_related_headings_in_browse',
+    oils_i18n_gettext(
+        'opac.show_related_headings_in_browse',
+        'Display related headings (see-also) in browse',
+        'cgf',
+        'label'
+    ),
+    TRUE
+);
+
 INSERT INTO config.settings_group (name, label)
     VALUES ('ebook_api', oils_i18n_gettext('ebook_api', 'Ebook API Integration', 'csg', 'label'));
 
 INSERT INTO config.settings_group (name, label)
     VALUES ('ebook_api', oils_i18n_gettext('ebook_api', 'Ebook API Integration', 'csg', 'label'));
 
diff --git a/Open-ILS/src/sql/Pg/upgrade/WWWW.cgf.sql b/Open-ILS/src/sql/Pg/upgrade/WWWW.cgf.sql
new file mode 100644 (file)
index 0000000..f5f6049
--- /dev/null
@@ -0,0 +1,14 @@
+BEGIN;
+
+INSERT INTO config.global_flag (name, label, enabled) VALUES (
+    'opac.show_related_headings_in_browse',
+    oils_i18n_gettext(
+        'opac.show_related_headings_in_browse',
+        'Display related headings (see-also) in browse',
+        'cgf',
+        'label'
+    ),
+    TRUE
+);
+
+COMMIT;
index 4e74241..b364655 100644 (file)
 
     depart_list = ['blimit', 'bterm', 'bpivot'];
     ctx.metalinks.push('<meta name="robots" content="noindex,follow">');
 
     depart_list = ['blimit', 'bterm', 'bpivot'];
     ctx.metalinks.push('<meta name="robots" content="noindex,follow">');
+    MACRO heading_use_label BLOCK;
+        SWITCH use;
+            CASE 'variant';
+               l('See');
+            CASE 'broader';
+               l('Broader term');
+            CASE 'narrower';
+               l('Broader term');
+            CASE 'other';
+               l('Related term');
+            CASE;
+               l('See');
+        END;
+    END;
 %]
 
     <h2 class="sr-only">[% l('Catalog Browse') %]</h2>
 %]
 
     <h2 class="sr-only">[% l('Catalog Browse') %]</h2>
                                             # that h.target_count is only
                                             # defined when h.target is.
 
                                             # that h.target_count is only
                                             # defined when h.target is.
 
-                                            IF h.target AND h.target_count AND result.list_authorities.grep('^' _ h.target _ '$').size == 0;
+                                            IF h.target AND h.target_count AND result.list_authorities.grep('^' _ h.target _ '$').size == 0 AND h.main_entry;
                                                 id = h.target; NEXT IF seenit.$id; seenit.$id = 1; 
                                                 IF !auth_headings_ul_added;
                                                     # only add a <ul> if we have at least one <li> (WCAG 2.0)
                                                 id = h.target; NEXT IF seenit.$id; seenit.$id = 1; 
                                                 IF !auth_headings_ul_added;
                                                     # only add a <ul> if we have at least one <li> (WCAG 2.0)
                                                 <ul class="browse-result-authority-headings"> 
                                                 [% END %]
 
                                                 <ul class="browse-result-authority-headings"> 
                                                 [% END %]
 
-                                                <li><span class="browse-result-authority-field-name">[% field.name %]</span>
+                                                <li><span class="browse-result-authority-field-name">[% heading_use_label(use=h.type) %]</span>
                                                 <a href="[% mkurl(ctx.opac_root _ '/browse', {bterm => h.heading}, ['bpivot']) %]">[% h.heading | html %]</a>
                                                 <span class="browse-result-authority-bib-links">([% h.target_count %])</span>
                                                 </li>
                                                 <a href="[% mkurl(ctx.opac_root _ '/browse', {bterm => h.heading}, ['bpivot']) %]">[% h.heading | html %]</a>
                                                 <span class="browse-result-authority-bib-links">([% h.target_count %])</span>
                                                 </li>
                                             # that h.target_count is only
                                             # defined when h.target is.
 
                                             # that h.target_count is only
                                             # defined when h.target is.
 
-                                            IF h.target AND h.target_count AND result.list_sees.grep('^' _ h.target _ '$').size == 0 AND !h.main_entry;
+                                            IF h.target AND h.target_count AND result.list_sees.grep('^' _ h.target _ '$').size == 0 AND !h.main_entry AND ctx.get_cgf('opac.show_related_headings_in_browse').enabled == 't';
                                                 id = h.target; NEXT IF seenit.$id; seenit.$id = 1; 
                                                 IF !auth_headings_ul_added;
                                                     # only add a <ul> if we have at least one <li> (WCAG 2.0)
                                                     auth_headings_ul_added = 1; %]
                                                 <ul class="browse-result-authority-headings"> 
                                                 [% END %]
                                                 id = h.target; NEXT IF seenit.$id; seenit.$id = 1; 
                                                 IF !auth_headings_ul_added;
                                                     # only add a <ul> if we have at least one <li> (WCAG 2.0)
                                                     auth_headings_ul_added = 1; %]
                                                 <ul class="browse-result-authority-headings"> 
                                                 [% END %]
-                                                <li><span class="browse-result-authority-field-name">[% field.name %]</span>
+                                                <li><span class="browse-result-authority-field-name">[% heading_use_label(use=h.type) %]</span>
                                                 <a href="[% mkurl(ctx.opac_root _ '/results', {query => 'identifier|authority_id[' _ h.target _ ']'}) %]">[% h.heading | html %]</a>
                                                 <span class="browse-result-authority-bib-links">([% h.target_count %])</span>
                                                 </li>
                                                 <a href="[% mkurl(ctx.opac_root _ '/results', {query => 'identifier|authority_id[' _ h.target _ ']'}) %]">[% h.heading | html %]</a>
                                                 <span class="browse-result-authority-bib-links">([% h.target_count %])</span>
                                                 </li>