mirror of
https://github.com/avatao-content/frontend-tutorial-framework
synced 2025-07-02 06:06:24 +00:00
Implement ProcessLogService and hook it up to existing log features
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user