فهرست منبع

HUE-2173 [dashboard] Reformat some part of the code

Romain Rigaux 8 سال پیش
والد
کامیت
c4b4b72a05

+ 1 - 1
desktop/libs/dashboard/src/dashboard/models.py

@@ -539,7 +539,7 @@ def augment_solr_response(response, collection, query):
           agg_keys = counts and [key for key, value in counts[0].items() if key.lower().startswith('agg_') or key.lower().startswith('dim_')]
           agg_keys.sort(key=lambda a: a[4:])
 
-          if len(agg_keys) == 1 and agg_keys[0].lower().startswith('dim_'): #PB
+          if len(agg_keys) == 1 and agg_keys[0].lower().startswith('dim_'):
             agg_keys.insert(0, 'count')
           counts = _augment_stats_2d(name, facet, counts, selected_values, agg_keys, rows)
           actual_dimension = sum([_f['aggregate']['function'] == 'count' for _f in collection_facet['properties']['facets']])

+ 43 - 68
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) {console.log('aaaa ' + field);
+  self._get_field_operations = function(field, facet) {
     if (! field) {
       return HIT_OPTIONS;
     } else if (isNumericColumn(field.type())) {
@@ -693,13 +693,12 @@ var Collection = function (vm, collection) {
     } else if (isDateTimeColumn(field.type())) {
       return DATETIME_HIT_OPTIONS;
     } else {
-      //facet.properties.facets_form.aggregate.function('count');
-      return ALPHA_HIT_OPTIONS; //facet.widgetType() == 'hit-widget' ? ALPHA_HIT_COUNTER_OPTIONS : ALPHA_HIT_OPTIONS;
+      return facet.widgetType() == 'hit-widget' ? ALPHA_HIT_COUNTER_OPTIONS : ALPHA_HIT_OPTIONS;
     }
   }
 
   // Very top facet
-  self._addObservablesToFacet = function(facet, vm) { 
+  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.properties.facets_form.field(), self.template.fieldsAttributes());
@@ -712,26 +711,26 @@ var Collection = function (vm, collection) {
         });
       }
     } 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();
-	      });
-	    }
-    }
-        
+        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') {        
+    if (typeof facet.template != 'undefined') {
       facet.template.filteredAttributeFields = ko.computed(function() { // Dup of template.filteredAttributeFields
         var _fields = [];
 
@@ -782,20 +781,20 @@ 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);
-    	});
-      }
+      $.each(facet.properties.facets(), function (index, nestedFacet) {
+        self._addObservablesToNestedFacet(self, nestedFacet, vm);
+      });
+    }
   }
-  
+
   self._addObservablesToNestedFacet = function(facet, nestedFacet, vm) {
 
-	nestedFacet.limit.subscribe(function () {
+    nestedFacet.limit.subscribe(function () {
       vm.search();
     });
-	  nestedFacet.mincount.subscribe(function () {
+      nestedFacet.mincount.subscribe(function () {
       vm.search();
     });
     if (nestedFacet.gap) {
@@ -803,36 +802,21 @@ var Collection = function (vm, collection) {
         vm.search();
       });
     }
+    if (nestedFacet.aggregate) {
+      nestedFacet.aggregate.function.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);
-	});
+      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) {
-      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) {
-          pivotFacet.aggregate.function.subscribe(function () {
-            vm.search();
-          });
-        }
-      });
-    }*/
   });
 
 
