GUI -- Table views auto refresh every two seconds while maintaining selected items.

Change-Id: Idbb27cf1977ba5b9410b1d75ce12971195291091
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 b2e1cc8..d8543fb 100644
--- a/web/gui/src/main/webapp/app/fw/widget/table.js
+++ b/web/gui/src/main/webapp/app/fw/widget/table.js
@@ -189,7 +189,8 @@
             function (_$log_, _is_) {
             return {
                 scope: {
-                    ctrlCallback: '&sortCallback'
+                    sortCallback: '&',
+                    sortParams: '='
                 },
                 link: function (scope, element) {
                     $log = _$log_;
@@ -204,8 +205,11 @@
 
                         if (col.attr('sortable') === '') {
                             updateSortDirection(col);
-                            scope.ctrlCallback({
-                                requestParams: sortRequestParams()
+                            scope.$apply(function () {
+                                scope.sortParams = sortRequestParams();
+                            });
+                            scope.sortCallback({
+                                requestParams: scope.sortParams
                             });
                         }
                     });
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 ef3fd66..84f11b7 100644
--- a/web/gui/src/main/webapp/app/fw/widget/tableBuilder.js
+++ b/web/gui/src/main/webapp/app/fw/widget/tableBuilder.js
@@ -21,7 +21,10 @@
     'use strict';
 
     // injected refs
-    var $log, fs, wss, ts;
+    var $log, $interval, fs, wss, ts;
+
+    // constants
+    var refreshInterval = 2000;
 
     // example params to buildTable:
     // {
@@ -40,9 +43,11 @@
             root = o.tag + 's',
             req = o.tag + 'DataRequest',
             resp = o.tag + 'DataResponse',
-            onSel = fs.isF(o.selCb);
+            onSel = fs.isF(o.selCb),
+            promise;
 
         o.scope.tableData = [];
+        o.scope.sortParams = {};
 
         function respCb(data) {
             o.scope.tableData = data[root];
@@ -55,16 +60,15 @@
         }
         o.scope.sortCallback = sortCb;
 
-        function selCb($event, sel) {
-            o.scope.sel = (o.scope.sel === sel) ? null : sel;
-            onSel && onSel($event, o.scope.sel);
+        function selCb($event, selRow) {
+            o.scope.selId = (o.scope.selId === selRow.id) ? null : selRow.id;
+            onSel && onSel($event, selRow);
         }
         o.scope.selectCallback = selCb;
 
-        function refresh() {
+        function refresh(params) {
             $log.debug('Refreshing ' + root + ' page');
-            ts.resetSort();
-            sortCb();
+            sortCb(params);
         }
         o.scope.refresh = refresh;
 
@@ -75,17 +79,26 @@
         o.scope.$on('$destroy', function () {
             wss.unbindHandlers(handlers);
             ts.resetSort();
+            if (angular.isDefined(promise)) {
+                $interval.cancel(promise);
+                promise = undefined;
+            }
         });
 
         sortCb();
+
+        promise = $interval(function () {
+            refresh(o.scope.sortParams);
+        }, refreshInterval);
     }
 
     angular.module('onosWidget')
         .factory('TableBuilderService',
-        ['$log', 'FnService', 'WebSocketService', 'TableService',
+        ['$log', '$interval', 'FnService', 'WebSocketService', 'TableService',
 
-            function (_$log_, _fs_, _wss_, _ts_) {
+            function (_$log_, _$interval_, _fs_, _wss_, _ts_) {
                 $log = _$log_;
+                $interval = _$interval_;
                 fs = _fs_;
                 wss = _wss_;
                 ts = _ts_;