Rename interfaces and variables

This commit is contained in:
R. Richard 2019-08-08 14:44:40 +02:00
parent 6b25416973
commit 6e22e7efe9
19 changed files with 90 additions and 130 deletions

View File

@ -5,11 +5,11 @@ import { Component, OnInit } from '@angular/core';
import { WebSocketService } from '../services/websocket.service';
import { WebSocketMessage } from '../message-types/websocket-message';
import {
ConsoleReadCommand,
ConsoleWriteCommand,
ConsoleLiveLogsCommand,
ConsoleRewriteContentCommand
} from '../message-types/console-commands';
ConsoleReadMessage,
ConsoleWriteMessage,
ConsoleLiveLogsMessage,
ConsoleRewriteContentMessage
} from '../message-types/console-messages';
import { config } from '../config';
import { ProcessLogService } from '../services/processlog.service';
import { LogMessage } from '../message-types/log-message';
@ -36,17 +36,17 @@ export class ConsoleComponent implements OnInit {
ngOnInit() {
this.webSocketService.connect();
this.webSocketService.observeKey<WebSocketMessage>('console').subscribe(
(event) => this.command_handlers[event.key](event)
message => this.command_handlers[message.key](message)
);
this.processLogService.newLogs.subscribe((data) => this.newLogsHandler(data));
}
readHandler(data: ConsoleReadCommand) {
readHandler(message: ConsoleReadMessage) {
this.sendContent(this.console_content);
}
writeHandler(data: ConsoleWriteCommand) {
this.setContent(data.value);
writeHandler(message: ConsoleWriteMessage) {
this.setContent(message.value);
}
newLogsHandler(logs: LogMessage) {
@ -58,12 +58,12 @@ export class ConsoleComponent implements OnInit {
}
}
showLiveLogsHandler(data: ConsoleLiveLogsCommand) {
this.processLogService.showLiveLogs = data.value;
showLiveLogsHandler(message: ConsoleLiveLogsMessage) {
this.processLogService.showLiveLogs = message.value;
}
rewriteContentWithProcessLogsOnDeployHandler(data: ConsoleRewriteContentCommand) {
this.rewriteContentWithProcessLogsOnDeploy = data.value;
rewriteContentWithProcessLogsOnDeployHandler(message: ConsoleRewriteContentMessage) {
this.rewriteContentWithProcessLogsOnDeploy = message.value;
}
setContent(content: string) {

View File

@ -6,7 +6,7 @@ import { DeploymentNotificationService } from '../services/deployment-notificati
import { Subscription } from 'rxjs';
import { WebSocketService } from '../services/websocket.service';
import { WebSocketMessage } from '../message-types/websocket-message';
import { HideMessagesCommand, LayoutCommand, TerminalMenuItemCommand } from '../message-types/dashboard-commands';
import { HideMessagesMessage, LayoutMessage, TerminalMenuItemMessage } from '../message-types/dashboard-messages';
import { config } from '../config';
import { ProcessLogService } from '../services/processlog.service';
import { LogMessage } from '../message-types/log-message';
@ -57,8 +57,8 @@ export class DashboardComponent implements OnInit, OnDestroy {
}
initCommandHandling() {
this.webSocketService.observeKey<WebSocketMessage>('dashboard').subscribe((event) => {
this.command_handlers[event.key](event);
this.webSocketService.observeKey<WebSocketMessage>('dashboard').subscribe((message) => {
this.command_handlers[message.key](message);
this.changeDetectorRef.detectChanges();
});
}
@ -93,27 +93,27 @@ export class DashboardComponent implements OnInit, OnDestroy {
}
}
layoutHandler(data: LayoutCommand) {
if (config.dashboard.enabledLayouts.includes(data.value)) {
this.setLayout(data.value);
layoutHandler(message: LayoutMessage) {
if (config.dashboard.enabledLayouts.includes(message.value)) {
this.setLayout(message.value);
} else {
console.log('Invalid ide layout "' + data.value + '" received!');
console.log('Invalid ide layout "' + message.value + '" received!');
}
}
hideMessagesHandler(data: HideMessagesCommand) {
this.hideMessages = data.value;
hideMessagesHandler(message: HideMessagesMessage) {
this.hideMessages = message.value;
}
terminalMenuItemHandler(data: TerminalMenuItemCommand) {
this.selectTerminalMenuItem(data.value);
terminalMenuItemHandler(message: TerminalMenuItemMessage) {
this.selectTerminalMenuItem(message.value);
}
reloadFrontendHandlder(data: WebSocketMessage) {
reloadFrontendHandlder(message: WebSocketMessage) {
setTimeout(() => window.location.reload(), 2000);
}
reloadIframeHandler(data: WebSocketMessage) {
reloadIframeHandler(message: WebSocketMessage) {
setTimeout(() => this.reloadIframeNoSubmit(), 200);
}

View File

@ -5,7 +5,7 @@ import { ChangeDetectorRef, Component, EventEmitter, OnInit, Output } from '@ang
import { WebSocketService } from '../services/websocket.service';
import { WebSocketMessage } from '../message-types/websocket-message';
import { IDECommand } from '../message-types/ide-command';
import { IDEMessage } from '../message-types/ide-message';
import { ProcessManagerService } from '../services/processmanager.service';
import { DeploymentNotificationService } from '../services/deployment-notification.service';
import { config } from '../config';
@ -73,14 +73,14 @@ export class IdeComponent implements OnInit {
}
subscribeWS() {
this.webSocketService.observeKey<WebSocketMessage>('ide').subscribe((event) => {
this.command_handlers[event.key](event);
this.webSocketService.observeKey<WebSocketMessage>('ide').subscribe((message) => {
this.command_handlers[message.key](message);
this.changeDetectorRef.detectChanges();
});
}
subscribeFirstLanguageDetection() {
this.webSocketService.observeKey<IDECommand>('ide.read').pipe(first()).subscribe(
this.webSocketService.observeKey<IDEMessage>('ide.read').pipe(first()).subscribe(
() => this.autoDetectEditorLanguageIfEnabled(this.filename)
);
}
@ -89,18 +89,18 @@ export class IdeComponent implements OnInit {
this.processManagerService.init();
this.processManagerService.subscribeCallback(
config.ide.deployProcessName,
(event) => {
(message) => {
this.deploymentNotificationService.deploying.next(false);
this.newLogs.emit({
stdout: event.stdout,
stderr: event.stderr
stdout: message.stdout,
stderr: message.stderr
});
}
);
this.processManagerService.subscribeSuccessCallback(
config.ide.deployProcessName,
(event) => this.setDeployButtonState(DeployButtonState.DEPLOYED)
(message) => this.setDeployButtonState(DeployButtonState.DEPLOYED)
);
this.processManagerService.subscribeErrorCallback(
@ -109,28 +109,24 @@ export class IdeComponent implements OnInit {
);
}
reloadHandler(data: WebSocketMessage) {
reloadHandler(message: WebSocketMessage) {
this.requestCode();
}
readHandler(data: IDECommand) {
readHandler(message: IDEMessage) {
if (this.codeState === CodeState.SAVED) {
this.updateFileData(data);
if (this.filename != message.filename) {
this.filename = message.filename;
}
this.code = (message.content != null) ? message.content : this.code;
this.files = message.files;
}
}
writeHandler(data: IDECommand) {
writeHandler(message: IDEMessage) {
this.setCodeState(CodeState.SAVED);
}
updateFileData(data: IDECommand) {
if (this.filename != data.filename) {
this.filename = data.filename;
}
this.code = (data.content != null) ? data.content : this.code;
this.files = data.files;
}
autoDetectEditorLanguageIfEnabled(filename: string) {
if (!config.ide.autoDetectFileLanguage) {
return;

View File

@ -16,8 +16,8 @@ export interface MessageData extends MessageMetadata {
message: string;
}
export interface MessagesMessage extends MessageData, WebSocketMessage {}
export interface Message extends MessageData, WebSocketMessage {}
export interface MessageQueueMessage extends WebSocketMessage {
export interface MessageQueue extends WebSocketMessage {
value: Array<MessageData>;
}

View File

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

View File

@ -4,12 +4,12 @@
import { SetValueCommand } from './set-value-command';
import { WebSocketMessage } from './websocket-message';
export interface ConsoleReadCommand extends WebSocketMessage {}
export interface ConsoleReadMessage extends WebSocketMessage {}
export interface ConsoleWriteCommand extends WebSocketMessage {
export interface ConsoleWriteMessage extends WebSocketMessage {
value: string;
}
export interface ConsoleLiveLogsCommand extends WebSocketMessage, SetValueCommand<boolean> {}
export interface ConsoleLiveLogsMessage extends WebSocketMessage, SetValueCommand<boolean> {}
export interface ConsoleRewriteContentCommand extends WebSocketMessage, SetValueCommand<string> {}
export interface ConsoleRewriteContentMessage extends WebSocketMessage, SetValueCommand<string> {}

View File

@ -4,8 +4,8 @@
import { SetValueCommand } from './set-value-command';
import { WebSocketMessage } from './websocket-message';
export interface LayoutCommand extends WebSocketMessage, SetValueCommand<string> {}
export interface LayoutMessage extends WebSocketMessage, SetValueCommand<string> {}
export interface HideMessagesCommand extends WebSocketMessage, SetValueCommand<boolean> {}
export interface HideMessagesMessage extends WebSocketMessage, SetValueCommand<boolean> {}
export interface TerminalMenuItemCommand extends WebSocketMessage, SetValueCommand<string> {}
export interface TerminalMenuItemMessage extends WebSocketMessage, SetValueCommand<string> {}

View File

@ -3,7 +3,7 @@
import { WebSocketMessage } from './websocket-message';
export interface FSMUpdate extends WebSocketMessage {
export interface FSMUpdateMessage extends WebSocketMessage {
current_state: string;
valid_transitions: object;
}

View File

@ -3,7 +3,7 @@
import { WebSocketMessage } from './websocket-message';
export interface IDECommand extends WebSocketMessage {
export interface IDEMessage extends WebSocketMessage {
filename: string;
content?: string;
files?: string[];

View File

@ -1,7 +0,0 @@
// Copyright (C) 2018 Avatao.com Innovative Learning Kft.
// All Rights Reserved. See LICENSE file for details.
export class MessageMetadata {
originator: string;
timestamp?: Date;
}

View File

@ -1,8 +0,0 @@
// Copyright (C) 2018 Avatao.com Innovative Learning Kft.
// All Rights Reserved. See LICENSE file for details.
import { MessagesMessage } from './messages-message';
export class MessageQueueMessage {
messages: Array<MessagesMessage>;
}

View File

@ -1,7 +0,0 @@
// 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';
export interface MessagesControlCommand extends CommandMessage, SetValueCommand<boolean> {}

View File

@ -1,8 +0,0 @@
// Copyright (C) 2018 Avatao.com Innovative Learning Kft.
// All Rights Reserved. See LICENSE file for details.
import { MessageMetadata } from './message-metadata';
export class MessagesMessage extends MessageMetadata {
message: string;
}

View File

@ -4,4 +4,4 @@
import { LogMessage } from './log-message';
import { WebSocketMessage } from './websocket-message';
export interface ProcessLogCommand extends WebSocketMessage, LogMessage {}
export interface ProcessLogMessage extends WebSocketMessage, LogMessage {}

View File

@ -4,7 +4,7 @@
import { LogMessage } from './log-message';
import { WebSocketMessage } from './websocket-message';
export interface ProcessCommand extends WebSocketMessage, LogMessage {
export interface ProcessMessage extends WebSocketMessage, LogMessage {
name: string;
error?: string;
}

View File

@ -2,7 +2,7 @@
// All Rights Reserved. See LICENSE file for details.
import { ChangeDetectorRef, Component, OnInit, EventEmitter, Output } from '@angular/core';
import { MessageConfig, MessageData, MessagesMessage, MessageQueueMessage } from '../message-types/bot-messages';
import { MessageConfig, MessageData, Message, MessageQueue } from '../message-types/bot-messages';
import { MarkdownService } from '../services/markdown.service';
import { WebSocketService } from '../services/websocket.service';
@ -42,40 +42,40 @@ export class MessagesComponent implements OnInit {
);
this.websocketService.connect();
this.websocketService.observeKey<MessagesMessage>('message.send').subscribe(
(event) => this.newMessage.next(event)
this.websocketService.observeKey<Message>('message.send').subscribe(
(message) => this.newMessage.next(message)
);
this.websocketService.observeKey<MessageQueueMessage>('message.queue').subscribe(
(event) => this.handleQueueMessage(event)
this.websocketService.observeKey<MessageQueue>('message.queue').subscribe(
(message) => this.handleQueueMessage(message)
);
this.websocketService.observeKey<MessageConfig>('message.config').subscribe(
(event) => this.configureMessages(event)
(message) => this.configureMessages(message)
);
}
writeMessage(data: MessageData) {
this.transformMessage(data);
this.messages.push(data);
writeMessage(message: MessageData) {
this.transformMessage(message);
this.messages.push(message);
this.changeDetectorRef.detectChanges();
}
transformMessage(data: MessageData) {
data.message = this.convertMarkdownToHTML(data.message);
if (!data.originator) {
data.originator = this.originator;
transformMessage(message: MessageData) {
message.message = this.convertMarkdownToHTML(message.message);
if (!message.originator) {
message.originator = this.originator;
}
if (!data.timestamp) {
data.timestamp = new Date();
if (!message.timestamp) {
message.timestamp = new Date();
}
}
handleQueueMessage(data: MessageQueueMessage) {
this.messageQueueAttender.queueMessages(data.value);
handleQueueMessage(message: MessageQueue) {
this.messageQueueAttender.queueMessages(message.value);
}
configureMessages(data: MessageConfig) {
if (data.originator) {
this.originator = data.originator;
configureMessages(message: MessageConfig) {
if (message.originator) {
this.originator = message.originator;
}
}

View File

@ -4,7 +4,7 @@
import { Injectable } from '@angular/core';
import { WebSocketService } from './websocket.service';
import { FSMUpdate } from '../message-types/fsm-update';
import { FSMUpdateMessage } from '../message-types/fsm-update-message';
@Injectable()
export class FSMUpdateService {
@ -14,9 +14,9 @@ export class FSMUpdateService {
constructor(private websocketService: WebSocketService) {}
public init(): void {
this.websocketService.observeKey<FSMUpdate>('fsm.announce').subscribe((event) => {
this.current_state = event.current_state;
this.valid_transitions = event.valid_transitions;
this.websocketService.observeKey<FSMUpdateMessage>('fsm.update').subscribe((message) => {
this.current_state = message.current_state;
this.valid_transitions = message.valid_transitions;
});
}

View File

@ -4,7 +4,7 @@
import { Injectable } from '@angular/core';
import { WebSocketService } from './websocket.service';
import { LogMessage } from '../message-types/log-message';
import { ProcessLogCommand } from '../message-types/process-log-command';
import { ProcessLogMessage } from '../message-types/process-log-message';
import { config } from '../config';
import { BehaviorSubject } from 'rxjs';
@ -15,8 +15,8 @@ export class ProcessLogService {
constructor(private webSocketService: WebSocketService) {
this.webSocketService.connect();
this.webSocketService.observeKey<ProcessLogCommand>('log.new').subscribe(
(event) => this.newLogsHandler(event)
this.webSocketService.observeKey<ProcessLogMessage>('process.log.new').subscribe(
(message) => this.newLogsHandler(message)
);
}
@ -26,11 +26,11 @@ export class ProcessLogService {
}
}
newLogsHandler(data: ProcessLogCommand) {
newLogsHandler(message: ProcessLogMessage) {
if (this.showLiveLogs) {
this.newLogs.next({
stdout: data.stdout,
stderr: data.stderr
stdout: message.stdout,
stderr: message.stderr
});
}
}

View File

@ -4,7 +4,7 @@
import { Injectable } from '@angular/core';
import { WebSocketService } from './websocket.service';
import { ProcessCommand } from '../message-types/process-command';
import { ProcessMessage } from '../message-types/process-message';
import { filter } from 'rxjs/operators';
@Injectable()
@ -17,20 +17,20 @@ export class ProcessManagerService {
this.webSocketService.connect();
}
subscribeCallback(process_name: string, callback: (event: ProcessCommand) => void) {
subscribeCallback(process_name: string, callback: (message: ProcessMessage) => void) {
this.observeProcessMessage(process_name).subscribe(callback);
}
subscribeSuccessCallback(process_name: string, callback: (event: ProcessCommand) => void) {
subscribeSuccessCallback(process_name: string, callback: (message: ProcessMessage) => void) {
this.observeProcessMessage(process_name).pipe(filter(message => !('error' in message))).subscribe(callback);
}
subscribeErrorCallback(process_name: string, callback: (event: ProcessCommand) => void) {
subscribeErrorCallback(process_name: string, callback: (message: ProcessMessage) => void) {
this.observeProcessMessage(process_name).pipe(filter(message => 'error' in message)).subscribe(callback);
}
observeProcessMessage(process_name: string) {
return this.webSocketService.observeKey<ProcessCommand>('process')
return this.webSocketService.observeKey<ProcessMessage>('process')
.pipe(filter(message => message.name === process_name));
}