mirror of
				https://github.com/avatao-content/frontend-tutorial-framework
				synced 2025-11-04 13:52:55 +00:00 
			
		
		
		
	Move live log checking logic to ProcessLogService
This commit is contained in:
		@@ -29,7 +29,7 @@ export class ConsoleComponent implements OnInit {
 | 
			
		||||
    this.webSocketService.observeKey<ConsoleCommand>('console').subscribe(
 | 
			
		||||
      (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) {
 | 
			
		||||
@@ -40,7 +40,7 @@ export class ConsoleComponent implements OnInit {
 | 
			
		||||
    this.sendContent(this.console_content);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  newLogHandler(logs: any) {
 | 
			
		||||
  newLogsHandler(logs: any) {
 | 
			
		||||
    if (this.rewriteContentWithProcessLogs !== '') {
 | 
			
		||||
      const log = logs[this.rewriteContentWithProcessLogs];
 | 
			
		||||
      if (log) {
 | 
			
		||||
 
 | 
			
		||||
@@ -20,7 +20,7 @@
 | 
			
		||||
        </div>
 | 
			
		||||
    </div>
 | 
			
		||||
    <div class="tfw-ide">
 | 
			
		||||
      <app-ide (newLog)="setConsoleContent($event)"></app-ide>
 | 
			
		||||
      <app-ide (newLogs)="setConsoleContentIfNoLiveLogs($event)"></app-ide>
 | 
			
		||||
    </div>
 | 
			
		||||
    <div class="tfw-terminal">
 | 
			
		||||
      <div class="btn-group btn-group-sm flex-wrap tao-grid-center-left tfw-console-terminal-menu">
 | 
			
		||||
 
 | 
			
		||||
@@ -102,10 +102,8 @@ export class DashboardComponent implements OnInit, OnDestroy {
 | 
			
		||||
    this.selectedTerminalMenuItem = item;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  setConsoleContent(logs: any) {
 | 
			
		||||
    if (!config.console.showLiveLogs) {
 | 
			
		||||
      this.processLogService.newLog.next(logs);
 | 
			
		||||
    }
 | 
			
		||||
  setConsoleContentIfNoLiveLogs(logs: any) {
 | 
			
		||||
    this.processLogService.emitNewLogsIfNoLiveLogs(logs);
 | 
			
		||||
    if (config.ide.showConsoleOnDeploy) {
 | 
			
		||||
      this.selectTerminalMenuItem('console');
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -63,7 +63,7 @@ export class IdeComponent implements OnInit {
 | 
			
		||||
  language: string = config.ide.defaultLanguage;
 | 
			
		||||
  theme = 'cobalt';
 | 
			
		||||
 | 
			
		||||
  @Output() newLog = new EventEmitter<any>();
 | 
			
		||||
  @Output() newLogs = new EventEmitter<any>();
 | 
			
		||||
 | 
			
		||||
  options: any = {enableBasicAutocompletion: true,
 | 
			
		||||
                  enableSnippets: true,
 | 
			
		||||
@@ -101,7 +101,7 @@ export class IdeComponent implements OnInit {
 | 
			
		||||
      config.ide.deployProcessName,
 | 
			
		||||
      (event) => {
 | 
			
		||||
        this.deploymentNotificationService.deploying.next(false);
 | 
			
		||||
        this.newLog.emit({
 | 
			
		||||
        this.newLogs.emit({
 | 
			
		||||
          stdout: event.data.stdout,
 | 
			
		||||
          stderr: event.data.stderr
 | 
			
		||||
        });
 | 
			
		||||
 
 | 
			
		||||
@@ -9,11 +9,11 @@ import { BehaviorSubject } from 'rxjs/BehaviorSubject';
 | 
			
		||||
 | 
			
		||||
@Injectable()
 | 
			
		||||
export class ProcessLogService {
 | 
			
		||||
  newLog = new BehaviorSubject<any>(config.console.defaultLogs);
 | 
			
		||||
  newLogs = new BehaviorSubject<any>(config.console.defaultLogs);
 | 
			
		||||
  showLiveLogs = config.console.showLiveLogs;
 | 
			
		||||
 | 
			
		||||
  command_handlers = {
 | 
			
		||||
    'new_log': this.newLogHandler.bind(this)
 | 
			
		||||
    'new_log': this.newLogsHandler.bind(this)
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  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) {
 | 
			
		||||
      this.newLog.next({
 | 
			
		||||
      this.newLogs.next({
 | 
			
		||||
        stdout: data.stdout,
 | 
			
		||||
        stderr: data.stderr
 | 
			
		||||
      });
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user