浏览代码

HUE-7766 [dashboard] Move counter display into its own template

Romain Rigaux 8 年之前
父节点
当前提交
7cfcda1

+ 15 - 12
desktop/libs/dashboard/src/dashboard/templates/common_search.mako

@@ -1525,8 +1525,7 @@ ${ dashboard.layout_skeleton(suffix='search') }
         <!-- ko if: widgetType() == 'hit-widget' -->
           <!-- ko with: $parent -->
             <!-- ko if: counts().length > 0 -->
-              <i data-bind="css: { 'fa-caret-down': counts()[0].count < 0, 'fa-caret-up': counts()[0].count > 0 }"></i>
-              <span class="big-counter" data-bind="textSqueezer: counts()[0].count"></span>
+              <span class="big-counter" data-bind="template: { name: 'counter-form', data: {counts: counts()[0].count, properties: $root.collection.getFacetById($parent.id()).properties }}"></span>
             <!-- /ko -->
           <!-- /ko -->
         <!-- /ko -->
@@ -2012,22 +2011,26 @@ ${ dashboard.layout_skeleton(suffix='search') }
     <div data-bind="with: $root.collection.getFacetById($parent.id())">
       <span data-bind="template: { name: 'facet-toggle2' }"></span>
 
-      <span class="pull-right" data-bind="template: { name: 'facet-compare', data: properties.compare }"></span>
+      <span class="pull-right" data-bind="visible: $root.availableDateFields().length > 0, template: { name: 'facet-compare', data: properties.compare }"></span>
     </div>
 
-    <i class="fa big-counter" data-bind="css: { 'fa-caret-down': counts() < 0, 'fa-caret-up': counts() > 0 }"></i>
-    <span class="big-counter" data-bind="textSqueezer: counts"></span>
-
-    <span data-bind="with: $root.collection.getFacetById($parent.id())">
-      <span class="big-counter" data-bind="visible: properties.compare.use_percentage">
-        ${ '%' }
-      </span>
-    </span>
+    <span class="big-counter" data-bind="template: { name: 'counter-form', data: {counts: counts(), properties: $root.collection.getFacetById($parent.id()).properties }}"></span>
   </div>
   <!-- /ko -->
 </script>
 
 
+<script type="text/html" id="counter-form">
+  <i class="fa" data-bind="visible: properties.compare.is_enabled, css: { 'fa-caret-down': counts < 0, 'fa-caret-up': counts > 0 }"></i>
+
+  <span  data-bind="textSqueezer: counts"></span>
+
+  <span  data-bind="visible: properties.compare.use_percentage">
+    ${ '%' }
+  </span>
+</script>
+
+
 <script type="text/html" id="facet-compare">
   <input type="checkbox" data-bind="checked: is_enabled"/> ${ _('Compare') }
 
@@ -2049,7 +2052,7 @@ ${ dashboard.layout_skeleton(suffix='search') }
       </span>
       <input type="checkbox" data-bind="checked: use_percentage"/>
       <span class="facet-field-label">
-        ${ _('Display both') }
+        ${ _('Hide value') }
       </span>
       <input type="checkbox"/>
     </span>

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

@@ -178,9 +178,10 @@ class SolrApi(object):
         elif facet['type'] == 'function':
           if facet['properties']['facets']:
             if facet['properties']['compare']['is_enabled']:
+              # TODO: global compare override
               json_facets[facet['id']] = {
                 'type' : "range",
-                'field' : "time",
+                'field' : collection['timeFilter'].get('field'),
                 'start' : "2014-05-04T01:35:00Z/HOURS",
                 'end' : "2014-05-04T14:15:00Z/HOURS",
                 'gap' : "+12HOURS",