Pārlūkot izejas kodu

[search] Fetch new fields when creating a collection dashboard

Romain Rigaux 11 gadi atpakaļ
vecāks
revīzija
0323612387

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

@@ -320,7 +320,7 @@ class Collection(models.Model):
     FACETS = []
 
     return {
-      'id': self.id, 'name': self.name, 'label': self.label,
+      'id': self.id, 'name': self.name, 'label': self.label, 'enabled': self.enabled,
       'template': TEMPLATE, 'facets': FACETS, 
       'fields': fields, 'idField': id_field, 
     }          

+ 0 - 1
apps/search/src/search/search_controller.py

@@ -16,7 +16,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import json
 import logging
 
 from desktop.lib.exceptions_renderable import PopupException

+ 6 - 4
apps/search/src/search/templates/admin_collections.mako

@@ -28,9 +28,12 @@ ${ commonheader(_('Search'), "search", user, "29px") | n,unicode }
 
 <div class="search-bar" style="height: 30px">
     <div class="pull-right" style="margin-top: 4px; margin-right: 20px">
-      <a href="${ url('search:index') }"><i class="fa fa-share"></i> ${ _('Search page') }</a>
+    <a class="btn" href="${ url('search:new_search') }"><i class="fa fa-file-o"></i> ${ _('New dasboard') }</a>
+    <button type="button" class="btn importBtn" data-bind="visible: collections().length > 0 && !isLoading()">
+      <i class="fa fa-plus-circle"></i> ${ _('Import Index') }
+      </button>
     </div>
-  <h4>${_('Collection Manager')}</h4>
+  <h4>${_('Dashboards')}</h4>
 </div>
 
 
@@ -38,11 +41,10 @@ ${ commonheader(_('Search'), "search", user, "29px") | n,unicode }
   <div class="card">
   <%actionbar:render>
     <%def name="search()">
-      <input type="text" placeholder="${_('Filter collections by name...')}" class="input-xlarge search-query" id="filterInput" data-bind="visible: collections().length > 0 && !isLoading()">
+      <input type="text" placeholder="${_('Filter dashboards by name...')}" class="input-xlarge search-query" id="filterInput" data-bind="visible: collections().length > 0 && !isLoading()">
     </%def>
 
     <%def name="creation()">
-      <button type="button" class="btn importBtn" data-bind="visible: collections().length > 0 && !isLoading()"><i class="fa fa-plus-circle"></i> ${ _('Import') }</button>
     </%def>
   </%actionbar:render>
 

+ 18 - 20
apps/search/src/search/templates/search2.mako

@@ -45,8 +45,14 @@ ${ commonheader(_('Search'), "search", user, "80px") | n,unicode }
     <strong>${_("Search")}</strong>
     <div class="input-append">
       <div class="selectMask">
-        <span class="current-collection" data-bind="text: collection.label"></span>
-        ## click: show also collection list + edit label box        
+        <span
+            data-bind="editable: collection.label, editableOptions: {enabled: $root.isEditing(), placement: 'right'}">
+        </span>
+        ##<i class="fa fa-edit" data-bind="visible: $root.isEditing() && ! $root.changeCollection(), click: function(){$root.changeCollection(true);}"></i>
+        <!-- ko if: $root.isEditing() && $root.changeCollection() -->
+        <select data-bind="options: $root.initial.collections, value: $root.collection.name">
+        </select>        
+        <!-- /ko -->
       </div>
 
       <span data-bind="foreach: query.qs">
@@ -97,8 +103,7 @@ ${ commonheader(_('Search'), "search", user, "80px") | n,unicode }
                     options: {'start': function(event, ui){lastWindowScrollPosition = $(window).scrollTop();$('.card-body').slideUp('fast');},
                               'stop': function(event, ui){$('.card-body').slideDown('fast'); $root.collection.template.isGridLayout(true); }}}"
          title="${_('Grid Results')}" rel="tooltip" data-placement="top">
-         <a data-bind="attr: {href: $root.availableDraggableResultset()},
-                       style: { cursor: $root.availableDraggableResultset() ? 'move' : 'default' }">
+         <a data-bind="style: { cursor: $root.availableDraggableResultset() ? 'move' : 'default' }">
                        <i class="fa fa-table"></i>
          </a>
     </div>
