Browse Source

[search] Improved labels and schema loading

Enrico Berti 12 năm trước cách đây
mục cha
commit
970b2b5

+ 28 - 2
apps/search/src/search/templates/admin_collection_properties.mako

@@ -74,7 +74,7 @@ ${ commonheader(_('Search'), "search", user, "40px") | n,unicode }
       </div>
 
       <div class="tab-pane" id="schema">
-        ${_('Loading...')} <img src="/static/art/spinner.gif">
+        <textarea id="schema_field">${_('Loading...')}</textarea>
       </div>
 
       <div class="tab-pane" id="properties">
@@ -86,14 +86,40 @@ ${ commonheader(_('Search'), "search", user, "40px") | n,unicode }
 
 </%layout:skeleton>
 
+<script src="/static/ext/js/codemirror-3.11.js"></script>
+<link rel="stylesheet" href="/static/ext/css/codemirror.css">
+<script src="/static/ext/js/codemirror-xml.js"></script>
+
 <script type="text/javascript" charset="utf-8">
   $(document).ready(function(){
+    var schemaViewer = $("#schema_field")[0];
+
+    var codeMirror = CodeMirror(function (elt) {
+      schemaViewer.parentNode.replaceChild(elt, schemaViewer);
+    }, {
+      value: schemaViewer.value,
+      readOnly: true,
+      lineNumbers: true
+    });
+
+    codeMirror.setSize("100%", $(document).height() - 150 - $(".form-actions").outerHeight());
+
     $.get("${ url('search:admin_collection_schema', collection_id=hue_collection.id) }", function(data) {
-        $("#schema").html(data.content); // Need to scroll to refresh
+      console.log(data);
+      codeMirror.setValue(data.solr_schema);
+        //$("#schema").html(data.content); // Need to scroll to refresh
     });
     $.get("${ url('search:admin_collection_solr_properties', collection_id=hue_collection.id) }", function(data) {
         $("#properties").html(data.content);
     });
+
+
+    // Force refresh on tab change
+    $("a[data-toggle='tab']").on("shown", function (e) {
+      if ($(e.target).attr("href") == "#schema") {
+        codeMirror.refresh();
+      }
+    });
  });
 </script>
 

+ 0 - 57
apps/search/src/search/templates/admin_collection_properties_solr_schema.mako

@@ -1,57 +0,0 @@
-## 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 django.utils.translation import ugettext as _
-%>
-
-<%namespace name="layout" file="layout.mako" />
-<%namespace name="macros" file="macros.mako" />
-
-<%layout:skeleton>
-
-  <%def name="title()">
-  </%def>
-
-  <%def name="content()">
-    <textarea id="schema_field">
-      ${ solr_schema.decode('utf-8') }
-    </textarea>
-  </%def>
-
-</%layout:skeleton>
-
-
-<script src="/static/ext/js/codemirror-3.11.js"></script>
-<link rel="stylesheet" href="/static/ext/css/codemirror.css">
-<script src="/static/ext/js/codemirror-xml.js"></script>
-
-
-<script type="text/javascript">
-  $(document).ready(function () {
-    var schemaViewer = $("#schema_field")[0];
-
-    window.codeMirror = CodeMirror(function (elt) {
-      schemaViewer.parentNode.replaceChild(elt, schemaViewer);
-    }, {
-      value: schemaViewer.value,
-      readOnly: true,
-      lineNumbers: true
-    });
-
-    window.codeMirror.setSize("100%", $(document).height() - 150 - $(".form-actions").outerHeight());
-  });
-</script>

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

@@ -29,7 +29,7 @@
 
   <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="icon-share-alt"></i> ${ _('Query UI') }</a> &nbsp; &nbsp;
+        <a href="${ url('search:index') }"><i class="icon-share-alt"></i> ${ _('Search page') }</a> &nbsp; &nbsp;
         <a href="${ url('search:admin_collections') }"><i class="icon-edit"></i> ${ _('Collection manager') }</a>
       </div>
     %if hasattr(caller, "title"):
@@ -79,7 +79,7 @@
         <a href="${ url('search:admin_collection_properties', collection_id=hue_collection.id) }"><i class="icon-reorder"></i> ${_('Properties')}</a>
       </li>
       <li>
-        <a href="${ url('search:index') }?collection_id=${ hue_collection.id }"><i class="icon-share-alt"></i> ${ _('Query') }</a>
+        <a href="${ url('search:index') }?collection_id=${ hue_collection.id }"><i class="icon-search"></i> ${ _('Search this collection') }</a>
       </li>
 
       <li class="nav-header">${_('Template')}</li>

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

@@ -311,12 +311,10 @@ def admin_collection_schema(request, collection_id):
   hue_collection = Collection.objects.get(id=collection_id)
   solr_schema = SolrApi(SOLR_URL.get()).schema(hue_collection.name)
 
-  content = render('admin_collection_properties_solr_schema.mako', request, {
-    'solr_schema': solr_schema,
-    'hue_collection': hue_collection,
-  }, force_template=True).content
-
-  return HttpResponse(json.dumps({'content': content}), mimetype="application/json")
+  content = {
+    'solr_schema': solr_schema.decode('utf-8')
+  }
+  return HttpResponse(json.dumps(content), mimetype="application/json")
 
 
 # TODO security