[Kimchi-devel] [PATCH 1/3 v3] [Kimchi] Issue #921: Peers button disappears

sguimaraes943 at gmail.com sguimaraes943 at gmail.com
Thu Sep 1 17:14:04 UTC 2016


From: Samuel Guimarães <sguimaraes943 at gmail.com>

This commit moves peers list from the drop-down on the top navigation bar to a DataTable that will be rendered on Host Dashboard if the user has Gingerbased installed.

Signed-off-by: Samuel Guimarães <sguimaraes943 at gmail.com>
---
 root.py                 |   6 +++
 ui/js/kimchi.peers.js   | 140 ++++++++++++++++++++++++++++++++++++++++++++++++
 ui/js/src/kimchi.api.js |  14 -----
 ui/pages/i18n.json.tmpl |   4 +-
 4 files changed, 149 insertions(+), 15 deletions(-)
 create mode 100644 ui/js/kimchi.peers.js

diff --git a/root.py b/root.py
index 90680b4..faa9eb9 100644
--- a/root.py
+++ b/root.py
@@ -67,6 +67,12 @@ class Kimchi(WokRoot):
         self.domain = 'kimchi'
         self.messages = messages
 
+        self.extends = {
+            "/plugins/gingerbase": {
+                "host-dashboard.html": "/plugins/kimchi/js/kimchi.peers.js"
+            }
+        }
+
         # Some paths or URI's present in the objectstore have changed after
         # Kimchi 2.0.0 release. Check here if an upgrade in the schema and data
         # are necessary.
