浏览代码

[search] Show collection properties instead of core properties

Romain Rigaux 12 年之前
父节点
当前提交
9a11973

+ 10 - 4
apps/search/src/search/api.py

@@ -83,11 +83,17 @@ class SolrApi(object):
     except RestException, e:
       raise PopupException('Error while accessing Solr: %s' % e)
 
-  def collection(self, core):
+  def collection_or_core(self, hue_collection):
+    if hue_collection.is_core_only:
+      return self.core(hue_collection.name)
+    else:
+      return self.collection(hue_collection.name)
+
+  def collection(self, name):
     try:
-      # TODO: if core get from here, if collection from Zookeeper
-      return self._root.get('admin/cores', params={'wt': 'json', 'core': core})
-    except RestException, e:
+      collections = self.collections()
+      return collections[name]
+    except Exception, e:
       raise PopupException('Error while accessing Solr: %s' % e)
 
   def cores(self):

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

@@ -23,7 +23,6 @@ from desktop.lib.conf import Config
 SOLR_URL = Config(
   key="solr_url",
   help=_("URL of the Solr Server."),
-  private=False,
   default="http://localhost:8983/solr/")
 
 #SOLR_URLS = UnspecifiedConfigSection(

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

@@ -40,7 +40,7 @@ ${ commonheader(_('Search'), "search", user) | n,unicode }
 
 <%layout:skeleton>
   <%def name="title()">
-    <h1>${_('Search Admin - ')} ${ hue_collection.label }</h1>
+    <h1>${_('Customize ')} ${ hue_collection.label }</h1>
   </%def>
 
   <%def name="navigation()">
@@ -57,7 +57,7 @@ ${ commonheader(_('Search'), "search", user) | n,unicode }
         <a href="#schema" data-toggle="tab">${_('Schema')}</a>
       </li>
       <li>
-        <a href="#properties" data-toggle="tab">${_('Properties')}</a>
+        <a href="#properties" data-toggle="tab">${_('Cores')}</a>
       </li>
     </ul>
     <div class="tab-content">

+ 50 - 74
apps/search/src/search/templates/admin_collection_properties_solr_properties.mako

@@ -23,15 +23,27 @@
 
 
 <%def name="indexProperty(key)">
-  %if key in solr_collection["status"][hue_collection.name]["index"]:
+  % if hue_collection.is_core_only:
+    % if key in solr_collection["status"][hue_collection.name]["index"]:
       ${ solr_collection["status"][hue_collection.name]["index"][key] }
-    %endif
+    % endif
+  % else:
+    % for key, value in solr_collection.iteritems():
+      ${ key } : ${ value }
+    % endfor  
+  % endif
 </%def>
 
 <%def name="collectionProperty(key)">
-  %if key in solr_collection["status"][hue_collection.name]:
+  % if hue_collection.is_core_only:
+    % if key in solr_collection["status"][hue_collection.name]:
       ${ solr_collection["status"][hue_collection.name][key] }
-    %endif
+    % endif
+  % else:
+    % for key, value in solr_collection.iteritems():
+      ${ key } : ${ value }
+    % endfor  
+  % endif
 </%def>
 
 <%layout:skeleton>
@@ -39,12 +51,9 @@
   </%def>
 
   <%def name="content()">
-    <ul class="nav nav-tabs">
-      <li class="active"><a href="#index_properties" data-toggle="tab">${_('Index properties')}</a></li>
-      <li><a href="#collection_properties" data-toggle="tab">${_('Core properties')}</a></li>
-    </ul>
-
-    <div class="tab-content">
+  
+  % if not hue_collection.is_core_only:
+    <div class="tab-content">         
       <div class="tab-pane active" id="index_properties">
         <table class="table">
           <thead>
@@ -55,44 +64,36 @@
           </thead>
           <tbody>
           <tr>
-            <td>sizeInBytes</td>
-            <td>${ indexProperty('sizeInBytes') }</td>
-          </tr>
-          <tr>
-            <td>segmentCount</td>
-            <td>${ indexProperty('segmentCount') }</td>
-          </tr>
-          <tr>
-            <td>maxDoc</td>
-            <td>${ indexProperty('maxDoc') }</td>
-          </tr>
-          <tr>
-            <td>lastModified</td>
-            <td>${ indexProperty('lastModified') }</td>
-          </tr>
-          <tr>
-            <td>current</td>
-            <td>${ indexProperty('current') }</td>
-          </tr>
-          <tr>
-            <td>version</td>
-            <td>${ indexProperty('version') }</td>
-          </tr>
-          <tr>
-            <td>directory</td>
-            <td>${ indexProperty('directory') }</td>
-          </tr>
-          <tr>
-            <td>numDocs</td>
-            <td>${ indexProperty('numDocs') }</td>
+            % for key, value in solr_collection.iteritems():
+              <td>${ key }</td>
+              <td>${ value }</td>
+            % endfor          
           </tr>
