TPac: facet display filtering and sorting
authorBill Erickson <berick@esilibrary.com>
Wed, 4 Jan 2012 18:03:01 +0000 (13:03 -0500)
committerMike Rylander <mrylander@gmail.com>
Mon, 13 Feb 2012 20:22:18 +0000 (15:22 -0500)
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 <berick@esilibrary.com>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/templates/opac/parts/config.tt2
Open-ILS/src/templates/opac/parts/result/facets.tt2

index e110472..9d802e3 100644 (file)
@@ -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']}
+];
+
 %]
index 7b02773..dd27dd9 100644 (file)
 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;
 
-        <div class="facet_box_temp">
-            <div class="header">
-                <span class="button">
+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;
-                    %]
-                        <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>
-                    [% 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;
-                    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);
+    <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);
                         END;
                     END;
-                    IF this_selected;
-                        # This facet is already selected by the user. 
-                        # Link removes the facet from the set of selected facets.
-                    %] 
-                        <div class="facet_template facet_template_selected">
-                            <div class="facet">
-                                [% IF new_facets.size == 0 %]
-                                <a href="[% mkurl('', {}, ['facet']) %]">[% display_value %]</a>
-                                [% ELSE %]
-                                <a href="[% mkurl('', {facet => new_facets}) %]">[% display_value %]</a>
-                                [% END %]
-                            </div>
-                            <div class="count">([% facet_data.count %])</div>
-                            <div class="clear">&nbsp;</div>
+                    expand_url = mkurl('', {close_facet => new_close});
+                    IF new_close.size == 0;
+                        expand_url  = mkurl('', {}, ['close_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>
+                [% 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;
+                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.
+                %] 
+                    <div class="facet_template facet_template_selected">
+                        <div class="facet">
+                            [% IF new_facets.size == 0 %]
+                            <a href="[% mkurl('', {}, ['facet']) %]">[% display_value %]</a>
+                            [% ELSE %]
+                            <a href="[% mkurl('', {facet => new_facets}) %]">[% display_value %]</a>
+                            [% END %]
                         </div>
-                    [% 
-                        ELSE;
-                        # This facet is not currently selected.  If selected, 
-                        # append this facet to the list of currently active facets.
-                    %]
-                        <div class="facet_template">
-                            <div class="facet">
-                                <a href='[% mkurl('', {facet => selected_facets.merge([param_string])}, ['page']) %]'>[% display_value %]</a>
-                            </div>
-                            <div class="count">([% facet_data.count %])</div>
-                            <div class="clear">&nbsp;</div>
+                        <div class="count">([% facet_data.count %])</div>
+                        <div class="clear">&nbsp;</div>
+                    </div>
+                [% 
+                    ELSE;
+                    # This facet is not currently selected.  If selected, 
+                    # append this facet to the list of currently active facets.
+                %]
+                    <div class="facet_template">
+                        <div class="facet">
+                            <a href='[% mkurl('', {facet => selected_facets.merge([param_string])}, ['page']) %]'>[% display_value %]</a>
                         </div>
-                    [% END %]
+                        <div class="count">([% facet_data.count %])</div>
+                        <div class="clear">&nbsp;</div>
+                    </div>
                 [% END %]
-                </div>
-            </div> <!-- box_wrapper -->
             [% END %]
-        </div> <!-- facet_box_temp -->
+            </div>
+        </div> <!-- box_wrapper -->
         [% END %]
-    [% END %]
+    </div> <!-- facet_box_temp -->
 [% END %]
 </div> <!-- facet_box_wrapper -->