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

View File

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

View File

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

View File

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