embark-area-51/lib/dashboard/monitor.js

350 lines
6.3 KiB
JavaScript
Raw Normal View History

2016-09-25 01:23:57 +00:00
/*jshint esversion: 6 */
2016-09-17 03:56:25 +00:00
var blessed = require("blessed");
2017-02-19 17:59:02 +00:00
var CommandHistory = require('./command_history.js');
var version = require('../../package.json')['version'];
2016-09-17 03:56:25 +00:00
function Dashboard(options) {
var title = (options && options.title) || "Embark " + version;
2016-09-17 03:56:25 +00:00
this.env = options.env;
2016-09-23 04:31:09 +00:00
this.console = options.console;
this.history = new CommandHistory();
2016-09-17 03:56:25 +00:00
2017-02-19 14:11:17 +00:00
this.color = (options && options.color) || "green";
this.minimal = (options && options.minimal) || false;
2016-09-17 03:56:25 +00:00
this.screen = blessed.screen({
smartCSR: true,
title: title,
dockBorders: false,
fullUnicode: true,
autoPadding: true
});
2017-02-19 14:11:17 +00:00
this.layoutLog();
this.layoutStatus();
this.layoutModules();
this.layoutCmd();
2016-09-17 03:56:25 +00:00
this.screen.key(["C-c"], function() {
process.exit(0);
});
this.logEntry = this.logEntry.bind(this);
this.setContracts = this.setContracts.bind(this);
this.availableServices = this.availableServices.bind(this);
2016-09-17 03:56:25 +00:00
this.status.setContent(this.env.green);
2016-09-17 03:56:25 +00:00
this.screen.render();
2016-09-17 03:56:25 +00:00
this.input.focus();
}
Dashboard.prototype.availableServices = function(services) {
this.progress.setContent(services.join('\n'));
this.screen.render();
};
Dashboard.prototype.setStatus = function(status) {
this.operations.setContent(status);
this.screen.render();
};
2016-09-17 03:56:25 +00:00
Dashboard.prototype.setContracts = function(contracts) {
var data = [];
data.push(["Contract Name", "Address", "Status"]);
contracts.forEach(function(row) {
data.push(row);
});
this.moduleTable.setData(data);
this.screen.render();
};
2016-09-17 03:56:25 +00:00
Dashboard.prototype.logEntry = function(text) {
this.logText.log(text);
2016-09-17 03:56:25 +00:00
this.screen.render();
};
Dashboard.prototype.layoutLog = function() {
this.log = blessed.box({
label: "Logs",
padding: 1,
width: "100%",
height: "55%",
left: "0%",
top: "42%",
border: {
2016-10-23 00:10:25 +00:00
type: "line"
2016-09-17 03:56:25 +00:00
},
style: {
fg: -1,
border: {
2016-10-23 00:10:25 +00:00
fg: this.color
}
2016-10-23 00:16:00 +00:00
}
2016-09-17 03:56:25 +00:00
});
this.logText = blessed.log({
parent: this.log,
tags: true,
width: "100%-5",
//height: '90%',
scrollable: true,
input: false,
alwaysScroll: true,
scrollbar: {
ch: " ",
inverse: true
},
keys: false,
vi: false,
mouse: true
});
this.screen.append(this.log);
};
Dashboard.prototype.layoutModules = function() {
this.modules = blessed.box({
label: "Contracts",
tags: true,
padding: 1,
width: "75%",
height: "42%",
left: "0%",
top: "0",
border: {
2016-10-23 00:10:25 +00:00
type: "line"
2016-09-17 03:56:25 +00:00
},
style: {
fg: -1,
border: {
2016-10-23 00:10:25 +00:00
fg: this.color
}
}
2016-09-17 03:56:25 +00:00
});
this.moduleTable = blessed.table({
parent: this.modules,
height: "100%",
width: "100%-5",
align: "left",
pad: 1,
margin: "auto",
2016-09-17 03:56:25 +00:00
shrink: true,
scrollable: true,
alwaysScroll: true,
scrollbar: {
ch: " ",
inverse: true
},
keys: false,
vi: false,
mouse: true,
data: [["ContractName", "Address", "Status"]]
});
this.screen.append(this.modules);
};
Dashboard.prototype.layoutAssets = function() {
this.assets = blessed.box({
label: "Asset Pipeline",
tags: true,
padding: 1,
width: "50%",
height: "55%",
left: "50%",
top: "42%",
border: {
2016-10-23 00:16:00 +00:00
type: "line"
2016-09-17 03:56:25 +00:00
},
style: {
fg: -1,
border: {
2016-10-23 00:16:00 +00:00
fg: this.color
}
}
2016-09-17 03:56:25 +00:00
});
this.assetTable = blessed.table({
parent: this.assets,
height: "100%",
width: "100%-5",
align: "left",
pad: 1,
scrollable: true,
alwaysScroll: true,
scrollbar: {
ch: " ",
inverse: true
},
keys: false,
vi: false,
mouse: true,
data: [["Name", "Size"]]
});
this.screen.append(this.assets);
};
Dashboard.prototype.layoutStatus = function() {
this.wrapper = blessed.layout({
width: "25%",
height: "42%",
top: "0%",
left: "75%",
layout: "grid"
});
this.status = blessed.box({
parent: this.wrapper,
label: "Environment",
tags: true,
padding: {
2016-10-23 00:16:00 +00:00
left: 1
2016-09-17 03:56:25 +00:00
},
width: "100%",
2016-09-17 16:28:26 +00:00
height: "20%",
2016-09-17 03:56:25 +00:00
valign: "middle",
border: {
2016-10-23 00:16:00 +00:00
type: "line"
2016-09-17 03:56:25 +00:00
},
style: {
fg: -1,
border: {
2016-10-23 00:16:00 +00:00
fg: this.color
}
}
2016-09-17 03:56:25 +00:00
});
this.operations = blessed.box({
parent: this.wrapper,
label: "Status",
tags: true,
padding: {
2016-10-23 00:16:00 +00:00
left: 1
2016-09-17 03:56:25 +00:00
},
width: "100%",
2016-09-17 16:28:26 +00:00
height: "20%",
2016-09-17 03:56:25 +00:00
valign: "middle",
border: {
2016-10-23 00:16:00 +00:00
type: "line"
2016-09-17 03:56:25 +00:00
},
style: {
fg: -1,
border: {
2016-10-23 00:16:00 +00:00
fg: this.color
}
}
2016-09-17 03:56:25 +00:00
});
this.progress = blessed.box({
parent: this.wrapper,
label: "Available Services",
tags: true,
padding: this.minimal ? {
2016-10-29 18:07:42 +00:00
left: 1
2016-09-17 03:56:25 +00:00
} : 1,
width: "100%",
2016-09-17 16:28:26 +00:00
height: "60%",
valign: "top",
2016-09-17 03:56:25 +00:00
border: {
2016-10-29 18:07:42 +00:00
type: "line"
2016-09-17 03:56:25 +00:00
},
style: {
fg: -1,
border: {
2016-10-23 00:16:00 +00:00
fg: this.color
}
}
2016-09-17 03:56:25 +00:00
});
this.screen.append(this.wrapper);
};
Dashboard.prototype.layoutCmd = function() {
this.consoleBox = blessed.box({
label: 'Console',
tags: true,
padding: 0,
width: '100%',
height: '6%',
left: '0%',
top: '95%',
border: {
2016-10-23 00:16:00 +00:00
type: 'line'
2016-09-17 03:56:25 +00:00
},
style: {
fg: 'black',
border: {
2016-10-23 00:16:00 +00:00
fg: this.color
}
}
2016-09-17 03:56:25 +00:00
});
this.input = blessed.textbox({
parent: this.consoleBox,
name: 'input',
input: true,
keys: false,
top: 0,
left: 1,
height: '50%',
width: '100%-2',
inputOnFocus: true,
style: {
fg: 'green',
bg: 'black',
focus: {
bg: 'black',
fg: 'green'
}
}
});
var self = this;
2016-09-17 04:08:16 +00:00
this.input.key(["C-c"], function() {
process.exit(0);
});
2016-09-23 05:52:59 +00:00
this.input.key(["C-w"], function() {
self.input.clearValue();
self.input.focus();
});
this.input.key(["up"], function() {
var cmd = self.history.getPreviousCommand();
self.input.setValue(cmd);
self.input.focus();
});
this.input.key(["down"], function() {
var cmd = self.history.getNextCommand();
self.input.setValue(cmd);
self.input.focus();
});
2016-09-17 03:56:25 +00:00
this.input.on('submit', function(data) {
if (data !== '') {
self.history.addCommand(data);
2017-02-16 01:08:47 +00:00
self.logText.log('console> '.bold.green + data);
2016-09-23 04:31:09 +00:00
self.console.executeCmd(data, function(result) {
self.logText.log(result);
});
2016-09-17 03:56:25 +00:00
}
self.input.clearValue();
self.input.focus();
});
this.screen.append(this.consoleBox);
};
module.exports = Dashboard;