@@ -108,8 +113,7 @@ ${ commonheader(_('Search'), "search", user, "80px") | n,unicode }
                     options: {'start': function(event, ui){lastWindowScrollPosition = $(window).scrollTop();$('.card-body').slideUp('fast');},
                               'stop': function(event, ui){$('.card-body').slideDown('fast', function(){$(window).scrollTop(lastWindowScrollPosition)}); $root.collection.template.isGridLayout(false); }}}"
          title="${_('HTML Results')}" rel="tooltip" data-placement="top">
-         <a data-bind="attr: {href: $root.availableDraggableResultset()}, 
-                       style: { cursor: $root.availableDraggableResultset() ? 'move' : 'default' }">
+         <a data-bind="style: { cursor: $root.availableDraggableResultset() ? 'move' : 'default' }">
                        <i class="fa fa-code"></i>
          </a>
     </div>
@@ -118,8 +122,7 @@ ${ commonheader(_('Search'), "search", user, "80px") | n,unicode }
                     options: {'start': function(event, ui){lastWindowScrollPosition = $(window).scrollTop();$('.card-body').slideUp('fast');},
                               'stop': function(event, ui){$('.card-body').slideDown('fast', function(){$(window).scrollTop(lastWindowScrollPosition)});}}}"
          title="${_('Text Facet')}" rel="tooltip" data-placement="top">
-         <a data-bind="attr: {href: $root.availableDraggableChart()}, 
-                       style: { cursor: $root.availableDraggableChart() ? 'move' : 'default' }">
+         <a data-bind="style: { cursor: $root.availableDraggableChart() ? 'move' : 'default' }">
                        <i class="fa fa-sort-amount-asc"></i>
          </a>
     </div>
@@ -128,8 +131,7 @@ ${ commonheader(_('Search'), "search", user, "80px") | n,unicode }
                     options: {'start': function(event, ui){lastWindowScrollPosition = $(window).scrollTop();$('.card-body').slideUp('fast');},
                               'stop': function(event, ui){$('.card-body').slideDown('fast', function(){$(window).scrollTop(lastWindowScrollPosition)});}}}"
          title="${_('Pie Chart')}" rel="tooltip" data-placement="top">
-         <a data-bind="attr: {href: $root.availableDraggableChart()}, 
-                       style: { cursor: $root.availableDraggableChart() ? 'move' : 'default' }">
+         <a data-bind="style: { cursor: $root.availableDraggableChart() ? 'move' : 'default' }">
                        <i class="hcha hcha-pie-chart"></i>
          </a>
     </div>
@@ -139,8 +141,7 @@ ${ commonheader(_('Search'), "search", user, "80px") | n,unicode }
                     options: {'start': function(event, ui){lastWindowScrollPosition = $(window).scrollTop();$('.card-body').slideUp('fast');},
                               'stop': function(event, ui){$('.card-body').slideDown('fast', function(){$(window).scrollTop(lastWindowScrollPosition)});}}}"
          title="${_('Bar Chart')}" rel="tooltip" data-placement="top">
-         <a data-bind="attr: {href: $root.availableDraggableChart()}, 
-                       style: { cursor: $root.availableDraggableChart() ? 'move' : 'default' }">
+         <a data-bind="style: { cursor: $root.availableDraggableChart() ? 'move' : 'default' }">
                        <i class="hcha hcha-bar-chart"></i>
          </a>
     </div>
@@ -149,8 +150,7 @@ ${ commonheader(_('Search'), "search", user, "80px") | n,unicode }
                     options: {'start': function(event, ui){lastWindowScrollPosition = $(window).scrollTop();$('.card-body').slideUp('fast');},
                               'stop': function(event, ui){$('.card-body').slideDown('fast', function(){$(window).scrollTop(lastWindowScrollPosition)});}}}"
          title="${_('Line')}" rel="tooltip" data-placement="top">
-         <a data-bind="attr: {href: $root.availableDraggableChart()}, 
-                       style: { cursor: $root.availableDraggableChart() ? 'move' : 'default' }">
+         <a data-bind="style: { cursor: $root.availableDraggableChart() ? 'move' : 'default' }">
                        <i class="hcha hcha-line-chart"></i>
          </a>
     </div>
