From fb8d3c4c0ab8a984d6246f124993a2310715bb76 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sat, 16 Dec 2017 10:54:17 -0500 Subject: [PATCH] refactor availableServices --- lib/dashboard/monitor.js | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/lib/dashboard/monitor.js b/lib/dashboard/monitor.js index 60be81b8..03675141 100644 --- a/lib/dashboard/monitor.js +++ b/lib/dashboard/monitor.js @@ -1,5 +1,3 @@ -/*jshint esversion: 6 */ - let blessed = require("blessed"); let CommandHistory = require('./command_history.js'); @@ -41,20 +39,20 @@ class Dashboard { } availableServices(_services) { - let services = []; - let check; - for (check in _services) { - let checkObj = _services[check]; - if (checkObj.status === 'on') { - services.push(checkObj.name.green); - } else if (checkObj.status === 'off') { - services.push(checkObj.name.red); - } else if (checkObj.status === 'warn') { - services.push(checkObj.name.grey); - } else { - services.push(checkObj.name); + let stateColors = { + 'on': 'green', + 'off': 'red', + 'warn': 'grey' + }; + + let services = Object.keys(_services).map((service) => { + let checkObj = _services[service]; + if (checkObj.status in stateColors) { + let color = stateColors[checkObj.status]; + return checkObj.name[color]; } - } + return checkObj.name; + }); this.progress.setContent(services.join('\n')); this.screen.render();