Move all message types to a standardised location

This commit is contained in:
Kristóf Tóth 2018-05-31 11:31:22 +02:00
parent 2bf68b1500
commit e510fb58f6
18 changed files with 30 additions and 30 deletions

View File

@ -3,10 +3,10 @@
import { Component, OnInit } from '@angular/core';
import { WebSocketService } from '../services/websocket.service';
import { ConsoleCommand } from './console-command';
import { ConsoleCommand } from '../message.types/console.command';
import { config } from '../config';
import { ProcessLogService } from '../services/processlog.service';
import { LogMessage } from '../services/log.message';
import { LogMessage } from '../message.types/log.message';
@Component({
selector: 'app-console',

View File

@ -5,10 +5,10 @@ import { Component, OnDestroy, OnInit, ChangeDetectorRef, ElementRef, ViewChild
import { DeploymentNotificationService } from '../services/deployment-notification.service';
import { Subscription } from 'rxjs';
import { WebSocketService } from '../services/websocket.service';
import { LayoutCommand } from './layout-command';
import { LayoutCommand } from '../message.types/layout.command';
import { config } from '../config';
import { ProcessLogService } from '../services/processlog.service';
import { LogMessage } from '../services/log.message';
import { LogMessage } from '../message.types/log.message';
@Component({
selector: 'app-dashboard',

View File

@ -16,7 +16,7 @@ import 'brace/mode/python';
import 'brace/mode/sql';
import 'brace/theme/cobalt';
import { SourceCode } from './source-code';
import { IDECommand } from '../message.types/ide.command';
import { WebSocketService } from '../services/websocket.service';
import { ProcessManagerService } from '../services/processmanager.service';
import { DeploymentNotificationService } from '../services/deployment-notification.service';
@ -89,7 +89,7 @@ export class IdeComponent implements OnInit {
}
subscribeWS() {
this.webSocketService.observeKey<SourceCode>(this.key_id).subscribe((event) => {
this.webSocketService.observeKey<IDECommand>(this.key_id).subscribe((event) => {
this.command_handlers[event.data.command](event.data);
this.changeDetectorRef.detectChanges();
});
@ -119,7 +119,7 @@ export class IdeComponent implements OnInit {
);
}
updateFileData(data: SourceCode) {
updateFileData(data: IDECommand) {
this.filename = data.filename;
this.directory = data.directory;
this.code = (data.content != null) ? data.content : this.code;
@ -127,15 +127,15 @@ export class IdeComponent implements OnInit {
this.files = data.files;
}
selectHandler(data: SourceCode) {
selectHandler(data: IDECommand) {
this.updateFileData(data);
}
reloadHandler(data: SourceCode) {
reloadHandler(data: IDECommand) {
this.requestCode();
}
readHandler(data: SourceCode) {
readHandler(data: IDECommand) {
if (this.codeState === CodeState.SAVED) {
this.updateFileData(data);
}
@ -145,7 +145,7 @@ export class IdeComponent implements OnInit {
this.setCodeState(CodeState.SAVED);
}
selectdirHandler(data: SourceCode) {
selectdirHandler(data: IDECommand) {
this.updateFileData(data);
}

View File

@ -1,7 +1,7 @@
// Copyright (C) 2018 Avatao.com Innovative Learning Kft.
// All Rights Reserved. See LICENSE file for details.
export interface SourceCode {
export interface IDECommand {
filename: string;
content?: string;
files: string[];

View File

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

View File

@ -1,7 +1,7 @@
// Copyright (C) 2018 Avatao.com Innovative Learning Kft.
// All Rights Reserved. See LICENSE file for details.
export class WSMessage<T> {
export class WebSocketMessage<T> {
key: string;
trigger?: string;
data: T;

View File

@ -5,8 +5,8 @@ import { ChangeDetectorRef, Component, OnInit } from '@angular/core';
import { MarkdownService } from '../services/markdown.service';
import { WebSocketService } from '../services/websocket.service';
import { Message } from './message';
import { MessageControl } from './messagecontrol';
import { MessagesMessage } from '../message.types/messages.message';
import { MessageControl } from '../message.types/messagecontrol';
import { config } from '../config';
@Component({
@ -15,7 +15,7 @@ import { config } from '../config';
styleUrls: ['./messages.component.scss']
})
export class MessagesComponent implements OnInit {
messages: Message[] = [];
messages: MessagesMessage[] = [];
showNextButton: boolean = config.messages.showNextButton;
command_handlers = {'showbutton': this.showButton.bind(this)};
@ -35,7 +35,7 @@ export class MessagesComponent implements OnInit {
ngOnInit() {
this.websocketService.connect();
this.websocketService.observeKey<Message>('message').subscribe(
this.websocketService.observeKey<MessagesMessage>('message').subscribe(
(event) => {
this.messages.push(event.data);
event.data.message = this.convert(event.data.message);

View File

@ -4,7 +4,7 @@
import { Injectable } from '@angular/core';
import { WebSocketService } from './websocket.service';
import { FSMUpdate } from './fsmupdate';
import { FSMUpdate } from '../message.types/fsm.update';
@Injectable()
export class FSMUpdateService {

View File

@ -3,10 +3,10 @@
import { Injectable } from '@angular/core';
import { WebSocketService } from './websocket.service';
import { ProcessLogCommand } from './processlog-command';
import { ProcessLogCommand } from '../message.types/process.log.command';
import { config } from '../config';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { LogMessage } from './log.message';
import { LogMessage } from '../message.types/log.message';
@Injectable()
export class ProcessLogService {

View File

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

View File

@ -6,7 +6,7 @@ import { QueueingSubject } from './queueing-subject';
import { Observable } from 'rxjs';
import websocketConnect from 'rxjs-websockets';
import { filter, map, share } from 'rxjs/operators';
import { WSMessage } from './wsmessage';
import { WebSocketMessage } from '../message.types/websocket.message';
function jsonWebsocketConnect(url: string, input: Observable<object>, protocols?: string | string[]) {
@ -19,7 +19,7 @@ function jsonWebsocketConnect(url: string, input: Observable<object>, protocols?
@Injectable()
export class WebSocketService {
private uplink: QueueingSubject<object>;
public downlink: Observable<WSMessage<undefined>>;
public downlink: Observable<WebSocketMessage<undefined>>;
constructor() {}
@ -33,13 +33,13 @@ export class WebSocketService {
wsproto + window.location.host + '/ws',
this.uplink = new QueueingSubject<object>()
).messages.pipe(
map(message => <WSMessage<undefined>> message),
map(message => <WebSocketMessage<undefined>> message),
share()
);
console.log('ws connected');
}
public observeKey<T>(key: string): Observable<WSMessage<T>> {
public observeKey<T>(key: string): Observable<WebSocketMessage<T>> {
return this.downlink.pipe(filter(message => message.key === key));
}