[Kimchi-devel] [PATCH] [Kimchi 4/6] Add Network listeners to update page according to user interations

Aline Manera aline.manera at gmail.com
Tue Jul 25 20:10:02 UTC 2017


It makes use of the async websockets notification mechanism provided by
Wok to update the Network tab content when a network is added or removed
without the need to polling requests to server.

Signed-off-by: Aline Manera <aline.manera at gmail.com>
---
 ui/js/src/kimchi.network.js | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/ui/js/src/kimchi.network.js b/ui/js/src/kimchi.network.js
index ea15228..430b7ae 100644
--- a/ui/js/src/kimchi.network.js
+++ b/ui/js/src/kimchi.network.js
@@ -1,7 +1,7 @@
 /*
  * Project Kimchi
  *
- * Copyright IBM Corp, 2013-2016
+ * Copyright IBM Corp, 2013-2017
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@ kimchi.NETWORK_TYPE_PASSTHROUGH = "passthrough";
 kimchi.NETWORK_TYPE_BRIDGED = "bridge";
 kimchi.NETWORK_TYPE_VEPA = "vepa";
 
-
 kimchi.initNetwork = function() {
     $('body').removeClass('wok-list wok-gallery');
 
@@ -36,6 +35,11 @@ kimchi.initNetwork = function() {
     kimchi.initNetworkListView();
 };
 
+wok.addNotificationListener('METHOD:/kimchi/networks', function() {
+    $("#networkBody").empty();
+    kimchi.initNetworkListView();
+});
+
 kimchi.initNetworkListView = function() {
     $('.wok-mask').removeClass('hidden');
     kimchi.listNetworks(function(data) {
@@ -57,6 +61,9 @@ kimchi.initNetworkListView = function() {
             network.persistent = data[i].persistent;
             kimchi.addNetworkItem(network);
         }
+        if($('#networkGrid').hasClass('wok-datagrid')) {
+            $('#networkGrid').dataGrid('destroy');
+        }
         $('#networkGrid').dataGrid({enableSorting: false});
         $('#networkGrid').removeClass('hidden');
         $('.wok-mask').fadeOut(300, function() {});
-- 
2.9.4



More information about the Kimchi-devel mailing list