Commit 9976c8c2 authored by jojohoch's avatar jojohoch
Browse files

[player] Refactor UnitDefinitionMenuComponent

Use private methods
Define all messages as properties
parent cf077c1f
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { FileService } from 'common/services/file.service';
import { Page } from 'common/interfaces/unit';
import { ElementCode, PagingMode, UnitState, VopStartCommand } from 'verona/models/verona';
import {
ElementCode, PagingMode, UnitState, VopPageNavigationCommand, VopStartCommand
} from 'verona/models/verona';
@Component({
selector: 'aspect-unit-definition-menu',
......@@ -13,7 +15,7 @@ export class UnitDefinitionMenuComponent {
@Input() scrollPages!: Page[];
@Input() elementCodes!: ElementCode[];
private message: VopStartCommand = {
private vopStartCommandMessage: VopStartCommand = {
type: 'vopStartCommand',
sessionId: 'dev',
unitDefinition: undefined,
......@@ -23,31 +25,34 @@ export class UnitDefinitionMenuComponent {
unitState: undefined
};
private vopPageNavigationCommandMessage: VopPageNavigationCommand = {
type: 'vopPageNavigationCommand',
sessionId: 'dev',
target: '0'
};
async load(pagingMode: PagingMode): Promise<void> {
await this.loadUnit(await FileService.loadFile(['.json']), pagingMode, {});
}
reloadUnit(): void {
this.message.unitState = { dataParts: { elementCodes: JSON.stringify(this.elementCodes) } };
this.postMessage();
this.vopStartCommandMessage.unitState = { dataParts: { elementCodes: JSON.stringify(this.elementCodes) } };
this.postMessage(this.vopStartCommandMessage);
}
loadUnit(unitDefinition: string, pagingMode: PagingMode, unitSate: UnitState): void {
this.message.unitDefinition = unitDefinition;
this.message.playerConfig = { pagingMode };
this.message.unitState = unitSate;
this.postMessage();
goToPage(pageIndex: number) {
this.vopPageNavigationCommandMessage.target = pageIndex.toString();
window.postMessage( this.vopPageNavigationCommandMessage, '*');
}
postMessage() : void {
window.postMessage(this.message, '*');
private loadUnit(unitDefinition: string, pagingMode: PagingMode, unitSate: UnitState): void {
this.vopStartCommandMessage.unitDefinition = unitDefinition;
this.vopStartCommandMessage.playerConfig = { pagingMode };
this.vopStartCommandMessage.unitState = unitSate;
this.postMessage(this.vopStartCommandMessage);
}
goToPage(pageIndex: number) {
window.postMessage({
type: 'vopPageNavigationCommand',
sessionId: 'dev',
target: pageIndex
}, '*');
}
private postMessage = (message: VopStartCommand | VopPageNavigationCommand): void => {
window.postMessage(message, '*');
};
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment