mirror of
https://github.com/avatao-content/frontend-tutorial-framework
synced 2024-12-05 02:41:32 +00:00
Make type hierarchy from messages
This commit is contained in:
parent
e510fb58f6
commit
887a81ab8e
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
8
src/app/message.types/message.control.command.ts
Normal file
8
src/app/message.types/message.control.command.ts
Normal 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;
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -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 {}
|
||||
|
@ -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'});
|
||||
}
|
||||
|
@ -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)
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user