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

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