Browse Source

HUE-2173 [dashboard] Show sorting and facet limit when it makes sense

Romain Rigaux 8 years ago
parent
commit
5c58297728

+ 5 - 0
desktop/libs/dashboard/src/dashboard/api.py

@@ -398,6 +398,11 @@ def _create_facet(collection, user, facet_id, facet_label, facet_field, widget_t
         properties['type'] = facet_type
 
       properties['facets_form'] = NESTED_FACET_FORM
+      # Not supported on dim 2 currently
+      properties['facets_form']['type'] = 'field'
+      properties['facets_form']['canRange'] = False
+      properties['facets_form']['isFacetForm'] = True
+
       facet = NESTED_FACET_FORM.copy()
       facet['field'] = facet_field
       facet['limit'] = 10

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

@@ -359,7 +359,6 @@ def range_pair2(facet_field, cat, fq_filter, iterable, end, facet):
   # e.g. counts":["0",17430,"1000",1949,"2000",671,"3000",404,"4000",243,"5000",165],"gap":1000,"start":0,"end":6000}
   pairs = []
   selected_values = [f['value'] for f in fq_filter]
-  print facet
   is_single_unit_gap = re.match('^[\+\-]?1[A-Za-z]*$', str(facet['gap'])) is not None
   is_up = facet['sort'] == 'asc'
 
@@ -507,7 +506,7 @@ def augment_solr_response(response, collection, query):
         rows = []
 
         facet_one = collection_facet['properties']['facets'][0]
-        
+
         # Number or Date range
         if facet_one['canRange'] and not facet_one['type'] == 'field':
           dimension = 3 if facet_one['isDate'] else 1

+ 3 - 2
desktop/libs/dashboard/src/dashboard/static/dashboard/js/search.ko.js

@@ -750,7 +750,7 @@ var Collection = function (vm, collection) {
 
       facet.fields = facet.template.fieldsAttributes;
 
-      facet.template.fields = ko.computed(function () {  // Dup of template.fields
+      facet.template.fields = ko.computed(function () { // Dup of template.fields
         var _fields = [];
         $.each(facet.template.fieldsAttributes(), function (index, field) {
           var position = facet.template.fieldsSelected.indexOf(field.name());
@@ -1004,7 +1004,8 @@ var Collection = function (vm, collection) {
       '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'),
-      'canRange': false // No supported on dim 2 currently
+      'canRange': ko.mapping.toJS(facet.properties.facets_form.canRange),
+      'type': ko.mapping.toJS(facet.properties.facets_form.type)
     });
     pivot.aggregate.metrics = ko.computed(function() {
       var _field = self.getTemplateField(pivot.field(), self.template.fieldsAttributes());

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

@@ -1975,8 +1975,8 @@ ${ dashboard.layout_skeleton(suffix='search') }
   <div class="row-fluid" data-bind="with: $root.getFacetFromQuery(id())">
     <div data-bind="with: $root.collection.getFacetById($parent.id())">
       <span data-bind="template: { name: 'facet-toggle2' }"></span>
-      ## TODO: Range if numeric
     </div>
+
     <span class="big-counter" data-bind="textSqueezer: counts"></span>
   </div>
   <!-- /ko -->
@@ -1988,7 +1988,7 @@ ${ dashboard.layout_skeleton(suffix='search') }
     <!-- ko if: $root.isEditing -->
     <div>
       <!-- 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>
+      <select data-bind="options: metrics, optionsText: 'label', optionsValue: 'value', value: $data.function, disable: ($parents[1].widgetType() == 'text-facet-widget' && $index() == 0 && !$parent.isFacetForm" class="input-small"></select>
 
       <!-- ko if: $data.function() == 'percentile' -->
         <!-- ko foreach: percentiles() -->
@@ -2009,7 +2009,7 @@ ${ dashboard.layout_skeleton(suffix='search') }
 
       <div data-bind="component: { name: 'hue-simple-ace-editor', params: { value: plain_formula, parsedValue: formula, autocomplete: { type: 'solrFormula', support: { fields: $root.collection.template.fieldsAttributes } }, singleLine: true } }, visible: $parent.field() == 'formula'"></div>
 
-      <!-- ko if: $data.function() != 'field' && $parents[1].widgetType() != 'hit-widget' -->
+      <!-- ko if: $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); }">
@@ -2040,6 +2040,7 @@ ${ dashboard.layout_skeleton(suffix='search') }
       <!-- /ko -->
       <!-- /ko -->
 
+      <!-- ko if: $parent.widgetType() != 'hit-widget' && type() != 'field' -->
       <!-- ko if: canRange() -->
         <div class="facet-field-cnt">
           <span class="facet-field-label facet-field-label-fixed-width">${ _('Type') }</span>
@@ -2057,6 +2058,8 @@ ${ dashboard.layout_skeleton(suffix='search') }
         <!-- 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 -->
         <!-- /ko -->
       </div>
     <!-- /ko -->
@@ -2519,7 +2522,7 @@ ${ dashboard.layout_skeleton(suffix='search') }
             <legend><i class="fa fa-bookmark-o"></i> ${ _('Query definitions') }
               <div class="input-append" style="margin-left: 30px; margin-top: 4px">
                 <input id="newqname" type="text" class="input-xxlarge" data-bind="textInput: $root.collection.newQDefinitionName, valueUpdate:'afterkeydown', tagsNotAllowed" style="margin-bottom: 0" placeholder="${ _('Add current query as...') }" />
-                <a title="${ _('Click on this button to add the currenty query as a new definition') }" class="btn plus-btn" data-bind="click: $root.collection.addQDefinition, css:{'disabled': $.trim($root.collection.newQDefinitionName()) == ''}" style="margin-top: 1px">
+                <a title="${ _('Click on this button to add the currenty query as a new definition') }" class="btn plus-btn" data-bind="click: $root.collection.addQDefinition, css: {'disabled': $.trim($root.collection.newQDefinitionName()) == ''}" style="margin-top: 1px">
                   <i class="fa fa-plus"></i>
                 </a>
               </div>