Skip to content
Snippets Groups Projects
Commit 2ca15907 authored by rhenck's avatar rhenck
Browse files

[editor] Refactor Verona API Service

Introduce interfaces and clean the structure.
parent 33e72a0b
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { registerLocaleData } from '@angular/common';
import localeDe from '@angular/common/locales/de';
import { VeronaAPIService } from './services/verona-api.service';
import { VeronaAPIService, VoeStartCommand } from './services/verona-api.service';
import { UnitService } from './services/unit.service';
@Component({
......@@ -18,7 +18,6 @@ import { UnitService } from './services/unit.service';
]
})
export class AppComponent implements OnInit {
editorConfig!: Record<string, any>;
isStandalone = (): boolean => window === window.parent;
constructor(private unitService: UnitService,
......@@ -30,12 +29,12 @@ export class AppComponent implements OnInit {
ngOnInit(): void {
this.veronaApiService.voeStartCommand
.subscribe((message: Record<string, any>): void => {
.subscribe((message: VoeStartCommand): void => {
this.unitService.loadUnitDefinition(message.unitDefinition);
});
this.veronaApiService.voeGetDefinitionRequest
.subscribe(() => {
this.veronaApiService.sendVoeDefinitionChangedNotification(this.unitService.getUnitAsJSON());
this.veronaApiService.sendVoeDefinitionChangedNotification(JSON.stringify(this.unitService.unit));
});
this.veronaApiService.sendVoeReadyNotification();
......
......@@ -6,32 +6,29 @@ import { fromEvent, Observable, Subject } from 'rxjs';
})
export class VeronaAPIService {
sessionID: string = '';
private _voeStartCommand = new Subject<Record<string, string>>(); // TODO proper interfaces
private _voeGetDefinitionRequest = new Subject<Record<string, string>>();
private _voeStartCommand = new Subject<VoeStartCommand>(); // TODO proper interfaces
private _voeGetDefinitionRequest = new Subject<VoeGetDefinitionRequest>();
private isStandalone = (): boolean => window === window.parent;
constructor() {
fromEvent(window, 'message')
.subscribe((event: Event): void => {
const message = (event as MessageEvent).data;
this.handleMessage(message);
this.handleMessage((event as MessageEvent).data);
});
}
private handleMessage(messageData: Record<string, string>): void {
private handleMessage(messageData: VoeGetDefinitionRequest | VoeStartCommand): void {
switch (messageData.type) {
case 'voeStartCommand':
// console.log('editor: voeStartCommand ', messageData);
this.sessionID = messageData.sessionId;
this._voeStartCommand.next(messageData);
this._voeStartCommand.next(messageData as VoeStartCommand);
break;
case 'voeGetDefinitionRequest':
// console.log('editor: voeGetDefinitionRequest ', messageData);
this._voeGetDefinitionRequest.next(messageData);
break;
default:
// console.warn(`editor: got message of unknown type ${messageData.type}`);
console.warn(`editor: got message of unknown type ${messageData}`);
}
}
......@@ -63,11 +60,24 @@ export class VeronaAPIService {
});
}
get voeStartCommand(): Observable<any> {
get voeStartCommand(): Observable<VoeStartCommand> {
return this._voeStartCommand.asObservable();
}
get voeGetDefinitionRequest(): Observable<any> {
get voeGetDefinitionRequest(): Observable<VoeGetDefinitionRequest> {
return this._voeGetDefinitionRequest.asObservable();
}
}
export interface VoeStartCommand extends MessageEvent {
sessionId: string,
unitDefinition: string,
unitDefinitionType: string,
editorConfig: {
definitionReportPolicy: string
}
}
export interface VoeGetDefinitionRequest extends MessageEvent {
sessionId: string
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment