浏览代码

HUE-2173 [dashboard] Pass to clean-up recursive facets template

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

+ 61 - 36
desktop/libs/dashboard/src/dashboard/static/dashboard/js/search.ko.js

@@ -685,7 +685,7 @@ var Collection = function (vm, collection) {
     return _field;
   };
 
-  self._get_field_operations = function(field, facet) {
+  self._get_field_operations = function(field, facet) {console.log('aaaa ' + field);
     if (! field) {
       return HIT_OPTIONS;
     } else if (isNumericColumn(field.type())) {
@@ -693,16 +693,16 @@ var Collection = function (vm, collection) {
     } else if (isDateTimeColumn(field.type())) {
       return DATETIME_HIT_OPTIONS;
     } else {
-      facet.properties.facets_form.aggregate.function('count');
-      return facet.widgetType() == 'hit-widget' ? ALPHA_HIT_COUNTER_OPTIONS : ALPHA_HIT_OPTIONS;
+      //facet.properties.facets_form.aggregate.function('count');
+      return ALPHA_HIT_OPTIONS; //facet.widgetType() == 'hit-widget' ? ALPHA_HIT_COUNTER_OPTIONS : ALPHA_HIT_OPTIONS;
     }
   }
 
-  self._addObservablesToFacet = function(facet, vm) {
-    // Very top facet
+  // Very top facet
+  self._addObservablesToFacet = function(facet, vm) { 
     if (facet.properties && facet.properties.facets_form && facet.properties.facets_form.aggregate) { // Only Solr 5+
       facet.properties.facets_form.aggregate.metrics = ko.computed(function() {
-        var _field = self.getTemplateField(facet.widgetType() == 'hit-widget' ? facet.field() : facet.properties.facets_form.field(), self.template.fieldsAttributes());
+        var _field = self.getTemplateField(facet.properties.facets_form.field(), self.template.fieldsAttributes());
         return self._get_field_operations(_field, facet);
       });
 
@@ -711,29 +711,27 @@ var Collection = function (vm, collection) {
           vm.search();
         });
       }
-    }
-
-    var facet_properties = facet.properties ? facet.properties : facet; // Old facet, nested facet
-
-    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();
-      });
-    }
-    if (facet_properties.aggregate) {
-      facet_properties.aggregate.function.subscribe(function () {
-        vm.search();
-      });
-    }
-
-    // For Solr 5+ facets only
-    if (typeof facet.template != 'undefined') {
+    } else {
+	    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();
+	      });
+	    }
+	    if (facet.properties.aggregate) {
+	      facet.properties.aggregate.function.subscribe(function () {
+	        vm.search();
+	      });
+	    }
+    }
+        
+    // For Solr 5+  only
+    if (typeof facet.template != 'undefined') {        
       facet.template.filteredAttributeFields = ko.computed(function() { // Dup of template.filteredAttributeFields
         var _fields = [];
 
@@ -784,18 +782,48 @@ var Collection = function (vm, collection) {
         type: self.engine(),
       }));
     }
