瀏覽代碼

HUE-7503 [dashboard] Add sorting to Nth dimension

Romain Rigaux 8 年之前
父節點
當前提交
92e40ec

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

@@ -367,7 +367,7 @@ def _create_facet(collection, user, facet_id, facet_label, facet_field, widget_t
     'canRange': False,
     'stacked': False,
     'limit': 10,
-    'mincount': 0,
+    'mincount': 1,
     'isDate': False,
     'aggregate': {'function': 'count', 'formula': '', 'generated_formula': '', 'percentiles': [{'value': 50}]}
   }
@@ -378,7 +378,7 @@ def _create_facet(collection, user, facet_id, facet_label, facet_field, widget_t
     facet_type = 'nested'
     properties['facets'] = []
     properties['domain'] = {'blockParent': [], 'blockChildren': []}
-    properties['facets_form'] = {'field': '', 'mincount': 1, 'limit': 10, 'aggregate': {'function': 'unique', 'formula': '', 'generated_formula': '', 'percentiles': [{'value': 50}]}}
+    properties['facets_form'] = {'field': '', 'mincount': 1, 'limit': 5, 'sort': 'desc', 'aggregate': {'function': 'unique', 'formula': '', 'generated_formula': '', 'percentiles': [{'value': 50}]}}
     properties['scope'] = 'world'
     properties['limit'] = 100
   else:
@@ -403,7 +403,7 @@ def _create_facet(collection, user, facet_id, facet_label, facet_field, widget_t
       else:
         facet_type = 'nested'
 
-      properties['facets_form'] = {'field': '', 'mincount': 1, 'limit': 10, 'aggregate': {'function': 'unique', 'formula': '', 'generated_formula': '', 'percentiles': [{'value': 50}]}}
+      properties['facets_form'] = {'field': '', 'mincount': 1, 'limit': 5, 'sort': 'desc', 'aggregate': {'function': 'unique', 'formula': '', 'generated_formula': '', 'percentiles': [{'value': 50}]}}
       properties['facets'] = []
       properties['domain'] = {'blockParent': [], 'blockChildren': []}
 

+ 9 - 5
desktop/libs/dashboard/src/dashboard/static/dashboard/js/search.ko.js

@@ -976,7 +976,8 @@ var Collection = function (vm, collection) {
       'field': ko.mapping.toJS(facet.properties.facets_form.field),
       '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)
+      'aggregate': ko.mapping.toJS(facet.properties.facets_form.aggregate),
+      'sort': ko.mapping.toJS(facet.properties.facets_form.sort)
     });
     pivot.aggregate.metrics = ko.computed(function() {
       var _field = self.getTemplateField(pivot.field(), self.template.fieldsAttributes());
@@ -986,6 +987,7 @@ var Collection = function (vm, collection) {
     facet.properties.facets_form.field(null);
     facet.properties.facets_form.limit(5);
     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('');
@@ -1357,13 +1359,15 @@ var Collection = function (vm, collection) {
   };
 
   self.toggleSortFacet2 = function (facet_field, event) {
-    if (facet_field.properties.sort() == 'desc') {
-      facet_field.properties.sort('asc');
+    var sortField = facet_field.properties ? facet_field.properties.sort : facet_field.sort;
+
+    if (sortField() == 'desc') {
+      sortField('asc');
     } else {
-      facet_field.properties.sort('desc');
+      sortField('desc');
     }
 
-    if (facet_field.properties.type && facet_field.properties.type() == 'range-up') {
+    if (facet_field.properties && facet_field.properties.type && facet_field.properties.type() == 'range-up') {
       vm.query.removeFilter(ko.mapping.fromJS({'id': facet_field.id})); // Reset filter query
     }
 

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

@@ -2097,6 +2097,15 @@ ${ dashboard.layout_skeleton(suffix='search') }
       <input data-bind="value: generated_formula" type="hidden"></input>
 
       <!-- ko if: $data.function() != 'field' && $data.metrics -->
+      <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($parent); }">
+          <i class="fa" data-bind="css: { 'fa-caret-down': $parent.sort() == 'desc', 'fa-caret-up': $parent.sort() == 'asc' }"></i>
+          <span data-bind="visible: $parent.sort() == 'desc'">${_('descending')}</span>
+          <span data-bind="visible: $parent.sort() == 'asc'">${_('ascending')}</span>
+        </a>
+      </div>
+
         <div class="facet-field-cnt">
           <span class="spinedit-cnt">
             <span class="facet-field-label">
@@ -2105,8 +2114,8 @@ ${ dashboard.layout_skeleton(suffix='search') }
             <input type="text" class="input-medium" data-bind="spinedit: $parent.limit"/>
           </span>
         </div>
-  
-        <div class="facet-field-cnt">
+
+        <div class="facet-field-cnt" data-bind="visible: $data.function() == 'count'">
           <span class="spinedit-cnt">
             <span class="facet-field-label">
               ${ _('Min Count') }
@@ -2114,8 +2123,6 @@ ${ dashboard.layout_skeleton(suffix='search') }
             <input type="text" class="input-medium" data-bind="spinedit: $parent.mincount"/>
           </span>
         </div>
-  
-        ${ _('Sorting') }
       <!-- /ko -->
     </div>
     <!-- /ko -->

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

@@ -267,6 +267,7 @@ class SolrApi(object):
           'mincount': int(facet['mincount']),
           'numBuckets': True,
           'allBuckets': True,
+          'sort': {'count': facet['sort']}
           #'prefix': '' # Forbidden on numeric fields
       }
       if widget['widgetType'] == 'tree2-widget' and facets[-1]['aggregate']['function'] != 'count':