refactor availableServices

This commit is contained in:
Iuri Matias 2017-12-16 10:54:17 -05:00
parent a76dbb69b9
commit fb8d3c4c0a
1 changed files with 13 additions and 15 deletions

View File

@ -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();