]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw/dashboard: move some logic from JS to Python side, some cleanups
authorChang Liu <liuchang0812@gmail.com>
Fri, 22 Dec 2017 07:18:21 +0000 (15:18 +0800)
committerChang Liu <liuchang0812@gmail.com>
Fri, 22 Dec 2017 07:20:23 +0000 (15:20 +0800)
Signed-off-by: Chang Liu <liuchang0812@gmail.com>
src/pybind/mgr/dashboard/module.py
src/pybind/mgr/dashboard/rgw_detail.html

index 4d18b3c979851544f4f03d98db9d3592302b3a03..9e50d2acc1a49f62d3f95da3f168783a874c4ac2 100644 (file)
@@ -66,6 +66,9 @@ def recurse_refs(root, path):
 def get_prefixed_url(url):
     return global_instance().url_prefix + url
 
+def to_sorted_array(data):
+    assert isinstance(data, dict)
+    return sorted(data.iteritems())
 
 
 class StandbyModule(MgrStandbyModule):
@@ -997,7 +1000,7 @@ class Module(MgrModule):
                     global_instance().log.error("Failed to load histogram for OSD {}".format(osd_id))
                 else:
                     histogram = json.loads(outb)
-
+               # TODO(chang liu): use to_sorted_array to simpify javascript code
                 return {
                     "osd": osd,
                     "osd_metadata": osd_metadata,
@@ -1160,8 +1163,7 @@ class Module(MgrModule):
             @cherrypy.tools.json_out()
             def rgw_daemons_data(self):
                 return self._rgw_daemons()
-
-            
+           
             def _rgw(self, rgw_id):
                 daemons = self.rgw_daemons_data()
                 rgw_metadata = {}
@@ -1176,8 +1178,8 @@ class Module(MgrModule):
 
                 return {
                     "rgw_id": rgw_id,
-                    "rgw_metadata": rgw_metadata,
-                    "rgw_status": rgw_status,
+                    "rgw_metadata": to_sorted_array(rgw_metadata),
+                    "rgw_status": to_sorted_array(rgw_status),
                 }
               
             @cherrypy.expose
index f367c4d77c37c0ed420ada25f968a257e6587e38..986dc90da0796a27530e9883be8343a5d6783adc 100644 (file)
             var refresh = function() {
                 $.get("{{ url_prefix }}/rgw/rgw_data/" + content_data.rgw_id + "/", function(data) {
                    content_data = data;
-                   setTimeout(refresh, 3000);
+                   setTimeout(refresh, 5000);
                 });
             };
             setTimeout(refresh, 5000);
 
-            var post_load = function() {
-                content_data.rgw_metadata_list = [];
-                content_data.rgw_status_list = [];
-                _.each(content_data.rgw_metadata, function(v, k) {
-                    content_data.rgw_metadata_list.push({
-                        key: k,
-                        value: v
-                    });
-                });
-                _.each(content_data.rgw_status, function(v, k) {
-                    content_data.rgw_status_list.push({
-                        key: k,
-                        value: v
-                    });
-                });
-                
-                if (content_data.rgw_status_list.length() == 0) {
-                     content_data.rgw_status_show = false;
-                } else {
-                     content_data.rgw_status_show = true;
-                }
-            };
-
             rivets.bind($("#content"), content_data);
-            post_load();
         });
 </script>
 
 <section class="content-header">
-    <h1>
-        rgw.{rgw_id}
-    </h1>
+    <h1 rv-text="rgw_id"></h1>
 </section>
 
-<div class="box" rv-show="rgw_status_show">
-    <div class="box-header">
-        <h3 class="box-title">Status</h3>
-    </div>
-    <div class="box-body">
-        <table>
-            <thead>
-            <tr>
-                <th>Key</th>
-                <th>Value</th>
-            </tr>
-            </thead>
-            <tbody>
-            <tr rv-each-meta_item="rgw_status_list">
-                <td>{meta_item.key}</td>
-                <td>{meta_item.value}</td>
-            </tr>
-            </tbody>
-        </table>
-    </div>
-</div>
+<section class="content">
+  <div class="box" rv-show="rgw_status | length">
+      <div class="box-header">
+         <h3 class="box-title">Status</h3>
+      </div>
+      <div class="box-body">
+         <table>
+             <thead>
+             <tr>
+                 <th>Key</th>
+                 <th>Value</th>
+             </tr>
+             </thead>
+             <tbody>
+             <tr rv-each-status-pair="rgw_status">
+                 <td rv-each-item="status-pair"> {item} </td>
+             </tr>
+             </tbody>
+         </table>
+      </div>
+  </div>
 
+  <div class="box" rv-show="rgw_metadata | length">
+      <div class="box-header">
+         <h3 class="box-title">Metadata</h3>
+      </div>
+      <div class="box-body">
+         <table class="table table-condensed">
+             <thead>
+             <tr>
+                 <th>Key</th>
+                 <th>Value</th>
+             </tr>
+             </thead>
+             <tbody>
+             <tr rv-each-meta-pair="rgw_metadata">
+                 <td rv-each-item="meta-pair"> {item} </td>
+             </tr>
+             </tbody>
+         </table>
+      </div>
+  </div>
 
-
-<div class="box">
-    <div class="box-header">
-        <h3 class="box-title">Metadata</h3>
-    </div>
-    <div class="box-body">
-        <table class="table table-condensed">
-            <thead>
-            <tr>
-                <th>Key</th>
-                <th>Value</th>
-            </tr>
-            </thead>
-            <tbody>
-            <tr rv-each-meta_item="rgw_metadata_list">
-                <td>{meta_item.key}</td>
-                <td>{meta_item.value}</td>
-            </tr>
-            </tbody>
-        </table>
-    </div>
-</div>
-
+</section>
 
 <!-- /.content -->