瀏覽代碼

[search] Support fixed date ranges in the global filter

Romain Rigaux 10 年之前
父節點
當前提交
80d3abe

+ 21 - 3
apps/search/src/search/static/search/js/search.ko.js

@@ -406,6 +406,23 @@ var Collection = function (vm, collection) {
   self.timeFilter.value.subscribe(function () {
     vm.search();
   });
+  self.timeFilter.type.subscribe(function (val) {
+    if (val == 'fixed' && self.timeFilter.from().length == 0) {
+      $.ajax({
+        type: "POST",
+        url: "/search/get_range_facet",
+        data: {
+          collection: ko.mapping.toJSON(self),
+          facet: ko.mapping.toJSON({widgetType: 'facet-widget', field: self.timeFilter.field()}),
+          action: 'get_range'
+        },
+        success: function (data) {
+          self.timeFilter.from(data.properties.start);
+          self.timeFilter.to(data.properties.end);
+        }
+      });
+    }
+  });
   self.template = ko.mapping.fromJS(collection.template);
   self.template.fieldsSelected.subscribe(function () {
     vm.search();
@@ -993,7 +1010,7 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
   self.results = ko.observableArray([]);
   self.resultsHash = '';
   self.norm_facets = {};
-  self.getFacetFromQuery = function (facet_id) {	
+  self.getFacetFromQuery = function (facet_id) {
     if (! (facet_id in self.norm_facets)) {
       self.norm_facets[facet_id] = ko.mapping.fromJS({
           id: facet_id,
@@ -1156,6 +1173,7 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
     $.each(self.fieldAnalyses(), function (index, analyse) { // Invalidate stats analysis
       analyse.stats.data.removeAll();
     });
+
     if (self.getFieldAnalysis()) {
       self.getFieldAnalysis().update();
     }
@@ -1254,8 +1272,8 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
     )
     .done(function() {
       if (arguments[0] instanceof Array) { // If multi queries
-    	var histograms = self.collection.getHistogramFacets();
-    	for(var h = 0; h < histograms.length; h++){ // Do not use $.each here
+        var histograms = self.collection.getHistogramFacets();
+        for(var h = 0; h < histograms.length; h++){ // Do not use $.each here
           var histoFacetId = histograms[h].id();
           var histoFacet = self.getFacetFromQuery(histoFacetId);
           var _series = [];

+ 17 - 5
apps/search/src/search/templates/search.mako

@@ -79,7 +79,8 @@ ${ commonheader(_('Search'), "search", user, "80px") | n,unicode }
     <!-- /ko -->
 
     <select data-bind="options: $root.availableDateFields, value: collection.timeFilter.field, optionsValue: 'name', visible: $root.isEditing() && $root.availableDateFields().length > 0" class="input-medium" style="margin-left: 4px"></select>
-    <span data-bind="template: {name: 'time-filter'}"></span>
+    <span data-bind="template: {name: 'time-filter'}, visible: collection.timeFilter.type() == 'rolling'"></span>
+    <span data-bind="template: {name: 'time-fixed-filter'}, visible: collection.timeFilter.type() == 'fixed'"></span>
   </form>
 
   <form class="form-search" style="margin: 0" data-bind="submit: searchBtn, visible: columns().length != 0">
@@ -106,8 +107,8 @@ ${ commonheader(_('Search'), "search", user, "80px") | n,unicode }
         <!--[if IE]><img src="${ static('desktop/art/spinner-inverted.gif') }" data-bind="visible: isRetrievingResults()"/><![endif]-->
       </button>
 
-      <span data-bind="template: {name: 'time-filter'}"></span>
-
+      <span data-bind="template: {name: 'time-filter'}, visible: collection.timeFilter.type() == 'rolling'"></span>
+      <span data-bind="template: {name: 'time-fixed-filter'}, visible: collection.timeFilter.type() == 'fixed'"></span>
     </div>
   </form>
 </div>
@@ -1612,6 +1613,17 @@ ${ dashboard.layout_skeleton() }
 </script>
 
 
+<script type="text/html" id="time-fixed-filter">
+  <span data-bind="visible: $root.availableDateFields().length > 0" >
+    <span data-bind="text: $root.collection.timeFilter.from" rel="tooltip" data-placement="bottom" data-toggle="modal" data-target="#timeSettingsDemiModal"></span>
+    <span data-bind="text: $root.collection.timeFilter.to" rel="tooltip" data-placement="bottom" data-toggle="modal" data-target="#timeSettingsDemiModal"></span>    
+    <a class="btn pointer" title="${ _('Time Settings') }" rel="tooltip" data-placement="bottom" data-toggle="modal" data-target="#timeSettingsDemiModal">
+      <i class="fa fa-calendar"></i>
+    </a>    
+  </span>
+</script>
+
+
 <script type="text/html" id="time-filter-select">
   <select id="settingstimeinterval" data-bind="value: collection.timeFilter.value" class="input-medium" style="margin-right: 4px">
     <option value="all">${ _('All') }</option>
@@ -1683,8 +1695,8 @@ ${ dashboard.layout_skeleton() }
 
             <!-- ko if: $root.availableDateFields().length == 0 -->
               <label class="checkbox">
-                  <input type="checkbox" style="margin-right: 4px; margin-top: 9px" data-bind="checked: $root.collection.autorefresh"/> ${ _('Auto-refresh every') } <input type="number" class="input-mini" style="margin-bottom: 0; margin-left: 6px; margin-right: 6px; width: 46px; text-align:center" data-bind="value: $root.collection.autorefreshSeconds"/> ${ _('seconds') }
-                </label>
+                <input type="checkbox" style="margin-right: 4px; margin-top: 9px" data-bind="checked: $root.collection.autorefresh"/> ${ _('Auto-refresh every') } <input type="number" class="input-mini" style="margin-bottom: 0; margin-left: 6px; margin-right: 6px; width: 46px; text-align:center" data-bind="value: $root.collection.autorefreshSeconds"/> ${ _('seconds') }
+              </label>
             <!-- /ko -->
           </fieldset>
         </form>

+ 1 - 1
desktop/libs/libsolr/src/libsolr/api.py

@@ -141,7 +141,7 @@ class SolrApi(object):
 
     time_field = collection['timeFilter'].get('field')
 
-    if time_field and collection['timeFilter']['value'] != 'all':
+    if time_field and (collection['timeFilter']['value'] != 'all' or collection['timeFilter']['type'] == 'fixed'):
       # fqs overrides main time filter
       fq_time_ids = [fq['id'] for fq in query['fqs'] if fq['field'] == time_field]
       props['time_filter_overrides'] = fq_time_ids