Move live log checking logic to ProcessLogService

This commit is contained in:
Kristóf Tóth 2018-05-30 11:14:48 +02:00
parent fc10db6cac
commit c889de0b05
5 changed files with 17 additions and 13 deletions

View File

@ -29,7 +29,7 @@ export class ConsoleComponent implements OnInit {
this.webSocketService.observeKey<ConsoleCommand>('console').subscribe( this.webSocketService.observeKey<ConsoleCommand>('console').subscribe(
(event) => 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)); this.processLogService.newLogs.subscribe((data) => this.newLogsHandler(data));
} }
writeHandler(data: ConsoleCommand) { writeHandler(data: ConsoleCommand) {
@ -40,7 +40,7 @@ export class ConsoleComponent implements OnInit {
this.sendContent(this.console_content); this.sendContent(this.console_content);
} }
newLogHandler(logs: any) { newLogsHandler(logs: any) {
if (this.rewriteContentWithProcessLogs !== '') { if (this.rewriteContentWithProcessLogs !== '') {
const log = logs[this.rewriteContentWithProcessLogs]; const log = logs[this.rewriteContentWithProcessLogs];
if (log) { if (log) {

View File

@ -20,7 +20,7 @@
</div> </div>
</div> </div>
<div class="tfw-ide"> <div class="tfw-ide">
<app-ide (newLog)="setConsoleContent($event)"></app-ide> <app-ide (newLogs)="setConsoleContentIfNoLiveLogs($event)"></app-ide>
</div> </div>
<div class="tfw-terminal"> <div class="tfw-terminal">
<div class="btn-group btn-group-sm flex-wrap tao-grid-center-left tfw-console-terminal-menu"> <div class="btn-group btn-group-sm flex-wrap tao-grid-center-left tfw-console-terminal-menu">

View File

@ -102,10 +102,8 @@ export class DashboardComponent implements OnInit, OnDestroy {
this.selectedTerminalMenuItem = item; this.selectedTerminalMenuItem = item;
} }
setConsoleContent(logs: any) { setConsoleContentIfNoLiveLogs(logs: any) {
if (!config.console.showLiveLogs) { this.processLogService.emitNewLogsIfNoLiveLogs(logs);
this.processLogService.newLog.next(logs);
}
if (config.ide.showConsoleOnDeploy) { if (config.ide.showConsoleOnDeploy) {
this.selectTerminalMenuItem('console'); this.selectTerminalMenuItem('console');
} }

View File

@ -63,7 +63,7 @@ export class IdeComponent implements OnInit {
language: string = config.ide.defaultLanguage; language: string = config.ide.defaultLanguage;
theme = 'cobalt'; theme = 'cobalt';
@Output() newLog = new EventEmitter<any>(); @Output() newLogs = new EventEmitter<any>();
options: any = {enableBasicAutocompletion: true, options: any = {enableBasicAutocompletion: true,
enableSnippets: true, enableSnippets: true,
@ -101,7 +101,7 @@ export class IdeComponent implements OnInit {
config.ide.deployProcessName, config.ide.deployProcessName,
(event) => { (event) => {
this.deploymentNotificationService.deploying.next(false); this.deploymentNotificationService.deploying.next(false);
this.newLog.emit({ this.newLogs.emit({
stdout: event.data.stdout, stdout: event.data.stdout,
stderr: event.data.stderr stderr: event.data.stderr
}); });

View File

@ -9,11 +9,11 @@ import { BehaviorSubject } from 'rxjs/BehaviorSubject';
@Injectable() @Injectable()
export class ProcessLogService { export class ProcessLogService {
newLog = new BehaviorSubject<any>(config.console.defaultLogs); newLogs = new BehaviorSubject<any>(config.console.defaultLogs);
showLiveLogs = config.console.showLiveLogs; showLiveLogs = config.console.showLiveLogs;
command_handlers = { command_handlers = {
'new_log': this.newLogHandler.bind(this) 'new_log': this.newLogsHandler.bind(this)
}; };
constructor(private webSocketService: WebSocketService) { constructor(private webSocketService: WebSocketService) {
@ -23,9 +23,15 @@ export class ProcessLogService {
); );
} }
newLogHandler(data: ProcessLogCommand) { emitNewLogsIfNoLiveLogs(log: any) {
if (!config.console.showLiveLogs) {
this.newLogs.next(log);
}
}
newLogsHandler(data: ProcessLogCommand) {
if (this.showLiveLogs) { if (this.showLiveLogs) {
this.newLog.next({ this.newLogs.next({
stdout: data.stdout, stdout: data.stdout,
stderr: data.stderr stderr: data.stderr
}); });