Implement ProcessLogService and hook it up to existing log features

This commit is contained in:
Kristóf Tóth 2018-05-29 16:48:45 +02:00
parent 1b8a36331c
commit cfdb69987d
6 changed files with 59 additions and 15 deletions

View File

@ -27,6 +27,7 @@ import { TestmessengerComponent } from './testmessenger/testmessenger.component'
import { DeploymentNotificationService } from './services/deployment-notification.service';
import { SafePipe } from './pipes/safe.pipe';
import { ConsoleComponent } from './console/console.component';
import { ProcessLogService } from './services/processlog.service';
@NgModule({
@ -57,7 +58,8 @@ import { ConsoleComponent } from './console/console.component';
TerminadoService,
FSMUpdateService,
ProcessManagerService,
DeploymentNotificationService
DeploymentNotificationService,
ProcessLogService
],
bootstrap: [
AppComponent

View File

@ -40,7 +40,8 @@ export const config = {
console: {
route: 'console',
defaultContent: '',
rewriteContentWithNewLogs: 'stdout'
rewriteContentWithProcessLogs: 'stdout',
showLiveLogs: true
},
testmessenger: {
route: 'testmessenger'

View File

@ -5,6 +5,7 @@ import { Component, OnInit } from '@angular/core';
import { WebSocketService } from '../services/websocket.service';
import { ConsoleCommand } from './console-command';
import { config } from '../config';
import { ProcessLogService } from '../services/processlog.service';
@Component({
selector: 'app-console',
@ -13,20 +14,22 @@ import { config } from '../config';
})
export class ConsoleComponent implements OnInit {
console_content: string = config.console.defaultContent;
rewriteContentWithNewLogs: string = config.console.rewriteContentWithNewLogs;
rewriteContentWithProcessLogs: string = config.console.rewriteContentWithProcessLogs;
command_handlers = {
'write': this.writeHandler.bind(this),
'read': this.readHandler.bind(this)
};
constructor(private webSocketService: WebSocketService) {}
constructor(private webSocketService: WebSocketService,
private processLogService: ProcessLogService) {}
ngOnInit() {
this.webSocketService.connect();
this.webSocketService.observeKey<ConsoleCommand>('console').subscribe((event) => {
this.command_handlers[event.data.command](event.data);
});
this.webSocketService.observeKey<ConsoleCommand>('console').subscribe(
(event) => this.command_handlers[event.data.command](event.data)
);
this.processLogService.newLog.subscribe((data) => this.newLogHandler(data));
}
writeHandler(data: ConsoleCommand) {
@ -38,8 +41,8 @@ export class ConsoleComponent implements OnInit {
}
newLogHandler(logs: any) {
if (this.rewriteContentWithNewLogs !== '') {
const log = logs[this.rewriteContentWithNewLogs];
if (this.rewriteContentWithProcessLogs !== '') {
const log = logs[this.rewriteContentWithProcessLogs];
if (log) {
this.setContent(log);
}

View File

@ -7,7 +7,7 @@ import { Subscription } from 'rxjs';
import { WebSocketService } from '../services/websocket.service';
import { LayoutCommand } from './layout-command';
import { config } from '../config';
import { ConsoleComponent } from '../console/console.component';
import { ProcessLogService } from '../services/processlog.service';
@Component({
selector: 'app-dashboard',
@ -21,7 +21,6 @@ export class DashboardComponent implements OnInit, OnDestroy {
hide_messages: boolean = config.dashboard.hide_messages;
iframeUrl: string = config.dashboard.iframeUrl;
@ViewChild('webiframe') webiframe: ElementRef;
@ViewChild(ConsoleComponent) childConsole: ConsoleComponent;
selectedTerminalMenuItem = config.dashboard.terminalOrConsole;
command_handlers = {'layout': this.layoutHandler.bind(this),
@ -31,7 +30,8 @@ export class DashboardComponent implements OnInit, OnDestroy {
constructor(private deploymentNotificationService: DeploymentNotificationService,
private webSocketService: WebSocketService,
private changeDetectorRef: ChangeDetectorRef) {}
private changeDetectorRef: ChangeDetectorRef,
private processLogService: ProcessLogService) {}
ngOnInit() {
this.webSocketService.connect();
@ -103,9 +103,11 @@ export class DashboardComponent implements OnInit, OnDestroy {
}
setConsoleContent(logs: any) {
this.childConsole.newLogHandler(logs);
if (config.ide.showConsoleOnDeploy) {
this.selectTerminalMenuItem('console');
if (!config.console.showLiveLogs) {
this.processLogService.newLog.next(logs);
if (config.ide.showConsoleOnDeploy) {
this.selectTerminalMenuItem('console');
}
}
}
}

View File

@ -0,0 +1,5 @@
export class ProcessLogCommand {
command: string;
stdout: string;
stderr: string;
}

View File

@ -0,0 +1,31 @@
import { Injectable } from '@angular/core';
import { WebSocketService } from './websocket.service';
import { Subject } from 'rxjs/Subject';
import { ProcessLogCommand } from './processlog-command';
import { config } from '../config';
@Injectable()
export class ProcessLogService {
newLog = new Subject<any>();
showLiveLogs = config.console.showLiveLogs;
command_handlers = {
'new_log': this.newLogHandler.bind(this)
};
constructor(private webSocketService: WebSocketService) {
this.webSocketService.connect();
this.webSocketService.observeKey<ProcessLogCommand>('processlog').subscribe(
(event) => this.command_handlers[event.data.command](event.data)
);
}
newLogHandler(data: ProcessLogCommand) {
if (this.showLiveLogs) {
this.newLog.next({
stdout: data.stdout,
stderr: data.stderr
});
}
}
}