@@ -961,18 +945,9 @@ var Collection = function (vm, collection) {
         if (data.status == 0) {
           var facet = ko.mapping.fromJS(data.facet);
 
-          if (false) {
-            // get doc2
-
-            // facet.subfacet = ko.mapping.fromJS(data.facet);
-            // self._addObservablesToFacet(facet, vm); // needed if we only have result?
-            // "read only"
-            // .isLoading(false)
-          } else {
-            self._addObservablesToFacet(facet, vm); // Top widget
-          }
-
+          self._addObservablesToFacet(facet, vm); // Top widget
           self.facets.push(facet);
+
           vm.search();
         } else {
           $(document).trigger("error", data.message);
@@ -1025,7 +1000,8 @@ var Collection = function (vm, collection) {
       'limit': ko.mapping.toJS(facet.properties.facets_form.limit),
       'mincount': ko.mapping.toJS(facet.properties.facets_form.mincount),
       'aggregate': ko.mapping.toJS(facet.properties.facets_form.aggregate),
-      'sort': ko.mapping.toJS(facet.properties.facets_form.aggregate.function == 'count' ? 'desc' : 'default')
+      'sort': ko.mapping.toJS(facet.properties.facets_form.aggregate.function == 'count' ? 'desc' : 'default'),
+      'canRange': false // No supported on dim 2 currently
     });
     pivot.aggregate.metrics = ko.computed(function() {
       var _field = self.getTemplateField(pivot.field(), self.template.fieldsAttributes());
@@ -1037,7 +1013,6 @@ var Collection = function (vm, collection) {
     facet.properties.facets_form.mincount(1);
     facet.properties.facets_form.sort('desc');
 
-    //facet.properties.facets_form.aggregate.function('count');
     facet.properties.facets_form.aggregate.formula('');
     facet.properties.facets_form.aggregate.percentiles.removeAll();
     facet.properties.facets_form.aggregate.percentiles.push({'value': 50});

+ 33 - 40
desktop/libs/dashboard/src/dashboard/templates/common_search.mako

@@ -1680,7 +1680,7 @@ ${ dashboard.layout_skeleton(suffix='search') }
 </script>
 
 
-
+## WIP skeleton
 <script type="text/html" id="document-widget">
   ##<div class="widget-spinner" data-bind="visible: isLoading()">
   ##  <i class="fa fa-spinner fa-spin"></i>
@@ -1692,10 +1692,10 @@ ${ dashboard.layout_skeleton(suffix='search') }
     <!-- ko with: $root.collection.getFacetById($parent.id()) -->
     <div>
       Name Uuid
-      
+
       ## Get sub widget by ID
       ## <div data-bind="template: { name: function() { return widgetType(); }}" class="widget-main-section"></div>
-      
+
     </div>
    <!-- /ko -->
   </div>
@@ -2036,9 +2036,8 @@ ${ dashboard.layout_skeleton(suffix='search') }
 <script type="text/html" id="metric-form">
 
     <!-- ko if: $root.isEditing -->
-
     <div>
-          <!-- ko with: aggregate -->
+      <!-- ko with: aggregate -->
       <select data-bind="options: metrics, optionsText: 'label', optionsValue: 'value', value: $data.function, disable: ($parents[1].widgetType() == 'text-facet-widget' && $index() == 0 && $parent.type)" class="input-small"></select>
 
       <!-- ko if: $data.function() == 'percentile' -->
@@ -2061,18 +2060,16 @@ ${ dashboard.layout_skeleton(suffix='search') }
       <input data-bind="value: formula, visible: $parent.field() == 'formula', valueUpdate: 'afterkeydown'"></input>
       <input data-bind="value: plain_formula" type="hidden"></input>
 
-
-
       <!-- ko if: $data.function() != 'field' && $parents[1].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($parents[1], $parent); }">
-          <i class="fa" data-bind="css: { 'fa-caret-down': $parent.sort() == 'desc', 'fa-caret-up': $parent.sort() == 'asc', 'fa-sort': $parent.sort() == 'default' }"></i>
-          <span data-bind="visible: $parent.sort() == 'desc'">${_('descending')}</span>
-          <span data-bind="visible: $parent.sort() == 'asc'">${_('ascending')}</span>
-          <span data-bind="visible: $parent.sort() == 'default'">${_('default')}</span>
-        </a>
-      </div>
+        <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($parents[1], $parent); }">
+            <i class="fa" data-bind="css: { 'fa-caret-down': $parent.sort() == 'desc', 'fa-caret-up': $parent.sort() == 'asc', 'fa-sort': $parent.sort() == 'default' }"></i>
+            <span data-bind="visible: $parent.sort() == 'desc'">${_('descending')}</span>
+            <span data-bind="visible: $parent.sort() == 'asc'">${_('ascending')}</span>
+            <span data-bind="visible: $parent.sort() == 'default'">${_('default')}</span>
+          </a>
+        </div>
 
         <div class="facet-field-cnt" data-bind="visible: $data.function() == 'count' && !$parent.canRange()">
           <span class="spinedit-cnt">
@@ -2092,30 +2089,28 @@ ${ dashboard.layout_skeleton(suffix='search') }
           </span>
         </div>
       <!-- /ko -->
-        <!-- /ko -->
-        
-
-    <!-- ko if: canRange() -->
-    <div class="facet-field-cnt">
-      <span class="facet-field-label facet-field-label-fixed-width">${ _('Type') }</span>
-      <a href="javascript: void(0)" title="${ _('Toggle how to group the values') }" data-bind="click: $root.collection.toggleRangeFacet2">
-        <i class="fa" data-bind="css: { 'fa-arrows-h': type() == 'range', 'fa-circle': type() == 'field', 'fa-level-up': type() == 'range-up' }, attr: { title: type() == 'field' ? 'Range' : type() == 'range-up' ? 'Range and up' : 'Term' }"></i>
-        <span data-bind="visible: type() == 'range'">${_('range')}</span>
-        <span data-bind="visible: type() == 'range-up'">${_('range & up')}</span>
-        <span data-bind="visible: type() == 'field'">${_('field')}</span>
-      </a>
-    </div>
-  
-      <!-- ko ifnot: isDate() -->
-        <div class="slider-cnt" data-bind="slider: {start: min, end: max, gap: initial_gap, min: initial_start, max: initial_end, properties: $data, labels: SLIDER_LABELS}"></div>
-      <!-- /ko -->
-      <!-- ko if: isDate() && $root.collection.timeFilter && $root.collection.timeFilter.field && $root.collection.timeFilter.field() != field() -->
-        <div data-bind="daterangepicker: {start: start, end: end, gap: initial_gap, relatedgap: gap, min: min, max: max}"></div>
       <!-- /ko -->
-        <!-- /ko -->
-    </div>
 
-    <!-- /ko -->  
+      <!-- ko if: canRange() -->
+        <div class="facet-field-cnt">
+          <span class="facet-field-label facet-field-label-fixed-width">${ _('Type') }</span>
+          <a href="javascript: void(0)" title="${ _('Toggle how to group the values') }" data-bind="click: $root.collection.toggleRangeFacet2">
+            <i class="fa" data-bind="css: { 'fa-arrows-h': type() == 'range', 'fa-circle': type() == 'field', 'fa-level-up': type() == 'range-up' }, attr: { title: type() == 'field' ? 'Range' : type() == 'range-up' ? 'Range and up' : 'Term' }"></i>
+            <span data-bind="visible: type() == 'range'">${_('range')}</span>
+            <span data-bind="visible: type() == 'range-up'">${_('range & up')}</span>
+            <span data-bind="visible: type() == 'field'">${_('field')}</span>
+          </a>
+        </div>
+
+        <!-- ko ifnot: isDate() -->
+          <div class="slider-cnt" data-bind="slider: {start: min, end: max, gap: initial_gap, min: initial_start, max: initial_end, properties: $data, labels: SLIDER_LABELS}"></div>
+        <!-- /ko -->
+        <!-- ko if: isDate() && $root.collection.timeFilter && $root.collection.timeFilter.field && $root.collection.timeFilter.field() != field() -->
+          <div data-bind="daterangepicker: {start: start, end: end, gap: initial_gap, relatedgap: gap, min: min, max: max}"></div>
+        <!-- /ko -->
+        <!-- /ko -->
+      </div>
+    <!-- /ko -->
 
     <!-- ko if: !$root.isEditing() -->
     <div class="content" style="border: 1px solid #d8d8d8;">
@@ -2125,8 +2120,6 @@ ${ dashboard.layout_skeleton(suffix='search') }
       <!-- /ko -->
     </div>
     <!-- /ko -->
-
-
 </script>
 
 

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

@@ -162,7 +162,7 @@ def collections_create(request):
         table = request.POST.get('table')
         columns = [field['name'] for field in collection.get('fields', [])]
 
-        searcher.update_data_from_hive(db, collection.get('name'), database, table, columns) # No up to date
+        searcher.update_data_from_hive(db, collection.get('name'), database, table, columns) # Not up to date
 
       response['status'] = 0
       response['message'] = _('Collection created!')

+ 3 - 41
desktop/libs/libsolr/src/libsolr/api.py

@@ -143,45 +143,6 @@ class SolrApi(object):
               ('facet.field', '{!key=%(key)s ex=%(id)s f.%(field)s.facet.limit=%(limit)s f.%(field)s.facet.mincount=%(mincount)s}%(field)s' % keys),
           )
         elif facet['type'] == 'nested':
-#           sort = {'count': facet['properties']['sort']}
-#           for i, agg in enumerate(self._get_dimension_aggregates(facet['properties']['facets'])):
-#             if agg['sort'] != 'default':
-#               agg_function = self._get_aggregate_function(agg)
-#               sort = {'agg_%02d_%02d:%s' % (1, i, agg_function): agg['sort']}
-# 
-#           if sort.get('count') == 'default':
-#             sort['count'] = 'desc'
-#           _f = {
-#               'field': facet['field'],
-#               'limit': int(facet['properties'].get('limit', 10)) + (1 if facet['widgetType'] == 'text-facet-widget' else 0),
-#               'mincount': int(facet['properties']['mincount']),
-#               'sort': sort,
-#           }
-# 
-
-# 
-#           if 'start' in facet['properties'] and not facet['properties'].get('type') == 'field':
-#             _f.update({
-#                 'type': 'range',
-#                 'start': facet['properties']['start'],
-#                 'end': facet['properties']['end'],
-#                 'gap': facet['properties']['gap'],
-#             })
-#             if timeFilter and timeFilter['time_field'] == facet['field'] and (facet['id'] not in timeFilter['time_filter_overrides'] or facet['widgetType'] != 'bucket-widget'):
-#               _f.update(self._get_time_filter_query(timeFilter, facet))
-#           else:
-#             _f.update({
-#                 'type': 'terms',
-#                 'field': facet['field'],
-#                 'excludeTags': facet['id'],
-#                 'offset': 0,
-#                 'numBuckets': True,
-#                 'allBuckets': True,
-#                 #'prefix': '' # Forbidden on numeric fields
-#             })
-#             if facet['properties']['canRange'] and not facet['properties']['isDate']:
-#               del _f['mincount'] # Numeric fields do not support
-
           _f = {}
           if facet['properties']['facets']:
             self._n_facet_dimension(facet, _f, facet['properties']['facets'], 1, timeFilter)
@@ -196,9 +157,9 @@ class SolrApi(object):
               if agg['sort'] != 'default':
                 agg_function = self._get_aggregate_function(agg)
                 sort = {'agg_%02d_%02d:%s' % (1, i, agg_function): agg['sort']}
-   
+
             if sort.get('count') == 'default':
-              sort['count'] = 'desc'            
+              sort['count'] = 'desc'
             dim_key = [key for key in _f['facet'].keys() if 'dim' in key][0]
             _f['facet'][dim_key].update({
                   'excludeTags': facet['id'],
@@ -309,6 +270,7 @@ class SolrApi(object):
             'end': facet['end'],
             'gap': facet['gap']
         })
+# Disabled currently
 #         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))