+    
+    if (facet.properties.facets) { // Sub facet
+    	$.each(facet.properties.facets(), function (index, nestedFacet) {
+          self._addObservablesToNestedFacet(self, nestedFacet, vm);
+    	});
+      }
+  }
+  
+  self._addObservablesToNestedFacet = function(facet, nestedFacet, vm) {
+
+	nestedFacet.limit.subscribe(function () {
+      vm.search();
+    });
+	  nestedFacet.mincount.subscribe(function () {
+      vm.search();
+    });
+    if (nestedFacet.gap) {
+      nestedFacet.gap.subscribe(function () {
+        vm.search();
+      });
+    }
+
+    nestedFacet.aggregate.function.subscribe(function () {
+      vm.search();
+    });
+
+    nestedFacet.aggregate.metrics = ko.computed(function() {
+	  var _field = self.getTemplateField(nestedFacet.field(), facet.template.fieldsAttributes());
+	  return self._get_field_operations(_field, facet);
+	});
   }
 
   self.facets = ko.mapping.fromJS(collection.facets);
   $.each(self.facets(), function (index, facet) {
     self._addObservablesToFacet(facet, vm);
 
-    if (facet.properties.aggregate && facet.properties.aggregate.function) {
+  /*  if (facet.properties.aggregate && facet.properties.aggregate.function) {
       facet.properties.aggregate.function.subscribe(function () {
         vm.search();
       });
-    }
-
+    }*/
+/*
     if (typeof facet.properties.facets != 'undefined') {
       $.each(facet.properties.facets(), function (index, pivotFacet) {
         if (pivotFacet.aggregate && pivotFacet.aggregate.function) {
@@ -804,7 +832,7 @@ var Collection = function (vm, collection) {
           });
         }
       });
-    }
+    }*/
   });
 
 
@@ -942,9 +970,6 @@ var Collection = function (vm, collection) {
             // .isLoading(false)
           } else {
             self._addObservablesToFacet(facet, vm); // Top widget
-            if (facet.properties.facets) { // Sub facet
-              self._addObservablesToFacet(facet.properties.facets()[0], vm);
-            }
           }
 
           self.facets.push(facet);

+ 7 - 22
desktop/libs/dashboard/src/dashboard/templates/common_search.mako

@@ -570,6 +570,9 @@ ${ dashboard.layout_skeleton(suffix='search') }
 
 <script type="text/html" id="facet-toggle2">
   <div class="pull-left margin-right-20">
+  
+  ## TODO toggle3 for nested facet probably / compat for toggle2
+  
 ##   <!-- ko if: $root.isEditing -->
 ##     <!-- ko if: properties.canRange() && typeof properties.type != "undefined" -->
 ##     <div class="facet-field-cnt">
@@ -582,20 +585,7 @@ ${ dashboard.layout_skeleton(suffix='search') }
 ##       </a>
 ##     </div>
 ##     <!-- /ko -->
-## 
-##     <!-- ko if: widgetType() != 'hit-widget' -->
-##     <div class="facet-field-cnt">
-##       <span class="facet-field-label facet-field-label-fixed-width">${ _('Sorting') }</span>
-##       <a href="javascript: void(0)" title="${ _('Toggle sort order') }" data-bind="click:  function() { $root.collection.toggleSortFacet2($data, $data); }">
-##         <i class="fa" data-bind="css: { 'fa-caret-down': properties.sort() == 'desc', 'fa-caret-up': properties.sort() == 'asc', 'fa-sort': properties.sort() == 'default' }"></i>
-##         <span data-bind="visible: properties.sort() == 'desc'">${_('descending')}</span>
-##         <span data-bind="visible: properties.sort() == 'asc'">${_('ascending')}</span>
-##         <span data-bind="visible: properties.sort() == 'default'">${_('default')}</span>
-##       </a>
-##     </div>
-##     <!-- /ko -->
-## 
-## 
+##  
 ##     <!-- ko if: type() == 'range' || type() == 'range-up' || (type() == 'nested' && typeof properties.min != "undefined") -->
 ##       <!-- ko ifnot: properties.isDate() -->
 ##         <div class="slider-cnt" data-bind="slider: {start: properties.min, end: properties.max, gap: properties.initial_gap, min: properties.initial_start, max: properties.initial_end, properties: properties, labels: SLIDER_LABELS}"></div>
@@ -2075,14 +2065,9 @@ ${ dashboard.layout_skeleton(suffix='search') }
 
     <!-- ko if: $root.isEditing -->
     <div>
-      ## For Counter widget
-      <!-- ko if: $data.function() != 'field' && $parent.properties -->
-        <select data-bind="options: $parents[1].properties.facets_form.aggregate.metrics, optionsText: 'label', optionsValue: 'value', value: $data.function" class="input-small"></select>
-      <!-- /ko -->
-
-      <!-- ko if: $data.function() != 'field' -->
-        <select data-bind="options: $parents[1].properties.facets_form.aggregate.metrics, optionsText: 'label', optionsValue: 'value', value: $data.function" class="input-small"></select>
-      <!-- /ko -->
+      ##<!-- ko if: $data.function() != 'field' -->
+        <select data-bind="options: metrics, optionsText: 'label', optionsValue: 'value', value: $data.function, disable: ($parents[1].widgetType() == 'text-facet-widget' && $index() == 0)" class="input-small"></select>
+      ##<!-- /ko -->
 
       <!-- ko if: $data.function() == 'percentile' -->
         <!-- ko foreach: percentiles() -->