GUI -- toggle state for some of the topo buttons, now persisted via cookie.

Change-Id: Ie80c840635fcc7b87705d73abf77b7bc6df03f18
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 402ad86..f40beb1 100644
--- a/web/gui/src/main/webapp/app/view/topo/topo.js
+++ b/web/gui/src/main/webapp/app/view/topo/topo.js
@@ -45,8 +45,8 @@
         // thus, deferred to here...
         actionMap = {
             I: [toggleInstances, 'Toggle ONOS instances panel'],
-            O: [tps.toggleSummary, 'Toggle ONOS summary panel'],
-            D: [tps.toggleDetails, 'Disable / enable details panel'],
+            O: [toggleSummary, 'Toggle ONOS summary panel'],
+            D: [toggleDetails, 'Disable / enable details panel'],
 
             H: [tfs.toggleHosts, 'Toggle host visibility'],
             M: [tfs.toggleOffline, 'Toggle offline visibility'],
@@ -95,27 +95,26 @@
 
     // --- Keystroke functions -------------------------------------------
 
-    // NOTE: this really belongs in the TopoPanelService -- but how to
-    //       cleanly link in the updateDeviceColors() call? To be fixed later.
     function toggleInstances(x) {
-        if (x === 'keyev') {
-            tis.toggle();
-            updatePrefsState('insts', tis.isVisible());
-        } else if (x) {
-            tis.show();
-        } else {
-            tis.hide();
-        }
+        updatePrefsState('insts', tis.toggle(x));
         tfs.updateDeviceColors();
     }
 
-    function toggleMap(x) {
-        var on = (x === 'keyev') ? !sus.visible(mapG) : !!x;
-        sus.visible(mapG, on);
-        updatePrefsState('bg', on);
+    function toggleSummary(x) {
+        updatePrefsState('summary', tps.toggleSummary(x));
     }
 
-    //  TODO: need wrapper functions for state changes needed in cookies
+    function toggleDetails(x) {
+        updatePrefsState('detail', tps.toggleDetails(x));
+    }
+
+    function toggleMap(x) {
+        var on = (x === 'keyev') ? !sus.visible(mapG) : !!x,
+            verb = on ? 'Show' : 'Hide';
+        sus.visible(mapG, on);
+        updatePrefsState('bg', on);
+        flash.flash(verb + ' background map');
+    }
 
     function resetZoom() {
         zoomer.reset();
@@ -250,20 +249,8 @@
 
     // --- User Preferemces ----------------------------------------------
 
-    var defaultPrefsState = {
-        bg: 1,
-        insts: 1,
-        summary: 1,
-        detail: 1,
-        hosts: 0
-    };
-
     var prefsState = {};
 
-    function topoDefPrefs() {
-        return angular.extend({}, defaultPrefsState);
-    }
-
     function updatePrefsState(what, b) {
         prefsState[what] = b ? 1 : 0;
         ps.setPrefs('topo_prefs', prefsState);
@@ -277,8 +264,8 @@
         $log.debug('TOPO---- Prefs State:', prefsState);
 
         toggleInstances(prefsState.insts);
-        tps.toggleSummary(prefsState.summary);
-        tps.toggleDetails(prefsState.detail);
+        toggleSummary(prefsState.summary);
+        toggleDetails(prefsState.detail);
     }
 
 
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 4378e6d..6d52a37 100644
--- a/web/gui/src/main/webapp/app/view/topo/topoEvent.js
+++ b/web/gui/src/main/webapp/app/view/topo/topoEvent.js
@@ -86,7 +86,6 @@
                 openListener = wss.addOpenListener(wsOpen);
                 wss.bindHandlers(handlerMap);
                 wss.sendEvent('topoStart');
-                wss.sendEvent('requestSummary');
                 $log.debug('topo comms started');
             }
 
diff --git a/web/gui/src/main/webapp/app/view/topo/topoInst.js b/web/gui/src/main/webapp/app/view/topo/topoInst.js
index a7093d3..7e92997 100644
--- a/web/gui/src/main/webapp/app/view/topo/topoInst.js
+++ b/web/gui/src/main/webapp/app/view/topo/topoInst.js
@@ -23,7 +23,7 @@
     'use strict';
 
     // injected refs
-    var $log, ps, sus, gs, ts, fs;
+    var $log, ps, sus, gs, ts, fs, flash;
 
     // api from topo
     var api;
@@ -309,20 +309,49 @@
         oiShowMaster = false;
     }
 
+    function showInsts() {
+        oiBox.show();
+    }
+
+    function hideInsts() {
+        oiBox.hide();
+    }
+
+    function toggleInsts(x) {
+        var kev = (x === 'keyev'),
+            on,
+            verb;
+
+        if (kev) {
+            on = oiBox.toggle();
+        } else {
+            on = !!x;
+            if (on) {
+                showInsts();
+            } else {
+                hideInsts();
+            }
+        }
+        verb = on ? 'Show' : 'Hide';
+        flash.flash(verb + ' instances panel');
+        return on;
+    }
+
     // ==========================
 
     angular.module('ovTopo')
     .factory('TopoInstService',
         ['$log', 'PanelService', 'SvgUtilService', 'GlyphService',
-            'ThemeService', 'FnService',
+            'ThemeService', 'FnService', 'FlashService',
 
-        function (_$log_, _ps_, _sus_, _gs_, _ts_, _fs_) {
+        function (_$log_, _ps_, _sus_, _gs_, _ts_, _fs_, _flash_) {
             $log = _$log_;
             ps = _ps_;
             sus = _sus_;
             gs = _gs_;
             ts = _ts_;
             fs = _fs_;
+            flash = _flash_;
 
             return {
                 initInst: initInst,
@@ -335,9 +364,9 @@
                 cancelAffinity: cancelAffinity,
 
                 isVisible: function () { return oiBox.isVisible(); },
-                show: function () { oiBox.show(); },
-                hide: function () { oiBox.hide(); },
-                toggle: function () { oiBox.toggle(); },
+                show: showInsts,
+                hide: hideInsts,
+                toggle: toggleInsts,
                 showMaster: function () { return oiShowMaster; }
             };
         }]);
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 d95c4f5..579ebde 100644
--- a/web/gui/src/main/webapp/app/view/topo/topoPanel.js
+++ b/web/gui/src/main/webapp/app/view/topo/topoPanel.js
@@ -226,7 +226,9 @@
     }
 
     function toggleSummary(x) {
-        var on = (x === 'keyev') ? !summaryPanel.isVisible() : !!x;
+        var kev = (x === 'keyev'),
+            on = kev ? !summaryPanel.isVisible() : !!x,
+            verb = on ? 'Show' : 'Hide';
 
         if (on) {
             // ask server to start sending summary data.
@@ -235,6 +237,8 @@
         } else {
             hideSummaryPanel();
         }
+        flash.flash(verb + ' summary panel');
+        return on;
     }
 
     // === -----------------------------------------------------
@@ -292,16 +296,21 @@
     }
 
     function toggleDetails(x) {
-        useDetails = (x === 'keyev') ? !useDetails : !!x;
+        var kev = (x === 'keyev'),
+            verb;
+
+        useDetails = kev ? !useDetails : !!x;
+        verb = useDetails ? 'Enable' : 'Disable';
+
         if (useDetails) {
-            flash.flash('Enable details panel');
             if (haveDetails) {
                 showDetailPanel();
             }
         } else {
-            flash.flash('Disable details panel');
             hideDetailPanel();
         }
+        flash.flash(verb + ' details panel');
+        return useDetails;
     }
 
     // ==========================