@@ -159,8 +159,7 @@ ${ commonheader(_('Search'), "search", user, "80px") | n,unicode }
                     options: {'start': function(event, ui){lastWindowScrollPosition = $(window).scrollTop();$('.card-body').slideUp('fast');},
                               'stop': function(event, ui){$('.card-body').slideDown('fast', function(){$(window).scrollTop(lastWindowScrollPosition)});}}}"
          title="${_('Histogram')}" rel="tooltip" data-placement="top">
-         <a data-bind="attr: {href: $root.availableDraggableHistogram()}, 
-                       style: { cursor: $root.availableDraggableHistogram() ? 'move' : 'default' }">
+         <a data-bind="style: { cursor: $root.availableDraggableHistogram() ? 'move' : 'default' }">
                        <i class="hcha hcha-timeline-chart"></i>
          </a>
     </div>
@@ -169,8 +168,7 @@ ${ commonheader(_('Search'), "search", user, "80px") | n,unicode }
                     options: {'start': function(event, ui){lastWindowScrollPosition = $(window).scrollTop();$('.card-body').slideUp('fast');},
                               'stop': function(event, ui){$('.card-body').slideDown('fast', function(){$(window).scrollTop(lastWindowScrollPosition)});}}}"
          title="${_('Filter Bar')}" rel="tooltip" data-placement="top">
-         <a data-bind="attr: {href: $root.availableDraggableFilter()}, 
-                       style: { cursor: $root.availableDraggableFilter() ? 'move' : 'default' }">
+         <a data-bind="style: { cursor: $root.availableDraggableFilter() ? 'move' : 'default' }">
                        <i class="fa fa-filter"></i>
          </a>
     </div>
@@ -179,8 +177,7 @@ ${ commonheader(_('Search'), "search", user, "80px") | n,unicode }
                     options: {'start': function(event, ui){lastWindowScrollPosition = $(window).scrollTop();$('.card-body').slideUp('fast');},
                               'stop': function(event, ui){$('.card-body').slideDown('fast', function(){$(window).scrollTop(lastWindowScrollPosition)});}}}"
          title="${_('Map')}" rel="tooltip" data-placement="top">
-         <a data-bind="attr: {href: $root.availableDraggableChart()}, 
-                       style: { cursor: $root.availableDraggableChart() ? 'move' : 'default' }">
+         <a data-bind="style: { cursor: $root.availableDraggableChart() ? 'move' : 'default' }">
                        <i class="hcha hcha-map-chart"></i>
          </a>
    </div>
@@ -492,6 +489,7 @@ ${ commonheader(_('Search'), "search", user, "80px") | n,unicode }
         <li class="active"><a href="javascript: void(0)" class="widget-editor-pill">${_('Editor')}</a></li>
         <li><a href="javascript: void(0)" class="widget-html-pill">${_('HTML')}</a></li>
         <li><a href="javascript: void(0)" class="widget-css-pill">${_('CSS & JS')}</a></li>
+        <li><a href="javascript: void(0)" class="widget-settings-pill">${_('Properties')}</a></li>
       </ul>
     </div>
 

+ 1 - 0
apps/search/src/search/urls.py

