浏览代码

HUE-5417 [search] Support result sorting for nested widgets

Romain Rigaux 9 年之前
父节点
当前提交
d7094ee

+ 9 - 7
apps/search/src/search/static/search/js/search.ko.js

@@ -1010,9 +1010,9 @@ var Collection = function (vm, collection) {
     return hasData;
   });
 
-  self.getTemplateField = function (name) {
+  self.getTemplateField = function (name, fields) {
     var _field = null;
-    $.each(self.template.fields(), function (index, field) {
+    $.each(fields, function (index, field) {
       if (field.name() == name) {
         _field = field;
         return false;
@@ -1293,14 +1293,16 @@ var Collection = function (vm, collection) {
     vm.search();
   }
 
-  self.translateSelectedField = function (index, direction) {
-    var array = self.template.fieldsSelected();
-    vm.resultsHash = '';
+  self.translateSelectedField = function (index, direction, template) {
+    var array = template.fieldsSelected();
+    if (self.template == template) {
+      vm.resultsHash = '';
+    }
 
     if (direction == 'left') {
-      self.template.fieldsSelected.splice(index - 1, 2, array[index], array[index - 1]);
+      template.fieldsSelected.splice(index - 1, 2, array[index], array[index - 1]);
     } else {
-      self.template.fieldsSelected.splice(index, 2, array[index + 1], array[index]);
+      template.fieldsSelected.splice(index, 2, array[index + 1], array[index]);
     }
   };
 

+ 18 - 15
apps/search/src/search/templates/common_search.mako

@@ -1064,8 +1064,10 @@ ${ dashboard.layout_skeleton() }
         <div id="result-main" style="overflow-x: auto">
           <table id="result-container" data-bind="visible: $root.hasRetrievedResults()" style="margin-top: 0; width: 100%">
             <thead>
-              <tr class="result-sorting" data-bind="visible: $root.collection.template.fieldsSelected().length > 0, template: {name: 'result-sorting'}">
+              <!-- ko if: $root.collection.template.fieldsSelected().length > 0 -->
+              <tr class="result-sorting" data-bind="template: {name: 'result-sorting', data: $root.collection}">
               </tr>
+              <!-- /ko -->
               <tr data-bind="visible: $root.collection.template.fieldsSelected().length == 0">
                 <th style="width: 18px">&nbsp;</th>
                 <th>${ _('Document') }</th>
@@ -1257,7 +1259,7 @@ ${ dashboard.layout_skeleton() }
       <div class="widget-section widget-settings-section" style="display: none">
         <div style="overflow-x: scroll; min-height: 40px">
           <table>
-            <tr class="result-sorting" data-bind="template: {name: 'result-sorting'}">
+            <tr class="result-sorting" data-bind="template: {name: 'result-sorting', data: $root.collection}">
             </tr>
           </table>
         </div>
@@ -1382,22 +1384,23 @@ ${ dashboard.layout_skeleton() }
   <!-- /ko -->
 </script>
 
+
 <script type="text/html" id="result-sorting">
-<th style="width: 18px">&nbsp;</th>
-<!-- ko foreach: $root.collection.template.fieldsSelected -->
-<th data-bind="with: $root.collection.getTemplateField($data)" style="white-space: nowrap">
-  <span data-bind="text: name, click: $root.collection.toggleSortColumnGridLayout" title="${ _('Click to sort') }"></span>
-  <i class="fa fa-sort inactive-action margin-right-10 margin-left-5" data-bind="click: $root.collection.toggleSortColumnGridLayout, css: { 'blue': sort.direction() != null, 'fa-sort-down': sort.direction() == 'desc', 'fa-sort-up': sort.direction() == 'asc' }" title="${ _('Click to sort') }"></i>
-  <!-- ko if: $root.isEditing -->
-    <!-- ko if: $index() > 0 -->
-    <i class="fa fa-caret-left inactive-action" data-bind="click: function(){ $root.collection.translateSelectedField($index(), 'left'); }" title="${ _('Move to the left') }"></i>
-    <!-- /ko -->
-    <!-- ko if: $index() < $root.collection.template.fields().length - 1 -->
-    <i class="fa fa-caret-right inactive-action" data-bind="click: function(){ $root.collection.translateSelectedField($index(), 'right'); }" title="${ _('Move to the right') }"></i>
+  <th style="width: 18px">&nbsp;</th>
+  <!-- ko foreach: template.fieldsSelected -->
+  <th data-bind="with: $root.collection.getTemplateField($data, $parent.template.fields())" style="white-space: nowrap">
+    <span data-bind="text: name, click: $root.collection.toggleSortColumnGridLayout" title="${ _('Click to sort') }"></span>
+    <i class="fa fa-sort inactive-action margin-right-10 margin-left-5" data-bind="click: $root.collection.toggleSortColumnGridLayout, css: { 'blue': sort.direction() != null, 'fa-sort-down': sort.direction() == 'desc', 'fa-sort-up': sort.direction() == 'asc' }" title="${ _('Click to sort') }"></i>
+    <!-- ko if: $root.isEditing -->
+      <!-- ko if: $index() > 0 -->
+      <i class="fa fa-caret-left inactive-action" data-bind="click: function(){ $root.collection.translateSelectedField($index(), 'left', $parents[1].template); }" title="${ _('Move to the left') }"></i>
+      <!-- /ko -->
+      <!-- ko if: $index() < $parents[1].template.fields().length - 1 -->
+      <i class="fa fa-caret-right inactive-action" data-bind="click: function(){ $root.collection.translateSelectedField($index(), 'right', $parents[1].template); }" title="${ _('Move to the right') }"></i>
+      <!-- /ko -->
     <!-- /ko -->
+  </th>
   <!-- /ko -->
-</th>
-<!-- /ko -->
 </script>
 
 

+ 1 - 1
apps/search/src/search/views.py

@@ -638,7 +638,7 @@ def _create_facet(collection, user, facet_id, facet_label, facet_field, widget_t
     'properties': properties,
     # Hue 4+
     'template': {
-        "showFieldList": False,
+        "showFieldList": True,
         "showGrid": False,
         "showChart": True,
         "chartSettings" : { # Use own?