GUI -- added 'debug' query param and cut out noisy debug console messages by default.

Change-Id: I8b3eff58677a3882c62c7f2267a5258ba2cd2593
diff --git a/web/gui/src/main/webapp/app/fw/README.txt b/web/gui/src/main/webapp/app/fw/README.txt
index 5ce4ebf..626547b 100644
--- a/web/gui/src/main/webapp/app/fw/README.txt
+++ b/web/gui/src/main/webapp/app/fw/README.txt
@@ -1,33 +1,44 @@
 # Framework related code
 
-- Util
-    - General Functions
-    - Key Handler
-    - Theme Service
-    - Alert Service
-    - Preference Service
-
-- Mast
-    - Masthead
-
-- Svg
-    - Glyph Service
-    - Icon Service
-    - Map Service
-    - Zoom Service
-
-- Layers
+- layer
     - Flash Service (transient messages)
     - Panel Service (floating panels)
     - Quick Help Service (key bindings, mouse gestures)
-    - Death Mask Service (loss of server connection)
+    - Veil Service (loss of server connection)
 
-- Remote
-    - Login Service
+- mast
+    - Masthead Service
+
+- nav
+    - Navigation Service (navigation menu)
+
+- remote
+    - REST Service
+    - URL functin Service
     - Web Socket Service
+    - Web Socket Event Service
+    - Web Socket encapsulation
 
-- Widget
-    - Table Styling Directives
+    - (Login Service) << planned
+
+- svg
+    - GeoData Service (TopoJSON map functions)
+    - Glyph Service
+    - Icon Service
+    - Map Service
+    - SVG Utilities Service
+    - Zoom Service
+
+- util
+    - General Functions
+    - Key Handler
+    - User Preference Service
+    - Randomization Service
+    - Theme Service
+
+- widget
+    - Button Service
+    - Table Service (table styling directives)
     - Table Builder Service
     - Toolbar Service
-    - Button Service
+    - Tooltip Service
diff --git a/web/gui/src/main/webapp/app/fw/layer/panel.js b/web/gui/src/main/webapp/app/fw/layer/panel.js
index 68899fb..aef71ee 100644
--- a/web/gui/src/main/webapp/app/fw/layer/panel.js
+++ b/web/gui/src/main/webapp/app/fw/layer/panel.js
@@ -185,16 +185,22 @@
                     $log.warn('Panel with ID "' + id + '" already exists');
                     return null;
                 }
-                $log.debug('creating panel:', id, settings);
+                if (fs.debugOn('widget')) {
+                    $log.debug('creating panel:', id, settings);
+                }
                 return makePanel(id, settings);
             }
 
             function destroyPanel(id) {
                 if (panels[id]) {
-                    $log.debug('destroying panel:', id);
+                    if (fs.debugOn('widget')) {
+                        $log.debug('destroying panel:', id);
+                    }
                     removePanel(id);
                 } else {
-                    $log.debug('no panel to destroy:', id);
+                    if (fs.debugOn('widget')) {
+                        $log.debug('no panel to destroy:', id);
+                    }
                 }
             }
 
diff --git a/web/gui/src/main/webapp/app/fw/layer/veil.js b/web/gui/src/main/webapp/app/fw/layer/veil.js
index 309b9f0..fc0530a 100644
--- a/web/gui/src/main/webapp/app/fw/layer/veil.js
+++ b/web/gui/src/main/webapp/app/fw/layer/veil.js
@@ -67,6 +67,7 @@
     }
 
     // function that only invokes the veil if the caller is the current view
