]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/templates-bootstrap/opac/parts/result/facets.tt2
LP#1778972: Tweaks and fixes to Bootstrap 4 template
[Evergreen.git] / Open-ILS / src / templates-bootstrap / opac / parts / result / facets.tt2
1 <div class="container-fluid my-3">
2 <div class="facet_box_wrapper row">
3 [%
4
5 long_facets = CGI.param('long_facet') || [];
6 selected_facets = CGI.param('facet') || [];
7
8 # sorted list of search facets
9 sorted_facets = [];
10
11 # we'll clobber the facet. "namespace" later
12 # Provide a default value if unset in config.tt2
13 DEFAULT_DISPLAY_COUNT = facet.default_display_count || 5;
14
15 IF facet.display;
16
17     # facet display configuration present.  Traverse the
18     # configuration lists, find the matching facets from
19     # search facet data, and append them to the sorted
20     # list of facets.
21
22     FOR display_chunk IN facet.display;
23         FOR display_field IN display_chunk.facet_order;
24             # find the matching facet in the facet data
25             FOR facet IN ctx.search_facets.values;
26                 IF facet.cmf.field_class == display_chunk.facet_class
27                         AND facet.cmf.name == display_field;
28                     sorted_facets.push(facet);
29                 END;
30             END;
31         END;
32     END;
33
34 ELSE;
35
36     # No facet display configuration is present.
37     # show all facets, sorted by name.
38
39     # collect facet type labels for easier sorting
40     labels = [];
41     FOR facet IN ctx.search_facets.values;
42         labels.push(facet.cmf.label);
43     END;
44
45     # We used to do a sort here, but now that's handled in EGCatLoader.
46     sorted_facets = ctx.search_facets.values;
47 END;
48
49 display_count_by_cmf = {};
50
51 FOR facet IN sorted_facets;
52     fclass = facet.cmf.field_class;
53     fname = facet.cmf.name;
54     fid = facet.cmf.id;
55     long_key = fclass _ fname %]
56
57     <div class="facet-card w-100">
58     <div class="card">
59         <div class="card-header">
60             <span class="title text-center">[% facet.cmf.label %]</span>
61
62         </div>
63         <div class="card-body">
64             <div>
65             [% FOR facet_data IN facet.data;
66                 display_value = facet_data.value | html;
67                 param_string = fclass _ '|' _ fname _ '[' _ facet_data.value _ ']';
68                 new_facets = [];
69                 this_selected = 0;
70                 FOR selected IN selected_facets;
71                     IF selected == param_string;
72                         this_selected = 1;
73                     ELSE;
74                         new_facets.push(selected);
75                     END;
76                 END;
77
78                 display_count_by_cmf.$fid = display_count_by_cmf.$fid || 0;
79
80                 NEXT UNLESS long_facets.grep(long_key).0 OR
81                     display_count_by_cmf.$fid < DEFAULT_DISPLAY_COUNT;
82
83                 # fix syntax highlighting: >
84
85                 display_count_by_cmf.$fid = display_count_by_cmf.$fid + 1;
86
87                 IF this_selected;
88                     # This facet is already selected by the user.
89                     # Link removes the facet from the set of selected facets.
90                 %]
91                     <div class="facet_template facet_template_selected">
92                         <div class="facet">
93                             [% IF new_facets.size == 0 %]
94                             <a
95                               title="[% l('Show all results, not just those matching this term') %]"
96                               href="[% mkurl('', {}, ['facet']) %]" rel="nofollow" vocab="">[% display_value %]</a>
97                             [% ELSE %]
98                             <a
99                               title="[% l('Expand to also show results not matching this term') %]"
100                               href="[% mkurl('', {facet => new_facets}) %]" rel="nofollow" vocab="">[% display_value %]</a>
101                             [% END %]
102                         </div>
103                         <div class="count">([% facet_data.count; IF facet_data.count == (ctx.superpage + 1) * ctx.superpage_size; '+'; END %])</div>
104                     </div>
105                 [%
106                     ELSE;
107                     # This facet is not currently selected.  If selected,
108                     # append this facet to the list of currently active facets.
109                 %]
110                     <div class="facet_template">
111                         <div class="facet">
112                             <a
113                               title="[% l('Limit to results matching this term') %]"
114                               href='[% mkurl('', {facet => selected_facets.merge([param_string])}, ['page']) %]' rel="nofollow" vocab="">
115                               [% display_value %]
116                             </a>
117                         </div>
118                         <div class="count">([% facet_data.count %])</div>
119                     </div>
120
121                 [% END %]
122
123             [% END %]</div>
124             <span class="float-right">
125                 [% IF long_facets.grep(long_key).0;
126                     new_long = [];
127                     FOR fct IN long_facets;
128                         IF fct != long_key;
129                             new_long.push(fct);
130                         END;
131                     END;
132                     expand_url = mkurl('', {long_facet => new_long});
133                     IF new_long.size == 0;
134                         expand_url  = mkurl('', {}, ['long_facet']);
135                     END;
136                 %]
137                     <a class="button" href="[% expand_url %]#facets"
138                       title="[% l('Show Fewer [_1] Entries', facet.cmf.label) %]" rel="nofollow" vocab="">
139                       [% l("Fewer") %]
140                     </a>
141                 [% ELSIF facet.data.size > DEFAULT_DISPLAY_COUNT %]
142                     <a class="button"
143                       title="[% l('Show More [_1] Entries', facet.cmf.label) %]"
144                       href="[% mkurl('', {long_facet => long_facets.merge([long_key])}) %]#facets" rel="nofollow" vocab="">
145                       [% l("More") %]
146                     </a>
147                 [% END %]
148             </span>
149             </div>
150
151         </div> <!-- box_wrapper -->
152     </div> <!-- facet_box_temp -->
153 [% END %]
154
155 </div> <!-- facet_box_wrapper -->
156 </div>