From 7e35393865d42452a366b8be734ce81c0a1e9892 Mon Sep 17 00:00:00 2001 From: Lebbeous Fogle-Weekley Date: Thu, 11 Oct 2012 16:00:36 -0400 Subject: [PATCH] TPAC: Make facet display work as in JSPAC 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 Signed-off-by: Kathy Lussier --- .../perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm | 10 +++- Open-ILS/src/templates/opac/css/style.css.tt2 | 4 +- Open-ILS/src/templates/opac/parts/config.tt2 | 1 + .../src/templates/opac/parts/result/facets.tt2 | 58 ++++++++++++---------- 4 files changed, 43 insertions(+), 30 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm index 4dc5ea0376..660b20ef87 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm @@ -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 diff --git a/Open-ILS/src/templates/opac/css/style.css.tt2 b/Open-ILS/src/templates/opac/css/style.css.tt2 index c22b9cedb3..b5c7418cfb 100644 --- a/Open-ILS/src/templates/opac/css/style.css.tt2 +++ b/Open-ILS/src/templates/opac/css/style.css.tt2 @@ -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 { diff --git a/Open-ILS/src/templates/opac/parts/config.tt2 b/Open-ILS/src/templates/opac/parts/config.tt2 index 2985f1fef8..b0fee8f9a3 100644 --- a/Open-ILS/src/templates/opac/parts/config.tt2 +++ b/Open-ILS/src/templates/opac/parts/config.tt2 @@ -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. diff --git a/Open-ILS/src/templates/opac/parts/result/facets.tt2 b/Open-ILS/src/templates/opac/parts/result/facets.tt2 index dd27dd9d27..fed133ab8d 100644 --- a/Open-ILS/src/templates/opac/parts/result/facets.tt2 +++ b/Open-ILS/src/templates/opac/parts/result/facets.tt2 @@ -1,12 +1,15 @@
[% -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 %]
- - - [% 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; %] - [% l('Expand') %] - [% ELSE %] - [% l('Collapse') %] + [% l("Fewer") %] + [% ELSIF facet.data.size > DEFAULT_DISPLAY_COUNT %] + [% l("More") %] [% END %] -
[% facet.cmf.label %]
- [% IF !close_facets.grep(close_key).0 %]
[% 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 %]
- [% END %]
[% END %]
-- 2.11.0