From: Bill Erickson Date: Wed, 4 Jan 2012 18:03:01 +0000 (-0500) Subject: TPac: facet display filtering and sorting X-Git-Tag: sprint4-merge-nov22~4599 X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=7510d7ff71c6cf1f2fc8ba9210a2d7ef34bc52d3;p=working%2FEvergreen.git TPac: facet display filtering and sorting Provides the ability (via config.tt2) to define which facets should display and the order of facet display. The behavior is consistent with the openils.widget.FacetSidebar Dojo class, used in JSPAC. Signed-off-by: Bill Erickson Signed-off-by: Jason Stephenson Signed-off-by: Mike Rylander --- diff --git a/Open-ILS/src/templates/opac/parts/config.tt2 b/Open-ILS/src/templates/opac/parts/config.tt2 index e1104720e5..9d802e301d 100644 --- a/Open-ILS/src/templates/opac/parts/config.tt2 +++ b/Open-ILS/src/templates/opac/parts/config.tt2 @@ -57,4 +57,16 @@ reset_password = 'true'; record.summary.jacket_size = 'medium'; +############################################################################## +# Define the order in which facets are displayed. Only facets listed here +# will be displayed. To show all facets sorted by name, comment out this +# setting. +# facet.display = [] # show no facets +facet.display = [ + {facet_class => 'author', facet_order => ['personal', 'corporate']}, + {facet_class => 'subject', facet_order => ['topic']}, + {facet_class => 'series', facet_order => ['seriestitle']}, + {facet_class => 'subject', facet_order => ['name', 'geographic']} +]; + %] diff --git a/Open-ILS/src/templates/opac/parts/result/facets.tt2 b/Open-ILS/src/templates/opac/parts/result/facets.tt2 index 7b027738c4..dd27dd9d27 100644 --- a/Open-ILS/src/templates/opac/parts/result/facets.tt2 +++ b/Open-ILS/src/templates/opac/parts/result/facets.tt2 @@ -4,94 +4,126 @@ close_facets = CGI.param('close_facet') || []; selected_facets = CGI.param('facet') || []; -# collect facet type labels for easier sorting -labels = []; -FOR facet IN ctx.search_facets.values; - labels.push(facet.cmf.label); -END; +# sorted list of search facets +sorted_facets = []; + +IF facet.display; + + # facet display configuration present. Traverse the + # configuration lists, find the matching facets from + # search facet data, and append them to the sorted + # list of facets. + + FOR display_chunk IN facet.display; + FOR display_field IN display_chunk.facet_order; + # find the matching facet in the facet data + FOR facet IN ctx.search_facets.values; + IF facet.cmf.field_class == display_chunk.facet_class + AND facet.cmf.name == display_field; + sorted_facets.push(facet); + END; + END; + END; + END; -FOR facet_label IN labels.sort; +ELSE; + + # No facet display configuration is present. + # show all facets, sorted by name. + + # collect facet type labels for easier sorting + labels = []; FOR facet IN ctx.search_facets.values; - IF facet.cmf.label == facet_label; - fclass = facet.cmf.field_class; - fname = facet.cmf.name; - close_key = fclass _ fname %] + 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; +END; -
-
- +FOR facet IN sorted_facets; + fclass = facet.cmf.field_class; + fname = facet.cmf.name; + close_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); - END; - END; - expand_url = mkurl('', {close_facet => new_close}); - IF new_close.size == 0; - expand_url = mkurl('', {}, ['close_facet']); - END; - %] - [% l('Expand') %] - [% ELSE %] - [% l('Collapse') %] - [% END %] - -
[% facet.cmf.label %]
-
- [% IF !close_facets.grep(close_key).0 %] -
-
- [% FOR facet_data IN facet.data; - display_value = facet_data.value | html; - param_string = fclass _ '|' _ fname _ '[' _ facet_data.value _ ']'; - new_facets = []; - this_selected = 0; - FOR selected IN selected_facets; - IF selected == param_string; - this_selected = 1; - ELSE; - new_facets.push(selected); +
+
+ + + [% IF close_facets.grep(close_key).0; + new_close = []; + FOR fct IN close_facets; + IF fct != close_key; + new_close.push(fct); END; END; - IF this_selected; - # This facet is already selected by the user. - # Link removes the facet from the set of selected facets. - %] -
-
- [% IF new_facets.size == 0 %] - [% display_value %] - [% ELSE %] - [% display_value %] - [% END %] -
-
([% facet_data.count %])
-
 
+ expand_url = mkurl('', {close_facet => new_close}); + IF new_close.size == 0; + expand_url = mkurl('', {}, ['close_facet']); + END; + %] + [% l('Expand') %] + [% ELSE %] + [% l('Collapse') %] + [% END %] + +
[% facet.cmf.label %]
+
+ [% IF !close_facets.grep(close_key).0 %] +
+
+ [% FOR facet_data IN facet.data; + display_value = facet_data.value | html; + param_string = fclass _ '|' _ fname _ '[' _ facet_data.value _ ']'; + new_facets = []; + this_selected = 0; + FOR selected IN selected_facets; + IF selected == param_string; + this_selected = 1; + ELSE; + new_facets.push(selected); + END; + END; + IF this_selected; + # This facet is already selected by the user. + # Link removes the facet from the set of selected facets. + %] +
+
+ [% IF new_facets.size == 0 %] + [% display_value %] + [% ELSE %] + [% display_value %] + [% END %]
- [% - ELSE; - # This facet is not currently selected. If selected, - # append this facet to the list of currently active facets. - %] -
- -
([% facet_data.count %])
-
 
+
([% facet_data.count %])
+
 
+
+ [% + ELSE; + # This facet is not currently selected. If selected, + # append this facet to the list of currently active facets. + %] +
+ - [% END %] +
([% facet_data.count %])
+
 
+
[% END %] -
-
[% END %] -
+
+
[% END %] - [% END %] +
[% END %]