Explorar o código

HUE-3294 [editor] First round of adding Search

Enrico Berti %!s(int64=9) %!d(string=hai) anos
pai
achega
4894752cbf

+ 3 - 3
apps/search/src/search/static/search/js/search.ko.js

@@ -1592,7 +1592,7 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
                   var _docs = [];
                   var _mustacheTmpl = self.collection.template.isGridLayout() ? "" : fixTemplateDotsAndFunctionNames(self.collection.template.template());
                   $.each(data.response.docs, function (index, item) {
-                    _docs.push(self._make_result_doc(item));
+                    _docs.push(self._make_result_doc(item, _mustacheTmpl));
                   });
                   self.results(_docs);
                 }
@@ -1632,7 +1632,7 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
       });
   };
 
-  self._make_result_doc = function(item) {
+  self._make_result_doc = function(item, _mustacheTmpl) {
       var row = [];
       var leafletmap = {};
       var _externalLink = item.externalLink;
@@ -1675,7 +1675,7 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
       if (_childDocuments) {
         var childRecords = [];
         $.each(_childDocuments, function (index, item) {
-          var record = self._make_result_doc(item);
+          var record = self._make_result_doc(item, _mustacheTmpl);
           $.each(item, function(key, val) {
             var _field = ko.mapping.fromJS({
                 key: key,

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

@@ -3294,7 +3294,7 @@ $(document).ready(function () {
     }
   ]);
 
-  ko.applyBindings(viewModel);
+  ko.applyBindings(viewModel, $('#searchComponents')[0]);
 
   viewModel.init(function(data){
     $(".chosen-select").trigger("chosen:updated");

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

@@ -24,6 +24,8 @@ from django.utils.translation import ugettext as _
 
 ${ commonheader(_('Search'), "search", user, request, "80px") | n,unicode }
 
+## <span id="searchComponents">
 ${ common_search.page_structure() }
+## </span>
 
 ${ commonfooter(request, messages) | n,unicode }

+ 27 - 0
apps/search/src/search/templates/search_embeddable.mako

@@ -0,0 +1,27 @@
+## Licensed to Cloudera, Inc. under one
+## or more contributor license agreements.  See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership.  Cloudera, Inc. licenses this file
+## to you under the Apache License, Version 2.0 (the
+## "License"); you may not use this file except in compliance
+## with the License.  You may obtain a copy of the License at
+##
+##     http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+
+<%!
+from desktop.views import commonheader, commonfooter, _ko
+from desktop import conf
+from django.utils.translation import ugettext as _
+%>
+
+<%namespace name="common_search" file="common_search.mako" />
+
+<span id="searchComponents">
+${ common_search.page_structure() }
+</span>

+ 2 - 0
apps/search/src/search/templates/search_m.mako

@@ -24,6 +24,8 @@ from django.utils.translation import ugettext as _
 
 ${ commonheader_m(_('Search'), "search", user, request, "80px") | n,unicode }
 
+<span id="searchComponents">
 ${ common_search.page_structure(True) }
+</span>
 
 ${ commonfooter_m(request, messages) | n,unicode }

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

@@ -20,6 +20,7 @@ from django.conf.urls import patterns, url
 urlpatterns = patterns('search.views',
   url(r'^$', 'index', name='index'),
   url(r'^m$', 'index_m', name='index_m'),
+  url(r'^embeddable$', 'index_embeddable', name='index_embeddable'),
   url(r'^search$', 'search', name='search'),
   url(r'^save$', 'save', name='save'),
   url(r'^new_search', 'new_search', name='new_search'),

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

@@ -46,7 +46,7 @@ LOG = logging.getLogger(__name__)
 
 
 
-def index(request, is_mobile=False):
+def index(request, is_mobile=False, is_embeddable=False):
   hue_collections = SearchController(request.user).get_search_collections()
   collection_id = request.GET.get('collection')
 
@@ -74,6 +74,8 @@ def index(request, is_mobile=False):
   template = 'search.mako'
   if is_mobile:
     template = 'search_m.mako'
+  if is_embeddable:
+    template = 'search_embeddable.mako'
 
   return render(template, request, {
     'collection': collection,
@@ -87,6 +89,9 @@ def index(request, is_mobile=False):
 def index_m(request):
   return index(request, True)
 
+def index_embeddable(request):
+  return index(request, False, True)
+
 
 def new_search(request):
   collections = SearchController(request.user).get_all_indexes()

+ 1 - 1
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -2309,7 +2309,7 @@
     }
   };
 
-  ko.bindingHandlers.typeahead = {
+  ko.bindingHandlers.typdeahead = {
     init: function (element, valueAccessor) {
       var binding = this;
       var elem = $(element);

+ 4 - 3
desktop/core/src/desktop/templates/responsive.mako

@@ -294,7 +294,8 @@ ${ hueIcons.symbols() }
     <div class="page-content">
       Load
       <a href="#" data-bind="click: function(){ currentApp('editor') }">editor</a> |
-      <a href="#" data-bind="click: function(){ currentApp('metastore') }">metastore</a>
+      <a href="#" data-bind="click: function(){ currentApp('metastore') }">metastore</a> |
+      <a href="#" data-bind="click: function(){ currentApp('search') }">search</a>
 
       <!-- ko if: isLoadingEmbeddable -->
       <i class="fa fa-spinner fa-spin"></i>
@@ -361,7 +362,8 @@ ${ assist.assistPanel() }
 
     self.EMBEDDABLE_PAGE_URLS = {
       editor: '/notebook/editor_embeddable',
-      metastore: '/metastore/tables/?is_embeddable=true'
+      metastore: '/metastore/tables/?is_embeddable=true',
+      search: '/search/embeddable?collection=4',
     };
 
     self.embeddable_cache = {};
@@ -374,7 +376,6 @@ ${ assist.assistPanel() }
       if (typeof self.embeddable_cache[newVal] === 'undefined'){
         $.ajax({
           url: self.EMBEDDABLE_PAGE_URLS[newVal],
-          cache: false,
           beforeSend:function (xhr) {
             xhr.setRequestHeader('X-Requested-With', 'Hue');
           },