GUI -- Topo - rewired modules to call wss.sendEvent(...) directly.

Change-Id: I9077694895b814c6dc342a518948e05e0cc2df01
diff --git a/web/gui/src/main/webapp/app/view/topo/topo.js b/web/gui/src/main/webapp/app/view/topo/topo.js
index 3dd8d6e..2a6d037 100644
--- a/web/gui/src/main/webapp/app/view/topo/topo.js
+++ b/web/gui/src/main/webapp/app/view/topo/topo.js
@@ -28,7 +28,8 @@
     ];
 
     // references to injected services etc.
-    var $log, fs, ks, zs, gs, ms, sus, flash, tes, tfs, tps, tis, tss, tts, tos;
+    var $log, fs, ks, zs, gs, ms, sus, flash, wss,
+        tes, tfs, tps, tis, tss, tts, tos;
 
     // DOM elements
     var ovtopo, svg, defs, zoomLayer, mapG, forceG, noDevsLayer;
@@ -102,7 +103,7 @@
     }
 
     function equalizeMasters() {
-        tes.sendEvent('equalizeMasters');
+        wss.sendEvent('equalizeMasters');
         flash.flash('Equalizing master roles');
     }
 
@@ -213,16 +214,16 @@
     // --- Controller Definition -----------------------------------------
 
     angular.module('ovTopo', moduleDependencies)
-        .controller('OvTopoCtrl', [
-            '$scope', '$log', '$location', '$timeout',
+        .controller('OvTopoCtrl', ['$scope', '$log', '$location', '$timeout',
             'FnService', 'MastService', 'KeyService', 'ZoomService',
             'GlyphService', 'MapService', 'SvgUtilService', 'FlashService',
+            'WebSocketService',
             'TopoEventService', 'TopoForceService', 'TopoPanelService',
             'TopoInstService', 'TopoSelectService', 'TopoTrafficService',
             'TopoObliqueService',
 
         function ($scope, _$log_, $loc, $timeout, _fs_, mast,
-                  _ks_, _zs_, _gs_, _ms_, _sus_, _flash_,
+                  _ks_, _zs_, _gs_, _ms_, _sus_, _flash_, _wss_,
                   _tes_, _tfs_, _tps_, _tis_, _tss_, _tts_, _tos_) {
             var self = this,
                 projection,
@@ -233,8 +234,7 @@
                     projection: function () { return projection; },
                     zoomLayer: function () { return zoomLayer; },
                     zoomer: function () { return zoomer; },
-                    opacifyMap: opacifyMap,
-                    sendEvent: _tes_.sendEvent
+                    opacifyMap: opacifyMap
                 };
 
             $log = _$log_;
@@ -245,6 +245,7 @@
             ms = _ms_;
             sus = _sus_;
             flash = _flash_;
+            wss = _wss_;
             tes = _tes_;
             tfs = _tfs_;
             // TODO: consider funnelling actions through TopoForceService...
@@ -290,7 +291,7 @@
             forceG = zoomLayer.append('g').attr('id', 'topo-force');
             tfs.initForce(svg, forceG, uplink, dim);
             tis.initInst({ showMastership: tfs.showMastership });
-            tps.initPanels({ sendEvent: tes.sendEvent });
+            tps.initPanels();
             tes.start();
 
             $log.log('OvTopoCtrl has been created');
diff --git a/web/gui/src/main/webapp/app/view/topo/topoEvent.js b/web/gui/src/main/webapp/app/view/topo/topoEvent.js
index e7f29d3..c4d92c2 100644
--- a/web/gui/src/main/webapp/app/view/topo/topoEvent.js
+++ b/web/gui/src/main/webapp/app/view/topo/topoEvent.js
@@ -90,8 +90,7 @@
 
             return {
                 start: start,
-                stop: stop,
-                sendEvent: wss.sendEvent
+                stop: stop
             };
         }]);
 }());
diff --git a/web/gui/src/main/webapp/app/view/topo/topoForce.js b/web/gui/src/main/webapp/app/view/topo/topoForce.js
index 5b9991d..4a40782 100644
--- a/web/gui/src/main/webapp/app/view/topo/topoForce.js
+++ b/web/gui/src/main/webapp/app/view/topo/topoForce.js
@@ -23,7 +23,8 @@
     'use strict';
 
     // injected refs
-    var $log, fs, sus, is, ts, flash, tis, tms, td3, tss, tts, tos, fltr, tls,
+    var $log, fs, sus, is, ts, flash, wss,
+        tis, tms, td3, tss, tts, tos, fltr, tls,
         icfg, uplink, svg;
 
     // configuration
@@ -374,7 +375,7 @@
             metaUi = {x: d.x, y: d.y, lng: ll[0], lat: ll[1]};
         }
         d.metaUi = metaUi;
