浏览代码

HUE-1811 [search] Install examples button in quick start wizard

Also display a landing page when no collections are setup
Romain Rigaux 11 年之前
父节点
当前提交
251ea05

+ 0 - 0
apps/search/src/search/fixtures/initial_indexes_examples.json → apps/search/src/search/fixtures/initial_search_examples.json


+ 0 - 0
apps/search/src/search/management/__init__.py


+ 0 - 0
apps/search/src/search/management/commands/__init__.py


+ 38 - 0
apps/search/src/search/management/commands/search_setup.py

@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+# 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.
+
+import logging
+
+from django.contrib.auth.models import User
+from django.core import management
+from django.core.management.base import NoArgsCommand
+from django.utils.translation import ugettext as _
+
+from desktop.models import Document
+from useradmin.models import install_sample_user
+
+LOG = logging.getLogger(__name__)
+
+# initial_search_examples.json: add 1000000 to the ids
+
+class Command(NoArgsCommand):
+  def handle_noargs(self, **options):
+
+    # Load jobs
+#    install_sample_user()
+    management.call_command('loaddata', 'initial_search_examples.json', verbosity=2)
+    Document.objects.sync()

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

@@ -33,6 +33,7 @@ from search.conf import SOLR_URL
 from search.data_export import download as export_download
 from search.decorators import allow_admin_only
 from search.forms import QueryForm, CollectionForm
+from search.management.commands import search_setup
 from search.models import Collection, augment_solr_response
 from search.search_controller import SearchController
 
@@ -390,7 +391,7 @@ def install_examples(request):
     result['message'] = _('A POST request is required.')
   else:
     try:
-      #pig_setup.Command().handle_noargs()
+      search_setup.Command().handle_noargs()
       result['status'] = 0
     except Exception, e:
       LOG.exception(e)

+ 14 - 9
desktop/core/src/desktop/templates/common_header.mako

@@ -368,15 +368,20 @@ from django.utils.translation import ugettext as _
        % if 'search' in apps:
          <%! from search.search_controller import SearchController %>
          <% collections = SearchController(user).get_search_collections() %>
-         <li class="dropdown">
-           <a title="${_('Solr Search')}" rel="navigator-tooltip" href="#" data-toggle="dropdown" class="dropdown-toggle">${_('Search')} <b class="caret"></b></a>
-           ## TODO: no collections yet? /search/admin/collections
-           <ul role="menu" class="dropdown-menu">
-             % for collection in collections:
-             <li><a href="${ url('search:index') }?collection=${ collection.id }"><img src="/search/static/art/icon_search_24.png" /> ${ collection.label }</a></li>
-             % endfor
-           </ul>
-         </li>
+         % if not collections:
+           <li>
+             <a title="${_('Solr Search')}" rel="navigator-tooltip" href="${ url('search:index') }">${_('Search')}</a>
+           </li>
+         % else:
+           <li class="dropdown">
+             <a title="${_('Solr Search')}" rel="navigator-tooltip" href="#" data-toggle="dropdown" class="dropdown-toggle">${_('Search')} <b class="caret"></b></a>
+             <ul role="menu" class="dropdown-menu">
+               % for collection in collections:
+               <li><a href="${ url('search:index') }?collection=${ collection.id }"><img src="/search/static/art/icon_search_24.png" /> ${ collection.label }</a></li>
+               % endfor
+             </ul>
+           </li>
+         % endif
        % endif
        % if other_apps:
        <li class="dropdown">