Make type hierarchy from messages

This commit is contained in:
Kristóf Tóth 2018-05-31 12:02:53 +02:00
parent e510fb58f6
commit 887a81ab8e
12 changed files with 51 additions and 37 deletions

View File

@ -7,6 +7,7 @@ import { ConsoleCommand } from '../message.types/console.command';
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',
@ -29,7 +30,7 @@ export class ConsoleComponent implements OnInit {
ngOnInit() {
this.webSocketService.connect();
this.webSocketService.observeKey<ConsoleCommand>('console').subscribe(
this.webSocketService.observeKey<CommandMessage>('console').subscribe(
(event) => this.command_handlers[event.data.command](event.data)
);
this.processLogService.newLogs.subscribe((data) => this.newLogsHandler(data));
@ -39,7 +40,7 @@ export class ConsoleComponent implements OnInit {
this.setContent(data.content);
}
readHandler(data: ConsoleCommand) {
readHandler(data: CommandMessage) {
this.sendContent(this.console_content);
}

View File

@ -9,6 +9,7 @@ import { LayoutCommand } from '../message.types/layout.command';
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-dashboard',
@ -42,7 +43,7 @@ export class DashboardComponent implements OnInit, OnDestroy {
}
initCommandHandling() {
this.webSocketService.observeKey<LayoutCommand>('dashboard').subscribe((event) => {
this.webSocketService.observeKey<CommandMessage>('dashboard').subscribe((event) => {
this.command_handlers[event.data.command](event.data);
this.changeDetectorRef.detectChanges();
});
@ -85,7 +86,7 @@ export class DashboardComponent implements OnInit, OnDestroy {
this.selectTerminalMenuItem(data.terminal_menu_item);
}
reloadFrontendHandlder(data: LayoutCommand) {
reloadFrontendHandlder(data: CommandMessage) {
setTimeout(() => window.location.reload(), 2000);
}

View File

@ -21,6 +21,7 @@ import { WebSocketService } from '../services/websocket.service';
import { ProcessManagerService } from '../services/processmanager.service';
import { DeploymentNotificationService } from '../services/deployment-notification.service';
import { config } from '../config';
import { CommandMessage } from '../message.types/command.message';
const modelist = brace.acequire('ace/ext/modelist');
const langTools = brace.acequire('ace/ext/language_tools');
@ -89,7 +90,7 @@ export class IdeComponent implements OnInit {
}
subscribeWS() {
this.webSocketService.observeKey<IDECommand>(this.key_id).subscribe((event) => {
this.webSocketService.observeKey<CommandMessage>(this.key_id).subscribe((event) => {
this.command_handlers[event.data.command](event.data);
this.changeDetectorRef.detectChanges();
});
@ -131,7 +132,7 @@ export class IdeComponent implements OnInit {
this.updateFileData(data);
}
reloadHandler(data: IDECommand) {
reloadHandler(data: CommandMessage) {
this.requestCode();
}
@ -141,7 +142,7 @@ export class IdeComponent implements OnInit {
}
}
writeHandler() {
writeHandler(data: CommandMessage) {
this.setCodeState(CodeState.SAVED);
}

View File

@ -1,7 +1,6 @@
// Copyright (C) 2018 Avatao.com Innovative Learning Kft.
// All Rights Reserved. See LICENSE file for details.
export class MessageControl {
command: string;
next_visibility?: boolean;
export interface CommandMessage {
readonly command: string;
}

View File

@ -1,8 +1,9 @@
// Copyright (C) 2018 Avatao.com Innovative Learning Kft.
// All Rights Reserved. See LICENSE file for details.
export interface ConsoleCommand {
command: string;
import { CommandMessage } from './command.message';
export interface ConsoleCommand extends CommandMessage {
content?: string;
showLiveLogs?: boolean;
rewriteContentWithProcessLogsOnDeploy?: string;

View File

@ -1,10 +1,11 @@
// Copyright (C) 2018 Avatao.com Innovative Learning Kft.
// All Rights Reserved. See LICENSE file for details.
export interface IDECommand {
import { CommandMessage } from './command.message';
export interface IDECommand extends CommandMessage {
filename: string;
content?: string;
files: string[];
directory: string;
command: string;
}

View File

@ -1,8 +1,9 @@
// Copyright (C) 2018 Avatao.com Innovative Learning Kft.
// All Rights Reserved. See LICENSE file for details.
export interface LayoutCommand {
command: string;
import { CommandMessage } from './command.message';
export interface LayoutCommand extends CommandMessage {
layout?: string;
hide_messages?: boolean;
terminal_menu_item?: string;

View File

@ -0,0 +1,8 @@
// Copyright (C) 2018 Avatao.com Innovative Learning Kft.
// All Rights Reserved. See LICENSE file for details.
import { CommandMessage } from './command.message';
export interface MessageControlCommand extends CommandMessage {
next_visibility?: boolean;
}

View File

@ -1,10 +1,10 @@
// Copyright (C) 2018 Avatao.com Innovative Learning Kft.
// All Rights Reserved. See LICENSE file for details.
export interface ProcessCommand {
command: string;
import { CommandMessage } from './command.message';
import { LogMessage } from './log.message';
export interface ProcessCommand extends CommandMessage, LogMessage {
process_name: string;
error?: string;
stdout: string;
stderr: string;
}

View File

@ -1,8 +1,7 @@
// Copyright (C) 2018 Avatao.com Innovative Learning Kft.
// All Rights Reserved. See LICENSE file for details.
export interface ProcessLogCommand {
command: string;
stdout: string;
stderr: string;
}
import { CommandMessage } from './command.message';
import { LogMessage } from './log.message';
export interface ProcessLogCommand extends CommandMessage, LogMessage {}

View File

@ -6,8 +6,9 @@ import { MarkdownService } from '../services/markdown.service';
import { WebSocketService } from '../services/websocket.service';
import { MessagesMessage } from '../message.types/messages.message';
import { MessageControl } from '../message.types/messagecontrol';
import { MessageControlCommand } from '../message.types/message.control.command';
import { config } from '../config';
import { CommandMessage } from '../message.types/command.message';
@Component({
selector: 'app-messages',
@ -17,7 +18,7 @@ import { config } from '../config';
export class MessagesComponent implements OnInit {
messages: MessagesMessage[] = [];
showNextButton: boolean = config.messages.showNextButton;
command_handlers = {'showbutton': this.showButton.bind(this)};
command_handlers = {'showbutton': this.showButtonHandler.bind(this)};
constructor(
private markdownService: MarkdownService,
@ -25,14 +26,6 @@ export class MessagesComponent implements OnInit {
private changeDetectorRef: ChangeDetectorRef
) {}
convert(text: string) {
return this.markdownService.convertToHtml(text);
}
showButton(data: MessageControl) {
this.showNextButton = data.next_visibility;
}
ngOnInit() {
this.websocketService.connect();
this.websocketService.observeKey<MessagesMessage>('message').subscribe(
@ -41,12 +34,20 @@ export class MessagesComponent implements OnInit {
event.data.message = this.convert(event.data.message);
this.changeDetectorRef.detectChanges();
});
this.websocketService.observeKey<MessageControl>('messagecontrol').subscribe(
this.websocketService.observeKey<CommandMessage>('messagecontrol').subscribe(
(event) => {
this.command_handlers[event.data.command](event.data);
});
}
convert(text: string) {
return this.markdownService.convertToHtml(text);
}
showButtonHandler(data: MessageControlCommand) {
this.showNextButton = data.next_visibility;
}
stepFSM() {
this.websocketService.sendJSON({key: '', trigger: 'step_next'});
}

View File

@ -7,6 +7,7 @@ import { ProcessLogCommand } from '../message.types/process.log.command';
import { config } from '../config';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { LogMessage } from '../message.types/log.message';
import { CommandMessage } from '../message.types/command.message';
@Injectable()
export class ProcessLogService {
@ -19,7 +20,7 @@ export class ProcessLogService {
constructor(private webSocketService: WebSocketService) {
this.webSocketService.connect();
this.webSocketService.observeKey<ProcessLogCommand>('processlog').subscribe(
this.webSocketService.observeKey<CommandMessage>('processlog').subscribe(
(event) => this.command_handlers[event.data.command](event.data)
);
}