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 { WebSocketService } from '../services/websocket.service';
import { WebSocketMessage } from '../message-types/websocket-message'; import { WebSocketMessage } from '../message-types/websocket-message';
import { import {
ConsoleReadCommand, ConsoleReadMessage,
ConsoleWriteCommand, ConsoleWriteMessage,
ConsoleLiveLogsCommand, ConsoleLiveLogsMessage,
ConsoleRewriteContentCommand ConsoleRewriteContentMessage
} from '../message-types/console-commands'; } from '../message-types/console-messages';
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';
@ -36,17 +36,17 @@ export class ConsoleComponent implements OnInit {
ngOnInit() { ngOnInit() {
this.webSocketService.connect(); this.webSocketService.connect();
this.webSocketService.observeKey<WebSocketMessage>('console').subscribe( 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)); this.processLogService.newLogs.subscribe((data) => this.newLogsHandler(data));
} }
readHandler(data: ConsoleReadCommand) { readHandler(message: ConsoleReadMessage) {
this.sendContent(this.console_content); this.sendContent(this.console_content);
} }
writeHandler(data: ConsoleWriteCommand) { writeHandler(message: ConsoleWriteMessage) {
this.setContent(data.value); this.setContent(message.value);
} }
newLogsHandler(logs: LogMessage) { newLogsHandler(logs: LogMessage) {
@ -58,12 +58,12 @@ export class ConsoleComponent implements OnInit {
} }
} }
showLiveLogsHandler(data: ConsoleLiveLogsCommand) { showLiveLogsHandler(message: ConsoleLiveLogsMessage) {
this.processLogService.showLiveLogs = data.value; this.processLogService.showLiveLogs = message.value;
} }
rewriteContentWithProcessLogsOnDeployHandler(data: ConsoleRewriteContentCommand) { rewriteContentWithProcessLogsOnDeployHandler(message: ConsoleRewriteContentMessage) {
this.rewriteContentWithProcessLogsOnDeploy = data.value; this.rewriteContentWithProcessLogsOnDeploy = message.value;
} }
setContent(content: string) { setContent(content: string) {

View File

@ -6,7 +6,7 @@ import { DeploymentNotificationService } from '../services/deployment-notificati
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
import { WebSocketService } from '../services/websocket.service'; import { WebSocketService } from '../services/websocket.service';
import { WebSocketMessage } from '../message-types/websocket-message'; 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 { 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';
@ -57,8 +57,8 @@ export class DashboardComponent implements OnInit, OnDestroy {
} }
initCommandHandling() { initCommandHandling() {
this.webSocketService.observeKey<WebSocketMessage>('dashboard').subscribe((event) => { this.webSocketService.observeKey<WebSocketMessage>('dashboard').subscribe((message) => {
this.command_handlers[event.key](event); this.command_handlers[message.key](message);
this.changeDetectorRef.detectChanges(); this.changeDetectorRef.detectChanges();
}); });
} }
@ -93,27 +93,27 @@ export class DashboardComponent implements OnInit, OnDestroy {
} }
} }
layoutHandler(data: LayoutCommand) { layoutHandler(message: LayoutMessage) {
if (config.dashboard.enabledLayouts.includes(data.value)) { if (config.dashboard.enabledLayouts.includes(message.value)) {
this.setLayout(data.value); this.setLayout(message.value);
} else { } else {
console.log('Invalid ide layout "' + data.value + '" received!'); console.log('Invalid ide layout "' + message.value + '" received!');
} }
} }
hideMessagesHandler(data: HideMessagesCommand) { hideMessagesHandler(message: HideMessagesMessage) {
this.hideMessages = data.value; this.hideMessages = message.value;
} }
terminalMenuItemHandler(data: TerminalMenuItemCommand) { terminalMenuItemHandler(message: TerminalMenuItemMessage) {
this.selectTerminalMenuItem(data.value); this.selectTerminalMenuItem(message.value);
} }
reloadFrontendHandlder(data: WebSocketMessage) { reloadFrontendHandlder(message: WebSocketMessage) {
setTimeout(() => window.location.reload(), 2000); setTimeout(() => window.location.reload(), 2000);
} }
reloadIframeHandler(data: WebSocketMessage) { reloadIframeHandler(message: WebSocketMessage) {
setTimeout(() => this.reloadIframeNoSubmit(), 200); 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 { WebSocketService } from '../services/websocket.service';
import { WebSocketMessage } from '../message-types/websocket-message'; 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 { 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';
@ -73,14 +73,14 @@ export class IdeComponent implements OnInit {
} }
subscribeWS() { subscribeWS() {
this.webSocketService.observeKey<WebSocketMessage>('ide').subscribe((event) => { this.webSocketService.observeKey<WebSocketMessage>('ide').subscribe((message) => {
this.command_handlers[event.key](event); this.command_handlers[message.key](message);
this.changeDetectorRef.detectChanges(); this.changeDetectorRef.detectChanges();
}); });
} }
subscribeFirstLanguageDetection() { subscribeFirstLanguageDetection() {
this.webSocketService.observeKey<IDECommand>('ide.read').pipe(first()).subscribe( this.webSocketService.observeKey<IDEMessage>('ide.read').pipe(first()).subscribe(
() => this.autoDetectEditorLanguageIfEnabled(this.filename) () => this.autoDetectEditorLanguageIfEnabled(this.filename)
); );
} }
@ -89,18 +89,18 @@ export class IdeComponent implements OnInit {
this.processManagerService.init(); this.processManagerService.init();
this.processManagerService.subscribeCallback( this.processManagerService.subscribeCallback(
config.ide.deployProcessName, config.ide.deployProcessName,
(event) => { (message) => {
this.deploymentNotificationService.deploying.next(false); this.deploymentNotificationService.deploying.next(false);
this.newLogs.emit({ this.newLogs.emit({
stdout: event.stdout, stdout: message.stdout,
stderr: event.stderr stderr: message.stderr
}); });
} }
); );
this.processManagerService.subscribeSuccessCallback( this.processManagerService.subscribeSuccessCallback(
config.ide.deployProcessName, config.ide.deployProcessName,
(event) => this.setDeployButtonState(DeployButtonState.DEPLOYED) (message) => this.setDeployButtonState(DeployButtonState.DEPLOYED)
); );
this.processManagerService.subscribeErrorCallback( this.processManagerService.subscribeErrorCallback(
@ -109,28 +109,24 @@ export class IdeComponent implements OnInit {
); );
} }
reloadHandler(data: WebSocketMessage) { reloadHandler(message: WebSocketMessage) {
this.requestCode(); this.requestCode();
} }
readHandler(data: IDECommand) { readHandler(message: IDEMessage) {
if (this.codeState === CodeState.SAVED) { 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); 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) { autoDetectEditorLanguageIfEnabled(filename: string) {
if (!config.ide.autoDetectFileLanguage) { if (!config.ide.autoDetectFileLanguage) {
return; return;

View File

@ -16,8 +16,8 @@ export interface MessageData extends MessageMetadata {
message: string; 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>; 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 { SetValueCommand } from './set-value-command';
import { WebSocketMessage } from './websocket-message'; 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; 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 { SetValueCommand } from './set-value-command';
import { WebSocketMessage } from './websocket-message'; 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'; import { WebSocketMessage } from './websocket-message';
export interface FSMUpdate extends WebSocketMessage { export interface FSMUpdateMessage extends WebSocketMessage {
current_state: string; current_state: string;
valid_transitions: object; valid_transitions: object;
} }

View File

@ -3,7 +3,7 @@
import { WebSocketMessage } from './websocket-message'; import { WebSocketMessage } from './websocket-message';
export interface IDECommand extends WebSocketMessage { export interface IDEMessage extends WebSocketMessage {
filename: string; filename: string;
content?: string; content?: string;
files?: 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 { LogMessage } from './log-message';
import { WebSocketMessage } from './websocket-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 { LogMessage } from './log-message';
import { WebSocketMessage } from './websocket-message'; import { WebSocketMessage } from './websocket-message';
export interface ProcessCommand extends WebSocketMessage, LogMessage { export interface ProcessMessage extends WebSocketMessage, LogMessage {
name: string; name: string;
error?: string; error?: string;
} }

View File

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

View File

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

View File

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

View File

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