Просмотр исходного кода

HUE-2173 [dashboard] Port the gradient map to the nested faceting

Romain Rigaux 8 лет назад
Родитель
Сommit
7ab9b55

+ 6 - 6
desktop/libs/dashboard/src/dashboard/api.py

@@ -392,6 +392,8 @@ def _create_facet(collection, user, facet_id, facet_label, facet_field, widget_t
       facet_type = 'field'
 
     if widget_type in ('bucket-widget', 'pie2-widget', 'timeline-widget', 'tree2-widget', 'text-facet-widget', 'hit-widget', 'gradient-map-widget'):
+      properties = {'canRange': False, 'stacked': False}
+
       if widget_type == 'text-facet-widget':
         properties['type'] = facet_type
 
@@ -408,13 +410,8 @@ def _create_facet(collection, user, facet_id, facet_label, facet_field, widget_t
         facet['stacked'] = False
         facet['type'] = 'range'
       else:
-        facet['canRange'] = False
         facet['type'] = facet_type
 
-      if widget_type == 'gradient-map-widget':
-        properties['scope'] = 'world'
-        facet['limit'] = 100
-
       properties['facets'] = [facet]
       properties['domain'] = {'blockParent': [], 'blockChildren': []}
 
@@ -432,11 +429,14 @@ def _create_facet(collection, user, facet_id, facet_label, facet_field, widget_t
         properties['scope'] = 'tree'
         properties['facets_form']['limit'] = 5
         properties['isOldPivot'] = True
+      elif widget_type == 'gradient-map-widget':
+        properties['scope'] = 'world'
+        facet['limit'] = 100
       else:
         properties['scope'] = 'stack'
         properties['timelineChartType'] = 'bar'
 
-  if widget_type in ('tree-widget', 'heatmap-widget', 'map-widget'):
+  if widget_type in ('tree-widget', 'heatmap-widget', 'map-widget') and widget_type != 'gradient-map-widget':
     properties['mincount'] = 1
     properties['facets'] = []
     properties['stacked'] = True

+ 17 - 14
desktop/libs/dashboard/src/dashboard/static/dashboard/js/search.ko.js

@@ -711,22 +711,22 @@ var Collection = function (vm, collection) {
         });
       }
     } else {
-        facet.properties.limit.subscribe(function () {
+      facet.properties.limit.subscribe(function () {
+        vm.search();
+      });
+      facet.properties.mincount.subscribe(function () {
+        vm.search();
+      });
+      if (facet.properties.gap) {
+        facet.properties.gap.subscribe(function () {
           vm.search();
         });
-        facet.properties.mincount.subscribe(function () {
+      }
+      if (facet.properties.aggregate) {
+        facet.properties.aggregate.function.subscribe(function () {
           vm.search();
         });
-        if (facet.properties.gap) {
-          facet.properties.gap.subscribe(function () {
-            vm.search();
-          });
-        }
-        if (facet.properties.aggregate) {
-          facet.properties.aggregate.function.subscribe(function () {
-            vm.search();
-          });
-        }
+      }
     }
 
     // For Solr 5+  only
@@ -790,18 +790,20 @@ var Collection = function (vm, collection) {
   }
 
   self._addObservablesToNestedFacet = function(facet, nestedFacet, vm) {
-
     nestedFacet.limit.subscribe(function () {
       vm.search();
     });
-      nestedFacet.mincount.subscribe(function () {
+
+    nestedFacet.mincount.subscribe(function () {
       vm.search();
     });
+
     if (nestedFacet.gap) {
       nestedFacet.gap.subscribe(function () {
         vm.search();
       });
     }
+
     if (nestedFacet.aggregate) {
       nestedFacet.aggregate.function.subscribe(function () {
         vm.search();
@@ -815,6 +817,7 @@ var Collection = function (vm, collection) {
   }
 
   self.facets = ko.mapping.fromJS(collection.facets);
+
   $.each(self.facets(), function (index, facet) {
     self._addObservablesToFacet(facet, vm);
   });

+ 28 - 30
desktop/libs/dashboard/src/dashboard/templates/common_search.mako

@@ -491,7 +491,7 @@ ${ dashboard.layout_skeleton(suffix='search') }
       </div>
     <!-- /ko -->
 
-    <!-- ko if: widgetType() == 'map-widget' || widgetType() == 'gradient-map-widget' -->
+    <!-- ko if: widgetType() == 'map-widget' -->
       <div class="facet-field-cnt">
         <span class="spinedit-cnt">
           <span class="facet-field-label facet-field-label-fixed-width">
@@ -623,30 +623,6 @@ ${ dashboard.layout_skeleton(suffix='search') }
   </span>
   <!-- /ko -->
 
-  <!-- ko if: widgetType() == 'gradient-map-widget' -->
-  <div class="facet-field-cnt">
-    <span class="spinedit-cnt">
-      <span class="facet-field-label facet-field-label-fixed-width">
-        ${ _('Scope') }
-      </span>
-      <select data-bind="selectedOptions: properties.scope" class="input-small">
-        <option value="world">${ _("World") }</option>
-        <option value="europe">${ _("Europe") }</option>
-        <option value="aus">${ _("Australia") }</option>
-        <option value="bra">${ _("Brazil") }</option>
-        <option value="can">${ _("Canada") }</option>
-        <option value="chn">${ _("China") }</option>
-        <option value="fra">${ _("France") }</option>
-        <option value="deu">${ _("Germany") }</option>
-        <option value="ita">${ _("Italy") }</option>
-        <option value="jpn">${ _("Japan") }</option>
-        <option value="gbr">${ _("UK") }</option>
-        <option value="usa">${ _("USA") }</option>
-      </select>
-    </span>
-  </div>
-  <!-- /ko -->
-
   <div class="filter-box" data-bind="visible: $root.isEditing() && properties.facets().length < 15 && widgetType() != 'hit-widget'" style="opacity: 0.7">
     <div class="title" style="border: 1px dashed #d8d8d8; border-bottom: none">
       <a data-bind="visible: properties.facets_form.field() && properties.facets_form.field() != 'formula' || properties.facets_form.aggregate.formula(), click: $root.collection.addPivotFacetValue2" class="pull-right" href="javascript:void(0)">
@@ -2305,17 +2281,39 @@ ${ dashboard.layout_skeleton(suffix='search') }
   <div class="row-fluid" data-bind="with: $root.getFacetFromQuery(id())">
     <div data-bind="with: $root.collection.getFacetById($parent.id())" style="margin-bottom: 20px">
       <span data-bind="template: { name: 'facet-toggle2' }"></span>
+      <div class="clearfix"></div>
     </div>
 
     <!-- ko with: $root.collection.getFacetById($parent.id()) -->
-    <div class="margin-bottom-10" data-bind="visible: ! $root.isEditing()">
-
-        <!-- ko if: $data.properties.facets().length == 1 -->
+      <div class="facet-field-cnt">
+        <span class="spinedit-cnt">
+          <span class="facet-field-label facet-field-label-fixed-width">
+            ${ _('Scope') }
+          </span>
+          <select data-bind="selectedOptions: properties.scope" class="input-small">
+            <option value="world">${ _("World") }</option>
+            <option value="europe">${ _("Europe") }</option>
+            <option value="aus">${ _("Australia") }</option>
+            <option value="bra">${ _("Brazil") }</option>
+            <option value="can">${ _("Canada") }</option>
+            <option value="chn">${ _("China") }</option>
+            <option value="fra">${ _("France") }</option>
+            <option value="deu">${ _("Germany") }</option>
+            <option value="ita">${ _("Italy") }</option>
+            <option value="jpn">${ _("Japan") }</option>
+            <option value="gbr">${ _("UK") }</option>
+            <option value="usa">${ _("USA") }</option>
+          </select>
+        </span>
+      </div>
+      
+      <div class="margin-bottom-10" data-bind="visible: ! $root.isEditing()">
+        <!-- ko if: $data.properties.facets().length == 2 -->
           <div class="margin-bottom-10">
-            <span data-bind="text: $data.properties.facets()[0].field"></span>
+            <span data-bind="text: $data.properties.facets()[1].field"></span>
           </div>
         <!-- /ko -->
-    </div>
+      </div>
 
       <span data-bind="template: { name: 'data-grid' }"></span>
     <!-- /ko -->

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

@@ -151,6 +151,14 @@ class SolrApi(object):
               _f['sort'] = {_fname: facet['properties']['sort']}
               # domain = '-d2:NaN' # Solr 6.4
 
+          if facet['properties'].get('domain'):
+            if facet['properties']['domain'].get('blockParent') or facet['properties']['domain'].get('blockChildren'):
+              _f['domain'] = {}
+              if facet['properties']['domain'].get('blockParent'):
+                _f['domain']['blockParent'] = ' OR '.join(facet['properties']['domain']['blockParent'])
+              if facet['properties']['domain'].get('blockChildren'):
+                _f['domain']['blockChildren'] = ' OR '.join(facet['properties']['domain']['blockChildren'])
+
           if _f:
             sort = {'count': facet['properties']['facets'][0]['sort']}
             for i, agg in enumerate(self._get_dimension_aggregates(facet['properties']['facets'][1:])):
@@ -274,14 +282,6 @@ class SolrApi(object):
 #         if timeFilter and timeFilter['time_field'] == facet['field'] and (widget['id'] not in timeFilter['time_filter_overrides']): # or facet['widgetType'] != 'bucket-widget'):
 #           _f.update(self._get_time_filter_query(timeFilter, facet))
 
-      if facet.get('domain'):
-        if facet['domain'].get('blockParent') or facet['domain'].get('blockChildren'):
-          _f['domain'] = {}
-          if facet['domain'].get('blockParent'):
-            _f['domain']['blockParent'] = ' OR '.join(facet['domain']['blockParent'])
-          if facet['domain'].get('blockChildren'):
-            _f['domain']['blockChildren'] = ' OR '.join(facet['domain']['blockChildren'])
-
       if widget['widgetType'] == 'tree2-widget' and facets[-1]['aggregate']['function'] != 'count':
         _f['subcount'] = self._get_aggregate_function(facets[-1])