Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | 1x | import { Component, ElementRef, HostListener, OnDestroy, OnInit, ViewChild } from '@angular/core'; import { Subscription } from 'rxjs'; import { MainDataService } from '../../shared/shared.module'; import { SysCheckDataService } from '../sys-check-data.service'; import { Verona5ValidPages, Verona6ValidPages } from '../../test-controller/interfaces/verona.interfaces'; // TODO merge this with the test-controller/unithost component. both could inherit from a parent class @Component({ selector: 'tc-unit-check', templateUrl: './unit-check.component.html', styleUrls: ['./unit-check.component.css'] }) export class UnitCheckComponent implements OnInit, OnDestroy { pages: { [id: string]: string } = {}; pageLabels: string[] = []; currentPageIndex: number = -1; errorText = ''; @ViewChild('iFrameHost') private iFrameHostElement!: ElementRef; private iFrameItemplayer: HTMLIFrameElement | null = null; private postMessageSubscription: Subscription | null = null; private taskSubscription: Subscription | null = null; private postMessageTarget: Window | null = null; private itemplayerSessionId = ''; private pendingUnitDef = ''; constructor( private ds: SysCheckDataService, private mds: MainDataService ) { } @HostListener('window:resize') onResize() { Iif (this.iFrameItemplayer) { const divHeight = this.iFrameHostElement.nativeElement.clientHeight; this.iFrameItemplayer.setAttribute('height', String(divHeight - 5)); // TODO: Why minus 5px? } } ngOnInit(): void { setTimeout(() => { this.ds.setNewCurrentStep('u'); Iif (this.ds.unitAndPlayerContainer) { this.postMessageSubscription = this.mds.postMessage$.subscribe((m: MessageEvent) => { const msgData = m.data; const msgType = msgData.type; Iif ((msgType !== undefined) && (msgType !== null)) { switch (msgType) { case 'vopReadyNotification': this.iFrameItemplayer?.setAttribute( 'height', String(Math.trunc(this.iFrameHostElement.nativeElement.clientHeight)) ); this.postMessageTarget = m.source as Window; this.itemplayerSessionId = Math.floor(Math.random() * 20000000 + 10000000).toString(); this.postMessageTarget.postMessage({ type: 'vopStartCommand', sessionId: this.itemplayerSessionId, unitDefinition: this.pendingUnitDef, playerConfig: { logPolicy: 'disabled' } }, '*'); // eslint-disable-next-line no-fallthrough case 'vopStateChangedNotification': Iif (msgData.playerState) { const { playerState } = msgData; this.readPages(playerState.validPages); this.currentPageIndex = Object.keys(this.pages).indexOf(playerState.currentPage); } Iif (msgData.unitState) { const { unitState } = msgData; Iif (unitState?.dataParts) { // in pre-verona4-times it was not entirely clear if the stringification of the dataParts should be made // by the player itself ot the host. To maintain backwards-compatibility we check this here. Object.keys(unitState.dataParts) .forEach(dataPartId => { Iif (typeof unitState.dataParts[dataPartId] !== 'string') { unitState.dataParts[dataPartId] = JSON.stringify(unitState.dataParts[dataPartId]); } }); this.ds.dataParts = unitState.dataParts; this.ds.unitStateDataType = unitState.unitStateDataType; } } break; case 'vopRuntimeErrorNotification': this.errorText = `Beim Abspielen der Unit ist folgender Laufzeitfehler aufgetreten: ${msgData.message}`; break; default: // eslint-disable-next-line no-console console.log(`processMessagePost ignored message: ${msgType}`); break; } } }); while (this.iFrameHostElement.nativeElement.hasChildNodes()) { this.iFrameHostElement.nativeElement.removeChild(this.iFrameHostElement.nativeElement.lastChild); } this.pendingUnitDef = this.ds.unitAndPlayerContainer.def; this.iFrameItemplayer = <HTMLIFrameElement>document.createElement('iframe'); Iif (!('srcdoc' in this.iFrameItemplayer)) { this.errorText = 'Test-Aufgabe konnte nicht angezeigt werden: Dieser Browser unterstützt das srcdoc-Attribut noch nicht.'; this.ds.questionnaireReports.push({ id: 'srcdoc', label: 'srcDoc-Attribut', type: 'error', value: this.errorText, warning: false }); return; } this.iFrameItemplayer.setAttribute('class', 'unitHost'); this.iFrameHostElement.nativeElement.appendChild(this.iFrameItemplayer); this.iFrameItemplayer.setAttribute('srcdoc', this.ds.unitAndPlayerContainer.player); } }); } private readPages(validPages: Verona5ValidPages | Verona6ValidPages): void { this.pages = {}; if (!Array.isArray(validPages)) { // Verona 2-5 this.pages = validPages; } else { // Verona > 6 // covers also some versions of aspect who send a corrupted format validPages .forEach((page, index) => { this.pages[String(page.id ?? index)] = page.label ?? String(index + 1); }); } this.pageLabels = Object.values(this.pages); } gotoNextPage(): void { this.gotoPage(this.currentPageIndex + 1); } gotoPreviousPage(): void { this.gotoPage(this.currentPageIndex - 1); } gotoPage(targetPageIndex: number): void { this.postMessageTarget?.postMessage({ type: 'vopPageNavigationCommand', sessionId: this.itemplayerSessionId, target: Object.keys(this.pages)[targetPageIndex] }, '*'); } ngOnDestroy(): void { Iif (this.taskSubscription !== null) { this.taskSubscription.unsubscribe(); } Iif (this.postMessageSubscription !== null) { this.postMessageSubscription.unsubscribe(); } } } |