[pve-devel] [PATCH manager 2/7] refactor health icons

Dominik Csapak d.csapak at proxmox.com
Tue Nov 22 12:32:10 CET 2016


instead of setting them manually every time, factor them out in a
get_health_icon function

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 www/manager6/Utils.js       | 30 ++++++++++++++++++++++++++++++
 www/manager6/dc/Health.js   |  4 ++--
 www/manager6/dc/NodeView.js |  8 ++------
 3 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js
index c824b97..f86eea8 100644
--- a/www/manager6/Utils.js
+++ b/www/manager6/Utils.js
@@ -69,6 +69,36 @@ Ext.define('PVE.Utils', { utilities: {
 	solaris: 'Solaris Kernel'
     },
 
+    get_health_icon: function(state, circle) {
+	if (circle === undefined) {
+	    circle = false;
+	}
+
+	if (state === undefined) {
+	    state = 'uknown';
+	}
+
+	var icon = 'faded fa-question';
+	switch(state) {
+	    case 'good':
+		icon = 'good fa-check';
+		break;
+	    case 'warning':
+		icon = 'warning fa-exclamation';
+		break;
+	    case 'critical':
+		icon = 'critical fa-times';
+		break;
+	    default: break;
+	}
+
+	if (circle) {
+	    icon += '-circle';
+	}
+
+	return icon;
+    },
+
     render_kvm_ostype: function (value) {
 	if (!value) {
 	    return gettext('Other OS types');
diff --git a/www/manager6/dc/Health.js b/www/manager6/dc/Health.js
index 1215857..f4e78e3 100644
--- a/www/manager6/dc/Health.js
+++ b/www/manager6/dc/Health.js
@@ -25,7 +25,7 @@ Ext.define('PVE.dc.Health', {
 	}
 
 	var cluster = {
-	    iconCls:'good fa-check-circle',
+	    iconCls: PVE.Utils.get_health_icon('good', true),
 	    text: gettext("Standalone node - no cluster defined")
 	};
 
@@ -48,7 +48,7 @@ Ext.define('PVE.dc.Health', {
 		cluster.text += gettext("Quorate") + ": ";
 		cluster.text += PVE.Utils.format_boolean(item.data.quorate);
 		if (item.data.quorate != 1) {
-		    cluster.iconCls = 'critical fa-times-circle';
+		    cluster.iconCls = PVE.Utils.get_health_icon('critical', true);
 		}
 
 		numNodes = item.data.nodes;
diff --git a/www/manager6/dc/NodeView.js b/www/manager6/dc/NodeView.js
index af5c6e0..e65235e 100644
--- a/www/manager6/dc/NodeView.js
+++ b/www/manager6/dc/NodeView.js
@@ -25,12 +25,8 @@ Ext.define('PVE.dc.NodeView', {
 	    sortable: true,
 	    dataIndex: 'online',
 	    renderer: function(value) {
-		var icon = '<i class="fa good fa-check"></i>';
-		if (!value) {
-		    icon = '<i class="fa critical fa-times"></i>';
-		}
-
-		return icon;
+		var cls = (value)?'good':'critical';
+		return  '<i class="fa ' + PVE.Utils.get_health_icon(cls) + '"><i/>';
 	    }
 	},
 	{
-- 
2.1.4





More information about the pve-devel mailing list