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

View File

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