-        uplink.sendEvent('updateMeta', {
+        wss.sendEvent('updateMeta', {
             id: d.id,
             'class': d.class,
             memento: metaUi
@@ -691,8 +692,7 @@
         return {
             node: function () { return node; },
             zoomingOrPanning: zoomingOrPanning,
-            updateDeviceColors: td3.updateDeviceColors,
-            sendEvent: uplink.sendEvent
+            updateDeviceColors: td3.updateDeviceColors
         };
     }
 
@@ -704,8 +704,7 @@
             findLinkById: tms.findLinkById,
             hovered: tss.hovered,
             validateSelectionContext: tss.validateSelectionContext,
-            selectOrder: tss.selectOrder,
-            sendEvent: uplink.sendEvent
+            selectOrder: tss.selectOrder
         }
     }
 
@@ -749,11 +748,12 @@
     angular.module('ovTopo')
     .factory('TopoForceService',
         ['$log', 'FnService', 'SvgUtilService', 'IconService', 'ThemeService',
-            'FlashService', 'TopoInstService', 'TopoModelService',
+            'FlashService', 'WebSocketService',
+            'TopoInstService', 'TopoModelService',
             'TopoD3Service', 'TopoSelectService', 'TopoTrafficService',
             'TopoObliqueService', 'TopoFilterService', 'TopoLinkService',
 
-        function (_$log_, _fs_, _sus_, _is_, _ts_, _flash_,
+        function (_$log_, _fs_, _sus_, _is_, _ts_, _flash_, _wss_,
                   _tis_, _tms_, _td3_, _tss_, _tts_, _tos_, _fltr_, _tls_) {
             $log = _$log_;
             fs = _fs_;
@@ -761,6 +761,7 @@
             is = _is_;
             ts = _ts_;
             flash = _flash_;
+            wss = _wss_;
             tis = _tis_;
             tms = _tms_;
             td3 = _td3_;
diff --git a/web/gui/src/main/webapp/app/view/topo/topoPanel.js b/web/gui/src/main/webapp/app/view/topo/topoPanel.js
index c1a8400..485bfc8 100644
--- a/web/gui/src/main/webapp/app/view/topo/topoPanel.js
+++ b/web/gui/src/main/webapp/app/view/topo/topoPanel.js
@@ -23,12 +23,7 @@
     'use strict';
 
     // injected refs
-    var $log, fs, ps, gs;
-
-    var api;
-    /*
-      sendEvent( event, {payload} )
-     */
+    var $log, fs, ps, gs, wss;
 
     // constants
     var pCls = 'topo-p',
@@ -147,7 +142,7 @@
             hideSummaryPanel();
         } else {
             // ask server to start sending summary data.
-            api.sendEvent('requestSummary');
+            wss.sendEvent('requestSummary');
             // note: the summary panel will appear, once data arrives
         }
     }
@@ -165,7 +160,7 @@
 
     function hideSummaryPanel() {
         // instruct server to stop sending summary data
-        api.sendEvent("cancelSummary");
+        wss.sendEvent("cancelSummary");
         summaryPanel.hide(detailPanel.up);
     }
 
@@ -208,9 +203,7 @@
 
     // ==========================
 
-    function initPanels(_api_) {
-        api = _api_;
-
+    function initPanels() {
         summaryPanel = ps.createPanel(idSum, panelOpts);
         detailPanel = ps.createPanel(idDet, panelOpts);
 
@@ -230,13 +223,14 @@
 
     angular.module('ovTopo')
     .factory('TopoPanelService',
-        ['$log', 'FnService', 'PanelService', 'GlyphService',
+        ['$log', 'FnService', 'PanelService', 'GlyphService', 'WebSocketService',
 
-        function (_$log_, _fs_, _ps_, _gs_) {
+        function (_$log_, _fs_, _ps_, _gs_, _wss_) {
             $log = _$log_;
             fs = _fs_;
             ps = _ps_;
             gs = _gs_;
+            wss = _wss_;
 
             return {
                 initPanels: initPanels,
diff --git a/web/gui/src/main/webapp/app/view/topo/topoSelect.js b/web/gui/src/main/webapp/app/view/topo/topoSelect.js
index 2f1dd15..af0e041 100644
--- a/web/gui/src/main/webapp/app/view/topo/topoSelect.js
+++ b/web/gui/src/main/webapp/app/view/topo/topoSelect.js
@@ -23,7 +23,7 @@
     'use strict';
 
     // injected refs
-    var $log, fs, flash, tps, tts;
+    var $log, fs, flash, wss, tps, tts;
 
     // api to topoForce
     var api;
@@ -31,7 +31,6 @@
        node()                         // get ref to D3 selection of nodes
        zoomingOrPanning( ev )
        updateDeviceColors( [dev] )
-       sendEvent( type, {payload} )
      */
 
     // internal state
@@ -143,7 +142,7 @@
 
     function requestDetails() {
         var data = getSel(0).obj;
-        api.sendEvent('requestDetails', {
+        wss.sendEvent('requestDetails', {
             id: data.id,
             class: data.class
         });
@@ -245,13 +244,14 @@
 
     angular.module('ovTopo')
     .factory('TopoSelectService',
-        ['$log', 'FnService', 'FlashService', 'TopoPanelService',
-            'TopoTrafficService',
+        ['$log', 'FnService', 'FlashService', 'WebSocketService',
+            'TopoPanelService', 'TopoTrafficService',
 
-        function (_$log_, _fs_, _flash_, _tps_, _tts_) {
+        function (_$log_, _fs_, _flash_, _wss_, _tps_, _tts_) {
             $log = _$log_;
             fs = _fs_;
             flash = _flash_;
+            wss = _wss_;
             tps = _tps_;
             tts = _tts_;
 
diff --git a/web/gui/src/main/webapp/app/view/topo/topoTraffic.js b/web/gui/src/main/webapp/app/view/topo/topoTraffic.js
index 30adc23..1ce8810 100644
--- a/web/gui/src/main/webapp/app/view/topo/topoTraffic.js
+++ b/web/gui/src/main/webapp/app/view/topo/topoTraffic.js
@@ -23,7 +23,7 @@
     'use strict';
 
     // injected refs
-    var $log, fs, flash;
+    var $log, fs, flash, wss;
 
     // api to topoForce
     var api;
@@ -34,7 +34,6 @@
      findLinkById( id )
      hovered()
      validateSelectionContext()
-     sendEvent( type, {payload} )
      */
 
     // constants
@@ -86,7 +85,7 @@
         }
 
         if (api.validateSelectionContext()) {
-            api.sendEvent('requestDeviceLinkFlows', {
+            wss.sendEvent('requestDeviceLinkFlows', {
                 ids: api.selectOrder(),
                 hover: hoverValid() ? hov.id : ''
             });
@@ -102,7 +101,7 @@
         }
 
         if (api.validateSelectionContext()) {
-            api.sendEvent('requestRelatedIntents', {
+            wss.sendEvent('requestRelatedIntents', {
                 ids: api.selectOrder(),
                 hover: hoverValid() ? hov.id : ''
             });
@@ -114,7 +113,7 @@
     //  Traffic requests
 
     function cancelTraffic() {
-        api.sendEvent('cancelTraffic');
+        wss.sendEvent('cancelTraffic');
     }
 
     // invoked in response to change in selection and/or mouseover/out:
@@ -132,28 +131,28 @@
     // keystroke-right-arrow (see topo.js)
     function showNextIntentAction() {
         hoverMode = hoverModeNone;
-        api.sendEvent('requestNextRelatedIntent');
+        wss.sendEvent('requestNextRelatedIntent');
         flash.flash('>');
     }
 
     // keystroke-left-arrow (see topo.js)
     function showPrevIntentAction() {
         hoverMode = hoverModeNone;
-        api.sendEvent('requestPrevRelatedIntent');
+        wss.sendEvent('requestPrevRelatedIntent');
         flash.flash('<');
     }
 
     // keystroke-W (see topo.js)
     function showSelectedIntentTrafficAction() {
         hoverMode = hoverModeNone;
-        api.sendEvent('requestSelectedIntentTraffic');
+        wss.sendEvent('requestSelectedIntentTraffic');
         flash.flash('Traffic on Selected Path');
     }
 
     // keystroke-A (see topo.js)
     function showAllTrafficAction() {
         hoverMode = hoverModeAll;
-        api.sendEvent('requestAllTraffic');
+        wss.sendEvent('requestAllTraffic');
         flash.flash('All Traffic');
     }
 
@@ -169,7 +168,7 @@
 
     function addHostIntentAction () {
         var so = api.selectOrder();
-        api.sendEvent('addHostIntent', {
+        wss.sendEvent('addHostIntent', {
             one: so[0],
             two: so[1],
             ids: so
@@ -179,7 +178,7 @@
 
     function addMultiSourceIntentAction () {
         var so = api.selectOrder();
-        api.sendEvent('addMultiSourceIntent', {
+        wss.sendEvent('addMultiSourceIntent', {
             src: so.slice(0, so.length - 1),
             dst: so[so.length - 1],
             ids: so
@@ -200,12 +199,13 @@
 
     angular.module('ovTopo')
     .factory('TopoTrafficService',
-        ['$log', 'FnService', 'FlashService',
+        ['$log', 'FnService', 'FlashService', 'WebSocketService',
 
-        function (_$log_, _fs_, _flash_) {
+        function (_$log_, _fs_, _flash_, _wss_) {
             $log = _$log_;
             fs = _fs_;
             flash = _flash_;
+            wss = _wss_;
 
             function initTraffic(_api_) {
                 api = _api_;