LP#1005040: add filter control widget for publication year
authorGalen Charlton <gmc@esilibrary.com>
Tue, 4 Oct 2016 21:00:15 +0000 (17:00 -0400)
committerKathy Lussier <klussier@masslnc.org>
Thu, 9 Feb 2017 20:45:07 +0000 (15:45 -0500)
This patch also changes the rewriting of an "is"
pubdate filter from between(value,value) to date1(value),
which should be slightly faster.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm
Open-ILS/src/templates/opac/parts/result/adv_filter.tt2

index d234753..c5a5307 100644 (file)
@@ -108,8 +108,7 @@ sub _prepare_biblio_search {
             $btw .= ')';
             $query = "$btw $query";
         } elsif ($cgi->param('pubdate') eq 'is') {
-            $query = 'between(' . $cgi->param('date1') .
-                ',' .  $cgi->param('date1') . ") $query";  # sic, date1 twice
+            $query = 'date1(' . $cgi->param('date1') . ") $query";
         } else {
             $query = $cgi->param('pubdate') .
                 '(' . $cgi->param('date1') . ") $query";
index ca3cbf0..dbe712f 100644 (file)
@@ -5,6 +5,8 @@
 # as that's got its own widget
 ignore_filters = ['search_format'];
 
+pubdate_filters = ['date1', 'before', 'after', 'between'];
+
 FOR filter IN ctx.query_struct.filters;
     fname = filter.name;
     IF ignore_filters.grep('^' _ fname _ '$').size;
@@ -14,7 +16,8 @@ FOR filter IN ctx.query_struct.filters;
     fvalues = filter.args;
     crad = ctx.get_crad(fname);
 
-    IF crad; # will be some special ones, like locations
+    # will be some special ones, like locations
+    IF crad AND NOT pubdate_filters.grep('^' _ filter.name _ '$').size;
         remove_filter = 'fi:' _ fname;
 %]
     <div class="facet_box_temp filter_box_temp">
@@ -75,7 +78,33 @@ FOR filter IN ctx.query_struct.filters;
             </div>
         </div> <!-- box_wrapper -->
     </div> <!-- facet_box_temp -->
-    [% END; # IF locations %]
+[% END; # IF locations %]
+
+[% IF pubdate_filters.grep('^' _ filter.name _ '$').size;
+    date1 = CGI.param('date1');
+    date2 = CGI.param('date2');
+%]
+    <div class="facet_box_temp filter_box_temp">
+        <div class="header">
+            <a class="button"
+              title="[% l('Remove publication date filter') %]"
+              href="[% mkurl('', {}, ['pubdate', 'date1', 'date2']) %]" rel="nofollow" vocab="">
+              [% l("Remove") %]
+            </a>
+            <h4 class="title">[% IF filter.negate; l('Not'); END %] [% l('Publication Year') %]</h4>
+        </div>
+        <div class="box_wrapper">
+            <div class="box">
+              [% IF    filter.name == 'date1'      %][% l('[_1]', date1) %]
+              [% ELSIF filter.name == 'before'  %][% l('Before [_1]', date1) %]
+              [% ELSIF filter.name == 'after'   %][% l('After [_1]', date1) %]
+              [% ELSIF filter.name == 'between' %][% l('Between [_1] and [_2]', date1, date2) %]
+              [% END %]
+            </div>
+        </div> <!-- box_wrapper -->
+    </div> <!-- facet_box_temp -->
+[% END; # IF pubdate_filters %]
+
 [% END; # FOR %]
 </div> <!-- facet_box_wrapper -->