Ver Fonte

HUE-5417 [search] Add field list to the grid facet

Romain Rigaux há 9 anos atrás
pai
commit
dad32c9dca

+ 2 - 1
apps/search/src/search/models.py

@@ -893,7 +893,8 @@ def augment_solr_response(response, collection, query):
           'extraSeries': extraSeries,
           'dimension': dimension,
           'response': {'response': {'start': 0, 'numFound': len(rows)}},
-          'docs': [dict(zip(cols, row)) for row in rows]
+          'docs': [dict(zip(cols, row)) for row in rows],
+          'fieldsAttributes': [Collection2._make_gridlayout_header_field({'name': col, 'type': 'string'}) for col in cols]
         }
 
         normalized_facets.append(facet)

+ 17 - 2
apps/search/src/search/static/search/js/search.ko.js

@@ -790,6 +790,16 @@ var Collection = function (vm, collection) {
 
             return _fields;
           });
+          facet.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());
+        	      if (position != -1) {
+        	        _fields[position] = field;
+        	      }
+        	    });
+        	    return _fields;
+        	  });
           self.facets.push(facet);
           vm.search();
         } else {
@@ -845,11 +855,11 @@ var Collection = function (vm, collection) {
       'mincount': ko.mapping.toJS(facet.properties.facets_form.mincount),
       'aggregate': ko.mapping.toJS(facet.properties.facets_form.aggregate),
     });
-      
+
       facet.properties.facets_form.field(null);
       facet.properties.facets_form.limit(5);
       facet.properties.facets_form.mincount(1);
-      
+
       facet.properties.facets_form.aggregate.function('count');
       facet.properties.facets_form.aggregate.ops.removeAll();
       facet.properties.facets_form.aggregate.percentiles(ko.mapping.fromJS([{'value': 50}]));
@@ -1625,6 +1635,11 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
                     });
                     facet.results(_docs);
                     facet.response(new_facet.response);
+                    // Update template
+                    var _facet_model = self.collection.getFacetById(new_facet.id);
+                    $.each(new_facet.fieldsAttributes, function(index, item) {
+                      _facet_model.template.fieldsAttributes.push(ko.mapping.fromJS(item));
+                    });
                   }
                   facet.label(new_facet.label);
                   facet.field(new_facet.field);

+ 2 - 2
apps/search/src/search/templates/common_search.mako

@@ -1704,8 +1704,8 @@ ${ dashboard.layout_skeleton() }
         </div>
         <div class="fields-list" data-bind="foreach: template.filteredAttributeFields">
           <div style="margin-bottom: 3px; white-space: nowrap; position:relative">
-            <input type="checkbox" data-bind="checkedValue: name, checked: template.fieldsSelected" style="margin: 0" />
-            <div data-bind="text: name, css:{'field-selector': true, 'hoverable': template.fieldsSelected.indexOf(name()) > -1}, click: highlightColumn" style="margin-right:10px"></div>
+            <input type="checkbox" data-bind="checkedValue: name, checked: $parent.template.fieldsSelected" style="margin: 0" />
+            <div data-bind="text: name, css:{'field-selector': true, 'hoverable': $parent.template.fieldsSelected.indexOf(name()) > -1}, click: highlightColumn" style="margin-right:10px"></div>
             <i class="fa fa-question-circle muted pointer analysis" data-bind="click: function(data, e) { $parent.fieldAnalysesName(name()); $parent.showFieldAnalysis(data, e); }, attr: {'title': '${ _ko('Analyze ') } ' + name() + ' (' + type() + ')'}" style="position:absolute; left: 168px; background-color: #FFF"></i>
           </div>
         </div>