Update console according to the new API

This commit is contained in:
R. Richard 2019-08-07 10:26:19 +02:00
parent 053b4816d1
commit 1808beda90
2 changed files with 29 additions and 22 deletions

View File

@ -3,11 +3,16 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { WebSocketService } from '../services/websocket.service'; import { WebSocketService } from '../services/websocket.service';
import { ConsoleContentCommand, RewriteContentCommand, ShowLiveLogsCommand } from '../message-types/console-commands'; import { WebSocketMessage } from '../message-types/websocket-message';
import {
ConsoleReadCommand,
ConsoleWriteCommand,
ConsoleLiveLogsCommand,
ConsoleRewriteContentCommand
} from '../message-types/console-commands';
import { config } from '../config'; import { config } from '../config';
import { ProcessLogService } from '../services/processlog.service'; import { ProcessLogService } from '../services/processlog.service';
import { LogMessage } from '../message-types/log-message'; import { LogMessage } from '../message-types/log-message';
import { CommandMessage } from '../message-types/command-message';
@Component({ @Component({
selector: 'app-console', selector: 'app-console',
@ -19,10 +24,10 @@ export class ConsoleComponent implements OnInit {
rewriteContentWithProcessLogsOnDeploy: string = config.console.rewriteContentWithProcessLogsOnDeploy; rewriteContentWithProcessLogsOnDeploy: string = config.console.rewriteContentWithProcessLogsOnDeploy;
command_handlers = { command_handlers = {
'write': this.writeHandler.bind(this), 'console.read': this.readHandler.bind(this),
'read': this.readHandler.bind(this), 'console.write': this.writeHandler.bind(this),
'showLiveLogs': this.showLiveLogsHandler.bind(this), 'console.showLiveLogs': this.showLiveLogsHandler.bind(this),
'rewriteContentWithProcessLogsOnDeploy': this.rewriteContentWithProcessLogsOnDeployHandler.bind(this) 'console.rewriteContentWithProcessLogsOnDeploy': this.rewriteContentWithProcessLogsOnDeployHandler.bind(this)
}; };
constructor(private webSocketService: WebSocketService, constructor(private webSocketService: WebSocketService,
@ -30,18 +35,18 @@ export class ConsoleComponent implements OnInit {
ngOnInit() { ngOnInit() {
this.webSocketService.connect(); this.webSocketService.connect();
this.webSocketService.observeKey<CommandMessage>('console').subscribe( this.webSocketService.observeKey<WebSocketMessage>('console').subscribe(
(event) => this.command_handlers[event.data.command](event.data) (event) => this.command_handlers[event.key](event)
); );
this.processLogService.newLogs.subscribe((data) => this.newLogsHandler(data)); this.processLogService.newLogs.subscribe((data) => this.newLogsHandler(data));
} }
writeHandler(data: ConsoleContentCommand) { readHandler(data: ConsoleReadCommand) {
this.setContent(data.content); this.sendContent(this.console_content);
} }
readHandler(data: ConsoleContentCommand) { writeHandler(data: ConsoleWriteCommand) {
this.sendContent(this.console_content); this.setContent(data.value);
} }
newLogsHandler(logs: LogMessage) { newLogsHandler(logs: LogMessage) {
@ -53,11 +58,11 @@ export class ConsoleComponent implements OnInit {
} }
} }
showLiveLogsHandler(data: ShowLiveLogsCommand) { showLiveLogsHandler(data: ConsoleLiveLogsCommand) {
this.processLogService.showLiveLogs = data.value; this.processLogService.showLiveLogs = data.value;
} }
rewriteContentWithProcessLogsOnDeployHandler(data: RewriteContentCommand) { rewriteContentWithProcessLogsOnDeployHandler(data: ConsoleRewriteContentCommand) {
this.rewriteContentWithProcessLogsOnDeploy = data.value; this.rewriteContentWithProcessLogsOnDeploy = data.value;
} }
@ -66,9 +71,9 @@ export class ConsoleComponent implements OnInit {
} }
sendContent(content: string) { sendContent(content: string) {
this.webSocketService.send('console', { this.webSocketService.sendJSON({
'command': 'read', 'key': 'console.content',
'content': content 'value': content
}); });
} }
} }

View File

@ -1,13 +1,15 @@
// Copyright (C) 2018 Avatao.com Innovative Learning Kft. // Copyright (C) 2018 Avatao.com Innovative Learning Kft.
// All Rights Reserved. See LICENSE file for details. // All Rights Reserved. See LICENSE file for details.
import { CommandMessage } from './command-message';
import { SetValueCommand } from './set-value-command'; import { SetValueCommand } from './set-value-command';
import { WebSocketMessage } from './websocket-message';
export interface ConsoleContentCommand extends CommandMessage { export interface ConsoleReadCommand extends WebSocketMessage {}
content?: string;
export interface ConsoleWriteCommand extends WebSocketMessage {
value: string;
} }
export interface ShowLiveLogsCommand extends CommandMessage, SetValueCommand<boolean> {} export interface ConsoleLiveLogsCommand extends WebSocketMessage, SetValueCommand<boolean> {}
export interface RewriteContentCommand extends CommandMessage, SetValueCommand<string> {} export interface ConsoleRewriteContentCommand extends WebSocketMessage, SetValueCommand<string> {}