ONOS-2074, ONOS-2075 - GUI -- App View Control Button state and icon bug fixes.

Change-Id: Icdaf5ca57963c6e4f30618cb6468c980ac3a786d
diff --git a/web/gui/src/main/webapp/app/directives.js b/web/gui/src/main/webapp/app/directives.js
index f04eca2..bac559b 100644
--- a/web/gui/src/main/webapp/app/directives.js
+++ b/web/gui/src/main/webapp/app/directives.js
@@ -72,8 +72,11 @@
                     iconSize: '@'
                 },
                 link: function (scope, element, attrs) {
-                    is.loadEmbeddedIcon(d3.select(element[0]),
-                                        scope.iconId, scope.iconSize);
+                    attrs.$observe('iconId', function () {
+                        var div = d3.select(element[0]);
+                        div.selectAll('*').remove();
+                        is.loadEmbeddedIcon(div, scope.iconId, scope.iconSize);
+                    });
                 }
             };
         }])
diff --git a/web/gui/src/main/webapp/app/view/app/app.html b/web/gui/src/main/webapp/app/view/app/app.html
index 0243b5a..f2e4dd3 100644
--- a/web/gui/src/main/webapp/app/view/app/app.html
+++ b/web/gui/src/main/webapp/app/view/app/app.html
@@ -56,7 +56,7 @@
                     </td>
                 </tr>
 
-                <tr ng-repeat="app in tableData track by app.id"
+                <tr ng-repeat="app in tableData"
                     ng-click="selectCallback($event, app)"
                     ng-class="{selected: app.id === selId}"
                     ng-repeat-done>
diff --git a/web/gui/src/main/webapp/app/view/app/app.js b/web/gui/src/main/webapp/app/view/app/app.js
index 1918f3a..55ccd94 100644
--- a/web/gui/src/main/webapp/app/view/app/app.js
+++ b/web/gui/src/main/webapp/app/view/app/app.js
@@ -33,7 +33,6 @@
         'FnService', 'TableBuilderService', 'WebSocketService', 'UrlFnService',
 
     function ($log, $scope, $http, fs, tbs, wss, ufs) {
-        var refreshCtrls;
         $scope.ctrlBtnState = {};
 
         function selCb($event, row) {
@@ -41,28 +40,28 @@
             $scope.ctrlBtnState.selection = !!$scope.selId;
             $log.debug('Got a click on:', row);
 
-            refreshCtrls = function () {
-                if ($scope.ctrlBtnState.selection) {
-                    $scope.ctrlBtnState.installed = row.state === INSTALLED;
-                    $scope.ctrlBtnState.active = row.state === ACTIVE;
-                } else {
-                    $scope.ctrlBtnState.installed = false;
-                    $scope.ctrlBtnState.active = false;
-                }
-            };
-
             refreshCtrls();
         }
 
-        function respCb() {
-            refreshCtrls && refreshCtrls();
+        function refreshCtrls() {
+            var row, rowIdx;
+            if ($scope.ctrlBtnState.selection) {
+                rowIdx = fs.find($scope.selId, $scope.tableData);
+                row = rowIdx >= 0 ? $scope.tableData[rowIdx] : null;
+
+                $scope.ctrlBtnState.installed = row && row.state === INSTALLED;
+                $scope.ctrlBtnState.active = row && row.state === ACTIVE;
+            } else {
+                $scope.ctrlBtnState.installed = false;
+                $scope.ctrlBtnState.active = false;
+            }
         }
 
         tbs.buildTable({
             scope: $scope,
             tag: 'app',
             selCb: selCb,
-            respCb: respCb
+            respCb: refreshCtrls
         });
 
         $scope.appAction = function (action) {
@@ -85,14 +84,9 @@
                         'Content-Type': undefined
                     }
                 })
-                    // TODO: look for finally function to combine lines
-                    // TODO: reexamine reset input value
-                    .success(function () {
+                    .finally(function () {
                         $scope.sortCallback($scope.sortParams);
                         document.getElementById('inputFileForm').reset();
-                    })
-                    .error(function () {
-                        $scope.sortCallback($scope.sortParams);
                     });
             }
         });