TPAC: Make facet display work as in JSPAC
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Thu, 11 Oct 2012 20:00:36 +0000 (16:00 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Wed, 17 Oct 2012 01:17:07 +0000 (21:17 -0400)
Namely, this means:
    - You see five facets per category by default, not ten.
    - You can click a link to see all the facets in a category
        (before this it was impossible to display more than ten).
    - When viewing all the facets in a category, you can click a link
        to reduce the list back to five.
    - This number five I'm talking about is configurable in config.tt2.
    - Alphabetical sorting of facets grouped by the same numbers of
      results is restored.

This addresses LP #1065109.

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm
Open-ILS/src/templates/opac/css/style.css.tt2
Open-ILS/src/templates/opac/parts/config.tt2
Open-ILS/src/templates/opac/parts/result/facets.tt2

index 4dc5ea0..660b20e 100644 (file)
@@ -299,7 +299,7 @@ sub get_records_and_facets {
     # collect the facet data
     my $search = OpenSRF::AppSession->create('open-ils.search');
     my $facet_req = $search->request(
-        'open-ils.search.facet_cache.retrieve', $facet_key, 10
+        'open-ils.search.facet_cache.retrieve', $facet_key
     ) if $facet_key;
 
     # gather up the unapi recs
@@ -318,7 +318,13 @@ sub get_records_and_facets {
             for my $ent (keys %$entries) {
                 push(@entries, {value => $ent, count => $$entries{$ent}});
             };
-            @entries = sort { $b->{count} <=> $a->{count} } @entries;
+
+            # Sort facet entries by 1) count descending, 2) text ascending
+            @entries = sort {
+                $b->{count} <=> $a->{count} ||
+                $a->{value} cmp $b->{value}
+            } @entries;
+
             $facets->{$cmf_id} = {
                 cmf => $self->ctx->{get_cmf}->($cmf_id),
                 data => \@entries
index c22b9ce..b5c7418 100644 (file)
@@ -970,9 +970,11 @@ div.facet_sidebar {
     overflow:hidden;
 }
 
-.facet_box_temp .header .button {
+.facet_box_temp .header a.button {
     float:right;
+    padding-top:6px;
     padding-right:6px;
+    color:[% css_colors.text_invert %];
 }
 
 .facet_box_wrapper .box_wrapper {
index 2985f1f..b0fee8f 100644 (file)
@@ -77,6 +77,7 @@ facet.display = [
     {facet_class => 'series',  facet_order => ['seriestitle']},
     {facet_class => 'subject', facet_order => ['name', 'geographic']}
 ];
+facet.default_display_count = 5;
 
 ##############################################################################
 # Define the advanced search limiters and labels.
index dd27dd9..fed133a 100644 (file)
@@ -1,12 +1,15 @@
 <div class="facet_box_wrapper">
 [% 
 
-close_facets = CGI.param('close_facet') || [];
+long_facets = CGI.param('long_facet') || [];
 selected_facets = CGI.param('facet') || [];
 
 # sorted list of search facets
 sorted_facets = [];
 
+# we'll clobber the facet. "namespace" later
+DEFAULT_DISPLAY_COUNT = facet.default_display_count;
+
 IF facet.display;
 
     # facet display configuration present.  Traverse the 
@@ -37,46 +40,38 @@ ELSE;
         labels.push(facet.cmf.label);
     END;
     
-    FOR facet_label IN labels.sort;
-        FOR facet IN ctx.search_facets.values;
-            IF facet.cmf.label == facet_label;
-                sorted_facets.push(facet);
-            END;
-        END;
-    END;
+    # We used to do a sort here, but now that's handled in EGCatLoader.
+    sorted_facets = ctx.search_facets.values;
 END;
 
+display_count_by_cmf = {};
+
 FOR facet IN sorted_facets;
     fclass = facet.cmf.field_class;
     fname = facet.cmf.name;
-    close_key = fclass _ fname %]
+    fid = facet.cmf.id;
+    long_key = fclass _ fname %]
 
     <div class="facet_box_temp">
         <div class="header">
-            <span class="button">
-
-                [% IF close_facets.grep(close_key).0;
-                    new_close = [];
-                    FOR fct IN close_facets;
-                        IF fct != close_key;
-                            new_close.push(fct);
+                [% IF long_facets.grep(long_key).0;
+                    new_long = [];
+                    FOR fct IN long_facets;
+                        IF fct != long_key;
+                            new_long.push(fct);
                         END;
                     END;
-                    expand_url = mkurl('', {close_facet => new_close});
-                    IF new_close.size == 0;
-                        expand_url  = mkurl('', {}, ['close_facet']);
+                    expand_url = mkurl('', {long_facet => new_long});
+                    IF new_long.size == 0;
+                        expand_url  = mkurl('', {}, ['long_facet']);
                     END;
                 %]
-                    <a href="[% expand_url %]"><img 
-                        src="[% ctx.media_prefix %]/images/adv_search_plus_btn.png" alt="[% l('Expand') %]" /></a>
-                [% ELSE %]
-                    <a href="[% mkurl('', {close_facet => close_facets.merge([close_key])}) %]"><img 
-                        src="[% ctx.media_prefix %]/images/adv_search_minus_btn.png" alt="[% l('Collapse') %]" /></a>
+                    <a class="button" href="[% expand_url %]">[% l("Fewer") %]</a>
+                [% ELSIF facet.data.size > DEFAULT_DISPLAY_COUNT %]
+                    <a class="button" href="[% mkurl('', {long_facet => long_facets.merge([long_key])}) %]">[% l("More") %]</a>
                 [% END %]
-            </span>
             <div class="title">[% facet.cmf.label %]</div>
         </div>
-        [% IF !close_facets.grep(close_key).0 %]
         <div class="box_wrapper">
             <div class="box">
             [% FOR facet_data IN facet.data;
@@ -91,6 +86,16 @@ FOR facet IN sorted_facets;
                         new_facets.push(selected);
                     END;
                 END;
+
+                display_count_by_cmf.$fid = display_count_by_cmf.$fid || 0;
+
+                NEXT UNLESS long_facets.grep(long_key).0 OR
+                    display_count_by_cmf.$fid < DEFAULT_DISPLAY_COUNT;
+
+                # fix syntax highlighting: >
+
+                display_count_by_cmf.$fid = display_count_by_cmf.$fid + 1;
+
                 IF this_selected;
                     # This facet is already selected by the user. 
                     # Link removes the facet from the set of selected facets.
@@ -122,7 +127,6 @@ FOR facet IN sorted_facets;
             [% END %]
             </div>
         </div> <!-- box_wrapper -->
-        [% END %]
     </div> <!-- facet_box_temp -->
 [% END %]
 </div> <!-- facet_box_wrapper -->