diff --git a/ui/js/kimchi.peers.js b/ui/js/kimchi.peers.js
new file mode 100644
index 0000000..f6d82c3
--- /dev/null
+++ b/ui/js/kimchi.peers.js
@@ -0,0 +1,140 @@
+/*
+ * Project Kimchi
+ *
+ * Copyright IBM Corp, 2013-2016
+ *
+ * Licensed 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.
+ */
+
+var kimchi = {
+
+    getPeers: function(suc, err) {
+        wok.requestJSON({
+            url: 'plugins/kimchi/peers',
+            type: 'GET',
+            contentType: 'application/json',
+            dataType: 'json',
+            resend: true,
+            success: suc,
+            error: err ? err : function(data) {
+                wok.message.error(data.responseJSON.reason);
+            }
+        });
+    },
+
+    initPeers: function() {
+
+        var peersAccordion = "<div class='panel-group federation-enabled accordion' id='peers-content-area-accordion' role='tablist' aria-multiselectable='true'>" +
+            "<h3>" +
+            "<a role='button' aria-expanded='true' data-toggle='collapse' data-parent='#peers-content-area-accordion' href='#peers-content-area' aria-expanded='false' aria-controls='peers-content-area' class=''>" +
+            "<span class='accordion-icon'></span>" +
+            "<span class='accordion-text' id='#peers-title'>"+i18n['KCHPEERS0001M']+"</span>" +
+            "</a>" +
+            "</h3>" +
+            "<div id='peers-content-area' class='panel-collapse collapse in' role='tabpanel' aria-labelledby='peers-title'>" +
+            "<div id='peers-alert-container'></div>" +
+            "<div class='row'>" +
+            "<div class='col-sm-12'>" +
+            "<table id='peers-list' class='table table-striped' cellspacing='0' width='100%''>" +
+            "<thead>" +
+            "<tr>" +
+            "<th>" + i18n['KCHPEERS0001M'] + "</th>" +
+            "</tr>" +
+            "</thead>" +
+            "</table>" +
+            "</div>" +
+            "</div>" +
+            "<div class='wok-mask' role='presentation'>" +
+            "<div class='wok-mask-loader-container'>" +
+            "<div class='wok-mask-loading'>" +
+            "<div class='wok-mask-loading-icon'></div>" +
+            "<div class='wok-mask-loading-text'>" + i18n['WOKGRD6001M'] + "</div>" +
+            "</div>" +
+            "</div>" +
+            "</div>" +
+            "</div>" +
+            "</div>";
+
+        var peersDatatableTable;
+        var peers = new Array();
+
+        $('#peers-container > .container').append(peersAccordion);
+
+        var peersDatatable = function(nwConfigDataSet) {
+            peersDatatableTable = $('#peers-list').DataTable({
+                "processing": true,
+                "data": peers,
+                "language": {
+                    "emptyTable": i18n['WOKSETT0010M']
+                },
+                "order": [],
+                "paging": false,
+                "dom": '<"row"<"col-sm-12"t>>',
+                "scrollY": "269px",
+                "scrollCollapse": true,
+                "columnDefs": [{
+                    "targets": 0,
+                    "searchable": false,
+                    "orderable": false,
+                    "width": "100%",
+                    "className": "tabular-data",
+                    "render": function(data, type, full, meta) {
+                        return '<a href="' + data + '" target="_blank">' + data + '</a>';
+                    }
+                }],
+                "initComplete": function(settings, json) {
+                    $('#peers-content-area > .wok-mask').addClass('hidden');
+                }
+            });
+        };
+
+        var getPeers = function() {
+            kimchi.getPeers(function(result) {
+                peers.length = 0;
+                for (var i = 0; i < result.length; i++) {
+                    var tempArr = [];
+                    tempArr.push(result[i]);
+                    peers.push(tempArr);
+                }
+                peersDatatable(peers);
+            }, function(err) {
+                wok.message.error(err.responseJSON.reason, '#peers-alert-container', true);
+            });
+        };
+        getPeers();
+
+    },
+
+    getConfig: function(suc, err, done) {
+        done = typeof done !== 'undefined' ? done : function() {};
+        wok.requestJSON({
+            url: "plugins/kimchi/config",
+            type: "GET",
+            contentType: "application/json",
+            dataType: "json",
+            success: suc,
+            error: err,
+            complete: done
+        });
+    }
+}
+
+$(document).ready(function() {
+    // Peers check
+    kimchi.getConfig(function(config) {
+        if (config.federation) {
+            $("#host-content-container").after('<div id="peers-container"><div class="container"></div></div>');
+            kimchi.initPeers();
+        }
+    });
+});
diff --git a/ui/js/src/kimchi.api.js b/ui/js/src/kimchi.api.js
index fd3e5d7..2f127aa 100644
--- a/ui/js/src/kimchi.api.js
+++ b/ui/js/src/kimchi.api.js
@@ -1071,20 +1071,6 @@ var kimchi = {
         });
     },
 
-    getPeers : function(suc, err) {
-        wok.requestJSON({
-            url : 'plugins/kimchi/peers',
-            type : 'GET',
-            contentType : 'application/json',
-            dataType : 'json',
-            resend : true,
-            success : suc,
-            error : err ? err : function(data) {
-                wok.message.error(data.responseJSON.reason);
-            }
-        });
-    },
-
     getVMPCIDevices : function(id, suc, err) {
         wok.requestJSON({
             url : 'plugins/kimchi/vms/' + encodeURIComponent(id) + '/hostdevs',
diff --git a/ui/pages/i18n.json.tmpl b/ui/pages/i18n.json.tmpl
index a5185b1..f9e148d 100644
--- a/ui/pages/i18n.json.tmpl
+++ b/ui/pages/i18n.json.tmpl
@@ -117,5 +117,7 @@
     "KCHPOOL6018M": "$_("Wipe Confirmation")",
 
     "KCHVMSTOR0001E": "$_("CDROM path needs to be a valid local/remote path and cannot be blank.")",
-    "KCHVMSTOR0002E": "$_("Disk pool or volume cannot be blank.")"
+    "KCHVMSTOR0002E": "$_("Disk pool or volume cannot be blank.")",
+
+    "KCHPEERS0001M": "$_("Peers")"
 }
-- 
2.5.5




More information about the Kimchi-devel mailing list