+    // TODO: review - is this deprecated ?
     function lostServer(ctrlName, msg) {
         if ($route.current.$$route.controller === ctrlName) {
             $log.debug('VEIL-service: ', ctrlName);
diff --git a/web/gui/src/main/webapp/app/fw/remote/websocket.js b/web/gui/src/main/webapp/app/fw/remote/websocket.js
index 0ca10e9..1c03d6f 100644
--- a/web/gui/src/main/webapp/app/fw/remote/websocket.js
+++ b/web/gui/src/main/webapp/app/fw/remote/websocket.js
@@ -61,7 +61,9 @@
         $log.info('Web socket open - ', url);
         vs.hide();
 
-        $log.debug('Sending ' + pendingEvents.length + ' pending event(s)...');
+        if (fs.debugOn('txrx')) {
+            $log.debug('Sending ' + pendingEvents.length + ' pending event(s)...');
+        }
         pendingEvents.forEach(function (ev) {
             _send(ev);
         });
@@ -82,7 +84,9 @@
             $log.error('Message.data is not valid JSON', msgEvent.data, e);
             return null;
         }
-        $log.debug(' << *Rx* ', ev.event, ev.payload);
+        if (fs.debugOn('txrx')) {
+            $log.debug(' << *Rx* ', ev.event, ev.payload);
+        }
 
         if (h = handlers[ev.event]) {
             try {
@@ -140,7 +144,9 @@
     }
 
     function _send(ev) {
-        $log.debug(' *Tx* >> ', ev.event, ev.payload);
+        if (fs.debugOn('txrx')) {
+            $log.debug(' *Tx* >> ', ev.event, ev.payload);
+        }
         ws.send(JSON.stringify(ev));
     }
 
diff --git a/web/gui/src/main/webapp/app/fw/util/fn.js b/web/gui/src/main/webapp/app/fw/util/fn.js
index 6c7bb2a..3e2fb29 100644
--- a/web/gui/src/main/webapp/app/fw/util/fn.js
+++ b/web/gui/src/main/webapp/app/fw/util/fn.js
@@ -20,7 +20,20 @@
 (function () {
     'use strict';
 
-    var $window;
+    // injected services
+    var $window, $log;
+
+    // internal state
+    var debugFlags = {};
+
+
+    function _parseDebugFlags(dbgstr) {
+        var bits = dbgstr ? dbgstr.split(",") : [];
+        bits.forEach(function (key) {
+            debugFlags[key] = true;
+        });
+        $log.debug('Debug flags:', dbgstr);
+    }
 
     function isF(f) {
         return typeof f === 'function' ? f : null;
@@ -186,10 +199,18 @@
                         .replace(/\.\d*/, ''));
     }
 
+    // return true if the given debug flag was specified in the query params
+    function debugOn(tag) {
+        return debugFlags[tag];
+    }
 
     angular.module('onosUtil')
-        .factory('FnService', ['$window', function (_$window_) {
+        .factory('FnService',
+        ['$window', '$location', '$log', function (_$window_, $loc, _$log_) {
             $window = _$window_;
+            $log = _$log_;
+
+            _parseDebugFlags($loc.search().debug);
 
             return {
                 isF: isF,
@@ -201,6 +222,7 @@
                 areFunctionsNonStrict: areFunctionsNonStrict,
                 windowSize: windowSize,
                 isMobile: isMobile,
+                debugOn: debugOn,
                 find: find,
                 inArray: inArray,
                 removeFromArray: removeFromArray,
diff --git a/web/gui/src/main/webapp/app/fw/util/prefs.js b/web/gui/src/main/webapp/app/fw/util/prefs.js
index 6138ca4..02a2390 100644
--- a/web/gui/src/main/webapp/app/fw/util/prefs.js
+++ b/web/gui/src/main/webapp/app/fw/util/prefs.js
@@ -21,7 +21,7 @@
     'use strict';
 
     // injected refs
-    var $log, $cookies;
+    var $log, $cookies, fs;
 
     // internal state
     var cache = {};
@@ -106,14 +106,17 @@
 
         // FORCE cookie to be set by writing directly to document.cookie...
         document.cookie = name + '=' + encodeURIComponent(str);
-        $log.debug('<<>> Wrote cookie <'+name+'>:', str);
+        if (fs.debugOn('prefs')) {
+            $log.debug('<<>> Wrote cookie <'+name+'>:', str);
+        }
     }
 
     angular.module('onosUtil')
-    .factory('PrefsService', ['$log', '$cookies',
-        function (_$log_, _$cookies_) {
+    .factory('PrefsService', ['$log', '$cookies', 'FnService',
+        function (_$log_, _$cookies_, _fs_) {
             $log = _$log_;
             $cookies = _$cookies_;
+            fs = _fs_;
 
             return {
                 getPrefs: getPrefs,
diff --git a/web/gui/src/main/webapp/app/fw/widget/table.js b/web/gui/src/main/webapp/app/fw/widget/table.js
index d8543fb..adae2d0 100644
--- a/web/gui/src/main/webapp/app/fw/widget/table.js
+++ b/web/gui/src/main/webapp/app/fw/widget/table.js
@@ -70,7 +70,9 @@
                     cstmWidths[index] = h.attr(colWidth);
                 }
             });
-            $log.debug('Headers with custom widths: ', cstmWidths);
+            if (fs.debugOn('widget')) {
+                $log.debug('Headers with custom widths: ', cstmWidths);
+            }
         }
 
         function setTdWidths(elem) {
diff --git a/web/gui/src/main/webapp/app/fw/widget/tableBuilder.js b/web/gui/src/main/webapp/app/fw/widget/tableBuilder.js
index 3af8d60..b3d759e 100644
--- a/web/gui/src/main/webapp/app/fw/widget/tableBuilder.js
+++ b/web/gui/src/main/webapp/app/fw/widget/tableBuilder.js
@@ -69,7 +69,9 @@
 
         function startRefresh() {
             promise = $interval(function () {
-                $log.debug('Refreshing ' + root + ' page');
+                if (fs.debugOn('widget')) {
+                    $log.debug('Refreshing ' + root + ' page');
+                }
                 sortCb(o.scope.sortParams);
             }, refreshInterval);
         }