move dashboard api into dashboard module

This commit is contained in:
Iuri Matias 2018-03-13 06:24:07 -04:00
parent 71510ddd57
commit 8e9a357448
4 changed files with 36 additions and 26 deletions

View File

@ -27,6 +27,36 @@ class Dashboard {
let console, monitor;
let self = this;
let plugin = this.plugins.createPlugin('dashboard', {});
plugin.registerAPICall(
'ws',
'/embark/dashboard',
(ws, req) => {
let dashboardState = { contractsState: [], environment: "", status: "", availableServices: [] };
// TODO: doesn't feel quite right, should be refactored into a shared
// dashboard state
self.events.request('setDashboardState');
self.events.on('contractsState', (contracts) => {
dashboardState.contractsState = [];
contracts.forEach(function (row) {
dashboardState.contractsState.push({contractName: row[0], address: row[1], status: row[2]});
});
ws.send(JSON.stringify(dashboardState));
});
self.events.on('status', (status) => {
dashboardState.status = status;
ws.send(JSON.stringify(dashboardState));
});
self.events.on('servicesState', (servicesState) => {
dashboardState.availableServices = servicesState;
ws.send(JSON.stringify(dashboardState));
});
}
);
async.waterfall([
function startConsole(callback) {
console = new Console({

View File

@ -16,7 +16,7 @@ class WebServer {
this.port = options.port || this.webServerConfig.port;
this.events.emit("status", __("Starting Server"));
this.server = new Server({logger: this.logger, host: this.host, port: this.port, events: this.events});
this.server = new Server({logger: this.logger, host: this.host, port: this.port, events: this.events, plugins: this.plugins});
this.setServiceCheck();
this.listenToCommands();

View File

@ -13,6 +13,7 @@ class Server {
this.port = options.port || 8000;
this.hostname = options.host || 'localhost';
this.logger = options.logger;
this.plugins = options.plugins;
}
start(callback) {
@ -39,30 +40,10 @@ class Server {
});
});
app.ws('/embark/dashboard', function(ws, req) {
let dashboardState = { contractsState: [], environment: "", status: "", availableServices: [] };
// TODO: doesn't feel quite right, should be refactored into a shared
// dashboard state
self.events.request('setDashboardState');
self.events.on('contractsState', (contracts) => {
dashboardState.contractsState = [];
contracts.forEach(function (row) {
dashboardState.contractsState.push({contractName: row[0], address: row[1], status: row[2]});
});
ws.send(JSON.stringify(dashboardState));
});
self.events.on('status', (status) => {
dashboardState.status = status;
ws.send(JSON.stringify(dashboardState));
});
self.events.on('servicesState', (servicesState) => {
dashboardState.availableServices = servicesState;
ws.send(JSON.stringify(dashboardState));
});
});
let apiCalls = self.plugins.getPluginsProperty("apiCalls", "apiCalls");
for (let apiCall of apiCalls) {
app[apiCall.method].apply(app, [apiCall.endpoint, apiCall.cb]);
}
app.get('/embark', function (req, res) {
res.send('Welcome to Embark')

View File

@ -1,6 +1,5 @@
pragma solidity ^0.4.17;
contract AnotherStorage {
address public simpleStorageAddress;
address simpleStorageAddress2;