Explorar el Código

[search] Add toggle field list visibility in grid layout

Works in live and edit modes
Romain Rigaux hace 11 años
padre
commit
40d6aa8

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

@@ -273,6 +273,7 @@ class Collection(models.Model):
         <br/>
       </div>""" % ' '.join(['{{%s}}' % field for field in fields]), 
       "isGridLayout": True,
+      "showFieldList": True,
       "fields": fields
     }
     
@@ -310,7 +311,9 @@ class Collection(models.Model):
     # Backward compatibility
     if 'autocomplete' not in properties_python:
       properties_python['autocomplete'] = False
-    # TODO: Should convert old format here
+    # TODO: Should convert old Hue 3.5 format here
+    if 'showFieldList' not in properties_python['collection']['template']:
+      properties_python['collection']['template']['showFieldList'] = True
     return properties_python
 
   def update_properties(self, post_data):

+ 15 - 4
apps/search/src/search/templates/search2.mako

@@ -333,10 +333,21 @@ ${ commonheader(_('Search'), "search", user, "60px") | n,unicode }
   </div>
 
   <!-- ko if: $root.collection.template.isGridLayout() -->
-  <div data-bind="visible: $root.isEditing" style="float:left; margin-right: 10px" >
-    <span>
-      ## Todo add a toggle to show fields or not in non edit mode
-      <strong>${ _('Fields') }</strong>
+  <div style="float:left; margin-right: 10px" >
+    <span data-bind="visible: ! $root.collection.template.showFieldList()">
+      <a href="javascript: void(0)" class="btn"
+        data-bind="click: $root.collection.template.showFieldList(true)">
+        <i class="fa fa-chevron-right"></i>
+      </a>
+    </span>
+  </div>
+  <div data-bind="visible: $root.isEditing() || $root.collection.template.showFieldList()" style="float:left; margin-right: 10px" >
+    <span data-bind="visible: $root.collection.template.showFieldList()">
+      <a href="javascript: void(0)" class="btn"
+        data-bind="click: $root.collection.template.showFieldList(false)">
+        <i class="fa fa-chevron-left"></i>
+      </a>
+      <strong>${ _('Fields') }</strong>      
       &nbsp;
       <a href="javascript: void(0)" class="btn"
         data-bind="click: toggleGridFieldsSelection, css: { 'btn-inverse': $root.collection.template.fields().length > 0 }">

+ 1 - 1
apps/search/static/js/search.ko.js

@@ -243,7 +243,7 @@ var SearchViewModel = function (collection_json, query_json) {
   self.selectedFacet = ko.observable();
 
   self.previewColumns = ko.observable("");
-  self.columns = ko.observableArray([]); // load back? 
+  self.columns = ko.observableArray([]); // aka 'layout'
   self.isEditing = ko.observable(false);
   self.draggableFacet = ko.observable(new Widget(12, "Facet", "facet-widget"));
   self.draggableResultset = ko.observable(new Widget(12, "Results", "resultset-widget"));