@@ -44,6 +44,7 @@ urlpatterns = patterns('search.views',
   url(r'^get_document$', 'get_document', name='get_document'),
   url(r'^get_range_facet$', 'get_range_facet', name='get_range_facet'),
   url(r'^get_timeline$', 'get_timeline', name='get_timeline'),
+  url(r'^get_collection', 'get_collection', name='get_collection'),
   
   # old
   url(r'^admin/collection/(?P<collection_id>\w+)/schema$', 'admin_collection_schema', name='admin_collection_schema'),

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

@@ -143,7 +143,9 @@ def save(request):
       hue_collection = Collection.objects.create2(name=collection['name'], label=collection['label'])
     hue_collection.update_properties({'collection': collection})
     hue_collection.update_properties({'layout': layout})
-    # Todo update certain atttributes like, label, enabled...
+    hue_collection.name = collection['name']
+    hue_collection.label = collection['label']
+    hue_collection.enable = collection['enabled']
     hue_collection.save()
     response['status'] = 0
     response['id'] = hue_collection.id
@@ -613,6 +615,25 @@ def get_range_facet(request):
   return HttpResponse(json.dumps(result), mimetype="application/json")
 
 
+# TODO security
+def get_collection(request):  
+  result = {'status': -1, 'message': 'Error'}
+
+  try:
+    name = request.POST['name']
+            
+    collection = Collection(name=name, label=name)
+    collection_json = collection.get_c(request.user)
+            
+    result['collection'] = json.loads(collection_json)
+    result['status'] = 0      
+
+  except Exception, e:
+    result['message'] = unicode(str(e), "utf8")
+
+  return HttpResponse(json.dumps(result), mimetype="application/json")
+
+
 def install_examples(request):
   result = {'status': -1, 'message': ''}
 

+ 0 - 1
apps/search/static/css/search.css

@@ -144,7 +144,6 @@
   border-top-right-radius: 0;
   box-shadow: none;
   color: #444444;
-  cursor: pointer;
   display: inline-block;
   font-size: 13px;
   height: 29px;

+ 24 - 7
apps/search/static/js/search.ko.js

@@ -231,7 +231,7 @@ var Query = function (vm, query) {
         }
       } else {
           var facet = self.getFacetFilter(self.selectedMultiq());
-          if (facet && facet.filter().length > 0) { // todo + histogram there?
+          if (facet && facet.filter().length > 0) {
             return 'facet';
           }
       }
@@ -342,6 +342,7 @@ var Collection = function (vm, collection) {
   self.id = collection.id;
   self.name = ko.mapping.fromJS(collection.name);
   self.label = ko.mapping.fromJS(collection.label);
+  self.enabled= ko.mapping.fromJS(collection.enabled);
   self.idField = collection.idField;
   self.template = ko.mapping.fromJS(collection.template);
   self.template.fieldsSelected.subscribe(function () {
@@ -482,6 +483,20 @@ var Collection = function (vm, collection) {
   });
 
 
+  self.updateFields = function() {
+    $.post("/search/get_collection/", {
+        name: self.name()
+	  }, function (data) {
+	    if (data.status == 0) {
+	      self.fields.removeAll();
+	      $.each(data.collection.collection.fields, function(index, field) {
+	    	self.fields.push(ko.mapping.fromJS(field));
+	      });
+	    }
+	}).fail(function (xhr, textStatus, errorThrown) {});
+  };
+  
+  
   self.addDynamicFields = function () { // + Adding merge smartly if schema updated
     $.post("/search/index/" + self.id + "/fields/dynamic", {
       }, function (data) {
@@ -493,7 +508,7 @@ var Collection = function (vm, collection) {
         });
       }
     }).fail(function (xhr, textStatus, errorThrown) {});
-  }
+  };
 
   self.toggleSortColumnGridLayout = function (template_field) {
     if (! template_field.sort.direction()) {
@@ -618,9 +633,6 @@ var NewTemplate = function (vm, initial) {
   var self = this;
 
   self.collections = ko.mapping.fromJS(initial.collections);
-  self.collections.subscribe(function (newValue) {
-    vm.collection.name(newValue);
-  });
   
   self.layout = initial.layout;
 };
@@ -639,6 +651,9 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
   if (initial_json.collections) {
     self.collection.name.subscribe(function (newValue) {
 	  self.collection.label(newValue);
+	  self.collection.updateFields();
+	  self.changeCollection(false);
+	  self.search();
     });
   }
   
@@ -659,6 +674,7 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
     }
     return _facet;    
   };
+  self.changeCollection = ko.observable(false);
 
   self.previewColumns = ko.observable("");
   self.columns = ko.observable([]);
@@ -788,8 +804,8 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
     )
     .done(function() {
       if (arguments[0] instanceof Array) { // If multi queries
-      var histoFacetId = self.collection.getHistogramFacet().id();
-      var histoFacet = self.getFacetFromQuery(histoFacetId);  
+        var histoFacetId = self.collection.getHistogramFacet().id();
+        var histoFacet = self.getFacetFromQuery(histoFacetId);  
         for (var i = 1; i < arguments.length; i++) {
           histoFacet.extraSeries.push(arguments[i][0]['series']);
         }
@@ -865,6 +881,7 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
       if (data.status == 0) {
         self.collection.id = data.id;
         $(document).trigger("info", data.message);
+        //window.location.hash = '#collection=' + data.id;
       }
       else {
         $(document).trigger("error", data.message);