+          </tbody>
+        </table>
+      </div>
+    </div>
+  % else:
+    <ul class="nav nav-tabs">
+      <li class="active"><a href="#index_properties" data-toggle="tab">${_('Index properties')}</a></li>
+      <li><a href="#collection_properties" data-toggle="tab">${_('Collection properties')}</a></li>
+    </ul>
+
+    <div class="tab-content">         
+      <div class="tab-pane active" id="index_properties">
+        <table class="table">
+          <thead>
           <tr>
-            <td>hasDeletions</td>
-            <td>${ indexProperty('hasDeletions') }</td>
+            <th width="20%">${_('Property')}</th>
+            <th>${_('Value')}</th>
           </tr>
+          </thead>
+          <tbody>
           <tr>
-            <td>size</td>
-            <td>${ indexProperty('size') }</td>
+            % for key, value in solr_collection.iteritems():
+              <td>${ key }</td>
+              <td>${ value }</td>
+            % endfor          
           </tr>
           </tbody>
         </table>
@@ -107,41 +108,16 @@
           </thead>
           <tbody>
           <tr>
-            <td>uptime</td>
-            <td>${ collectionProperty('uptime') }</td>
-          </tr>
-          <tr>
-            <td>name</td>
-            <td>${ collectionProperty('name') }</td>
-          </tr>
-          <tr>
-            <td>isDefaultCore</td>
-            <td>${ collectionProperty('isDefaultCore') }</td>
-          </tr>
-          <tr>
-            <td>dataDir</td>
-            <td>${ collectionProperty('dataDir') }</td>
-          </tr>
-          <tr>
-            <td>instanceDir</td>
-            <td>${ collectionProperty('instanceDir') }</td>
-          </tr>
-          <tr>
-            <td>startTime</td>
-            <td>${ collectionProperty('startTime') }</td>
-          </tr>
-          <tr>
-            <td>config</td>
-            <td>${ collectionProperty('config') }</td>
-          </tr>
-          <tr>
-            <td>schema</td>
-            <td>${ collectionProperty('schema') }</td>
+            % for key, value in solr_collection.iteritems():
+              <td>${ key }</td>
+              <td>${ value }</td>
+            % endfor          
           </tr>
           </tbody>
         </table>
       </div>
     </div>
+  % endif
 
   </%def>
 </%layout:skeleton>

+ 5 - 1
apps/search/src/search/templates/layout.mako

@@ -65,10 +65,14 @@
   <div class="well sidebar-nav" style="min-height: 250px">
     <ul class="nav nav-list">
 
-    <li class="nav-header">${_('Core')}</li>
+    <li class="nav-header">${_('Collection')}</li>
       <li class="${ utils.is_selected(section, 'properties') }">
         <a href="${ url('search:admin_collection_properties', collection=collection) }"><i class="icon-reorder"></i> ${_('Properties')}</a>
       </li>
+      ## Yes or no????? No for now
+      <li class="${ utils.is_selected(section, 'cores') }">
+        <a href="${ url('search:admin_collection_properties', collection=collection) }"><i class="icon-reorder"></i> ${_('Cores')}</a>
+      </li>
 
       <li class="nav-header">${_('Template')}</li>
       <li class="${ utils.is_selected(section, 'template') }">

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

@@ -241,7 +241,10 @@ ${ commonheader(_('Search'), "search", user, "40px") | n,unicode }
     });
     $(".dateFacetHeader").after(orderedDateFacets);
 
-    $(".current-collection").text("${ hue_collection.label }");
+    % if hue_collection:
+      $(".current-collection").text("${ hue_collection.label }");
+    % endif
+
     % if user.is_superuser:
         $(".dropdown-collection").each(function () {
           if ($(this).data("value") == $("select[name='collection']").val()) {

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

@@ -136,9 +136,9 @@ def admin(request):
 
 
 @allow_admin_only
-def admin_collection_properties(request, collection):
-  solr_collection = SolrApi(SOLR_URL.get()).collection(collection)
+def admin_collection_properties(request, collection):  
   hue_collection = Collection.objects.get(name=collection)
+  solr_collection = SolrApi(SOLR_URL.get()).collection_or_core(hue_collection)
 
   if request.method == 'POST':
     collection_form = CollectionForm(request.POST, instance=hue_collection)