ONOS-1749, ONOS-2386 - GUI -- Can jump to selected device in Device View from Topo View by clicking on Detail Panel title or action button. Bug fix for deselecting action buttons on Device View upon details panel close.

Change-Id: If0afe487cf486c17cca7a5950e2a49d3bd8d28bb
diff --git a/web/gui/src/main/webapp/app/view/device/device.js b/web/gui/src/main/webapp/app/view/device/device.js
index 1f8f1cfb..ecfcc98 100644
--- a/web/gui/src/main/webapp/app/view/device/device.js
+++ b/web/gui/src/main/webapp/app/view/device/device.js
@@ -22,13 +22,13 @@
     'use strict';
 
     // injected refs
-    var $log, $scope, fs, mast, ps, wss, is, ns;
+    var $log, $scope, $location, fs, mast, ps, wss, is, ns;
 
     // internal state
     var detailsPanel,
         pStartY, pHeight,
         top, bottom, iconDiv,
-        wSize, selRow;
+        wSize;
 
     // constants
     var topPdg = 13,
@@ -60,8 +60,8 @@
         div.select('g').attr('transform', 'translate(25, 0) rotate(45)');
 
         div.on('click', function () {
+            $scope.selId = null;
             detailsPanel.hide();
-            selRow.removeClass('selected');
         });
     }
 
@@ -187,28 +187,39 @@
 
     angular.module('ovDevice', [])
     .controller('OvDeviceCtrl',
-        ['$log', '$scope', 'TableBuilderService', 'FnService',
+        ['$log', '$scope', '$location', 'TableBuilderService', 'FnService',
             'MastService', 'PanelService', 'WebSocketService', 'IconService',
             'NavService',
 
-        function (_$log_, _$scope_,
+        function (_$log_, _$scope_, _$location_,
                   tbs, _fs_, _mast_, _ps_, _wss_, _is_, _ns_) {
             $log = _$log_;
             $scope = _$scope_;
+            $location = _$location_;
             fs = _fs_;
             mast = _mast_;
             ps = _ps_;
             wss = _wss_;
             is = _is_;
             ns = _ns_;
-            var handlers = {};
+            var params = $location.search(),
+                handlers = {};
             $scope.panelData = [];
             $scope.flowTip = 'Show flow view for selected device';
             $scope.portTip = 'Show port view for selected device';
             $scope.groupTip = 'Show group view for selected device';
 
+            // details panel handlers
+            handlers[detailsResp] = respDetailsCb;
+            wss.bindHandlers(handlers);
+
+            // query for if a certain device needs to be highlighted
+            if (params.hasOwnProperty('devId')) {
+                $scope.selId = params['devId'];
+                wss.sendEvent(detailsReq, { id: $scope.selId });
+            }
+
             function selCb($event, row) {
-                selRow = angular.element($event.currentTarget);
                 if ($scope.selId) {
                     wss.sendEvent(detailsReq, { id: row.id });
                 } else {
@@ -223,10 +234,6 @@
                 selCb: selCb
             });
 
-            // details panel handlers
-            handlers[detailsResp] = respDetailsCb;
-            wss.bindHandlers(handlers);
-
             $scope.nav = function (path) {
                 if ($scope.selId) {
                     ns.navTo(path, { devId: $scope.selId });
@@ -240,44 +247,44 @@
             $log.log('OvDeviceCtrl has been created');
         }])
 
-        .directive('deviceDetailsPanel', ['$rootScope', '$window',
-        function ($rootScope, $window) {
-            return function (scope) {
+    .directive('deviceDetailsPanel', ['$rootScope', '$window',
+    function ($rootScope, $window) {
+        return function (scope) {
 
-                function heightCalc() {
-                    pStartY = fs.noPxStyle(d3.select('.tabular-header'), 'height')
-                                            + mast.mastHeight() + topPdg;
-                    wSize = fs.windowSize(pStartY);
-                    pHeight = wSize.height;
+            function heightCalc() {
+                pStartY = fs.noPxStyle(d3.select('.tabular-header'), 'height')
+                                        + mast.mastHeight() + topPdg;
+                wSize = fs.windowSize(pStartY);
+                pHeight = wSize.height;
+            }
+            heightCalc();
+
+            createDetailsPane();
+
+            scope.$watch('panelData', function () {
+                if (!fs.isEmptyObject(scope.panelData)) {
+                    populateDetails(scope.panelData);
+                    detailsPanel.show();
                 }
-                heightCalc();
+            });
 
-                createDetailsPane();
-
-                scope.$watch('panelData', function () {
+            $rootScope.$watchCollection(
+                function () {
+                    return {
+                        h: $window.innerHeight,
+                        w: $window.innerWidth
+                    };
+                }, function () {
                     if (!fs.isEmptyObject(scope.panelData)) {
+                        heightCalc();
                         populateDetails(scope.panelData);
-                        detailsPanel.show();
                     }
-                });
+                }
+            );
 
-                $rootScope.$watchCollection(
-                    function () {
-                        return {
-                            h: $window.innerHeight,
-                            w: $window.innerWidth
-                        };
-                    }, function () {
-                        if (!fs.isEmptyObject(scope.panelData)) {
-                            heightCalc();
-                            populateDetails(scope.panelData);
-                        }
-                    }
-                );
-
-                scope.$on('$destroy', function () {
-                    ps.destroyPanel(pName);
-                });
-            };
-        }]);
+            scope.$on('$destroy', function () {
+                ps.destroyPanel(pName);
+            });
+        };
+    }]);
 }());