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

View File

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

View File

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

View File

@ -1,7 +1,6 @@
// 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.
export class MessageControl { export interface CommandMessage {
command: string; readonly command: string;
next_visibility?: boolean;
} }

View File

@ -1,8 +1,9 @@
// 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.
export interface ConsoleCommand { import { CommandMessage } from './command.message';
command: string;
export interface ConsoleCommand extends CommandMessage {
content?: string; content?: string;
showLiveLogs?: boolean; showLiveLogs?: boolean;
rewriteContentWithProcessLogsOnDeploy?: string; rewriteContentWithProcessLogsOnDeploy?: string;

View File

@ -1,10 +1,11 @@
// 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.
export interface IDECommand { import { CommandMessage } from './command.message';
export interface IDECommand extends CommandMessage {
filename: string; filename: string;
content?: string; content?: string;
files: string[]; files: string[];
directory: string; directory: string;
command: string;
} }

View File

@ -1,8 +1,9 @@
// 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.
export interface LayoutCommand { import { CommandMessage } from './command.message';
command: string;
export interface LayoutCommand extends CommandMessage {
layout?: string; layout?: string;
hide_messages?: boolean; hide_messages?: boolean;
terminal_menu_item?: string; 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. // Copyright (C) 2018 Avatao.com Innovative Learning Kft.
// All Rights Reserved. See LICENSE file for details. // All Rights Reserved. See LICENSE file for details.
export interface ProcessCommand { import { CommandMessage } from './command.message';
command: string; import { LogMessage } from './log.message';
export interface ProcessCommand extends CommandMessage, LogMessage {
process_name: string; process_name: string;
error?: string; error?: string;
stdout: string;
stderr: string;
} }

View File

@ -1,8 +1,7 @@
// 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.
export interface ProcessLogCommand { import { CommandMessage } from './command.message';
command: string; import { LogMessage } from './log.message';
stdout: string;
stderr: string; 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 { WebSocketService } from '../services/websocket.service';
import { MessagesMessage } from '../message.types/messages.message'; 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 { config } from '../config';
import { CommandMessage } from '../message.types/command.message';
@Component({ @Component({
selector: 'app-messages', selector: 'app-messages',
@ -17,7 +18,7 @@ import { config } from '../config';
export class MessagesComponent implements OnInit { export class MessagesComponent implements OnInit {
messages: MessagesMessage[] = []; messages: MessagesMessage[] = [];
showNextButton: boolean = config.messages.showNextButton; showNextButton: boolean = config.messages.showNextButton;
command_handlers = {'showbutton': this.showButton.bind(this)}; command_handlers = {'showbutton': this.showButtonHandler.bind(this)};
constructor( constructor(
private markdownService: MarkdownService, private markdownService: MarkdownService,
@ -25,14 +26,6 @@ export class MessagesComponent implements OnInit {
private changeDetectorRef: ChangeDetectorRef private changeDetectorRef: ChangeDetectorRef
) {} ) {}
convert(text: string) {
return this.markdownService.convertToHtml(text);
}
showButton(data: MessageControl) {
this.showNextButton = data.next_visibility;
}
ngOnInit() { ngOnInit() {
this.websocketService.connect(); this.websocketService.connect();
this.websocketService.observeKey<MessagesMessage>('message').subscribe( this.websocketService.observeKey<MessagesMessage>('message').subscribe(
@ -41,12 +34,20 @@ export class MessagesComponent implements OnInit {
event.data.message = this.convert(event.data.message); event.data.message = this.convert(event.data.message);
this.changeDetectorRef.detectChanges(); this.changeDetectorRef.detectChanges();
}); });
this.websocketService.observeKey<MessageControl>('messagecontrol').subscribe( this.websocketService.observeKey<CommandMessage>('messagecontrol').subscribe(
(event) => { (event) => {
this.command_handlers[event.data.command](event.data); 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() { stepFSM() {
this.websocketService.sendJSON({key: '', trigger: 'step_next'}); 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 { config } from '../config';
import { BehaviorSubject } from 'rxjs/BehaviorSubject'; import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { LogMessage } from '../message.types/log.message'; import { LogMessage } from '../message.types/log.message';
import { CommandMessage } from '../message.types/command.message';
@Injectable() @Injectable()
export class ProcessLogService { export class ProcessLogService {
@ -19,7 +20,7 @@ export class ProcessLogService {
constructor(private webSocketService: WebSocketService) { constructor(private webSocketService: WebSocketService) {
this.webSocketService.connect(); this.webSocketService.connect();
this.webSocketService.observeKey<ProcessLogCommand>('processlog').subscribe( this.webSocketService.observeKey<CommandMessage>('processlog').subscribe(
(event) => this.command_handlers[event.data.command](event.data) (event) => this.command_handlers[event.data.command](event.data)
); );
} }