From 6e3aa2e399ee61e231cdc727a02e7f8959e6b070 Mon Sep 17 00:00:00 2001
From: Leonardo Menezes <mail@lmenezes.com>
Date: Sat, 14 Apr 2018 16:49:25 +0200
Subject: [PATCH] add cluster status text to navbar and tab title

closes #134
---
 public/js/app.js                | 32 ++++++++++++--------------------
 public/navbar.html              |  2 +-
 src/app/shared/services/page.js | 32 ++++++++++++--------------------
 3 files changed, 25 insertions(+), 41 deletions(-)

diff --git a/public/js/app.js b/public/js/app.js
index ba2cf1a..1c89145 100644
--- a/public/js/app.js
+++ b/public/js/app.js
@@ -3008,9 +3008,6 @@ angular.module('cerebro').factory('ModalService', ['$sce', function($sce) {
 angular.module('cerebro').factory('PageService', ['DataService', '$rootScope',
   '$document', function(DataService, $rootScope, $document) {
 
-    var clusterName;
-    var clusterStatus;
-
     var link = $document[0].querySelector('link[rel~=\'icon\']');
 
     var colors = {
@@ -3020,35 +3017,30 @@ angular.module('cerebro').factory('PageService', ['DataService', '$rootScope',
       black: 'img/black-favicon.png'
     };
 
-    this.setup = function(newName, newStatus) {
-      setPageTitle(newName);
-      setFavIconColor(newStatus);
+    this.setup = function(name, status) {
+      setPageTitle(name, status);
+      setFavIconColor(status);
     };
 
-    var setPageTitle = function(newClusterName) {
-      if (clusterName !== newClusterName) {
-        if (newClusterName) {
-          clusterName = newClusterName;
-          $rootScope.title = 'cerebro[' + clusterName + ']';
-        } else {
-          clusterName = undefined;
-          $rootScope.title = 'cerebro - no connection';
-        }
+    var setPageTitle = function(name, status) {
+      if (name) {
+        $rootScope.title = name + '[' + status + ']';
+      } else {
+        $rootScope.title = 'cerebro - no connection';
       }
     };
 
-    var setFavIconColor = function(newClusterStatus) {
+    var setFavIconColor = function(status) {
       if (link) {
-        clusterStatus = newClusterStatus;
-        var url = clusterStatus ? colors[clusterStatus] : colors.black;
         link.type = 'image/png';
-        link.href = url;
+        link.href = colors[status] || colors.black;
       }
     };
 
     return this;
 
-  }]);
+  }
+]);
 
 angular.module('cerebro').factory('RefreshService',
   function($rootScope, $timeout) {
diff --git a/public/navbar.html b/public/navbar.html
index adceb08..b1a8478 100644
--- a/public/navbar.html
+++ b/public/navbar.html
@@ -77,7 +77,7 @@
         </li>
         <li class="hidden-xs">
           <a class="nav-item nav-link">
-            <span ng-show="host">{{host}}</span>
+            <span ng-show="host">{{host}} [{{status}}]</span>
           </a>
         </li>
         <li>
diff --git a/src/app/shared/services/page.js b/src/app/shared/services/page.js
index 4b3c878..b128484 100644
--- a/src/app/shared/services/page.js
+++ b/src/app/shared/services/page.js
@@ -1,9 +1,6 @@
 angular.module('cerebro').factory('PageService', ['DataService', '$rootScope',
   '$document', function(DataService, $rootScope, $document) {
 
-    var clusterName;
-    var clusterStatus;
-
     var link = $document[0].querySelector('link[rel~=\'icon\']');
 
     var colors = {
@@ -13,32 +10,27 @@ angular.module('cerebro').factory('PageService', ['DataService', '$rootScope',
       black: 'img/black-favicon.png'
     };
 
-    this.setup = function(newName, newStatus) {
-      setPageTitle(newName);
-      setFavIconColor(newStatus);
+    this.setup = function(name, status) {
+      setPageTitle(name, status);
+      setFavIconColor(status);
     };
 
-    var setPageTitle = function(newClusterName) {
-      if (clusterName !== newClusterName) {
-        if (newClusterName) {
-          clusterName = newClusterName;
-          $rootScope.title = 'cerebro[' + clusterName + ']';
-        } else {
-          clusterName = undefined;
-          $rootScope.title = 'cerebro - no connection';
-        }
+    var setPageTitle = function(name, status) {
+      if (name) {
+        $rootScope.title = name + '[' + status + ']';
+      } else {
+        $rootScope.title = 'cerebro - no connection';
       }
     };
 
-    var setFavIconColor = function(newClusterStatus) {
+    var setFavIconColor = function(status) {
       if (link) {
-        clusterStatus = newClusterStatus;
-        var url = clusterStatus ? colors[clusterStatus] : colors.black;
         link.type = 'image/png';
-        link.href = url;
+        link.href = colors[status] || colors.black;
       }
     };
 
     return this;
 
-  }]);
+  }
+]);
-- 
GitLab