From fe026f77d8332e0c78b70821332de7d1db3513ac Mon Sep 17 00:00:00 2001
From: mechtelm <nicht@mehr.fragen>
Date: Thu, 10 Sep 2020 21:23:28 +0200
Subject: [PATCH] test works (hm not completed?)

---
 .../network-check/network-check.component.ts  | 50 +++++-----
 .../network-check/tc-speed-chart.component.ts |  7 --
 src/app/sys-check/report/report.component.ts  |  2 +-
 .../unit-check/unit-check.component.ts        | 95 ++++++++++---------
 4 files changed, 74 insertions(+), 80 deletions(-)

diff --git a/src/app/sys-check/network-check/network-check.component.ts b/src/app/sys-check/network-check/network-check.component.ts
index f32db21d..fefd1a49 100644
--- a/src/app/sys-check/network-check/network-check.component.ts
+++ b/src/app/sys-check/network-check/network-check.component.ts
@@ -58,10 +58,8 @@ export class NetworkCheckComponent implements OnInit, OnDestroy {
           networkType: connection.type || null,
         };
       }
-      if (this.ds.networkReport.length === 0) {
+      if (this.ds.checkConfig && this.ds.networkReport.length === 0) {
         this.startCheck();
-      } else {
-
       }
     })
   }
@@ -86,29 +84,31 @@ export class NetworkCheckComponent implements OnInit, OnDestroy {
   }
 
   private plotPrepare(isDownloadPart: boolean) {
-    const testSizes = (isDownloadPart) ? this.ds.checkConfig.downloadSpeed.sequenceSizes : this.ds.checkConfig.uploadSpeed.sequenceSizes;
-    const plotterSettings = {
-      css: 'border: 1px solid silver; margin: 2px; width: 100%;',
-      width: 800,
-      height: 240,
-      labelPadding: 4,
-      xAxisMaxValue: 16 + Math.max(...testSizes),
-      xAxisMinValue: Math.min(...testSizes),
-      yAxisMaxValue: (isDownloadPart) ? 1200 : 2500,
-      yAxisMinValue: (isDownloadPart) ? 20 : 100,
-      xAxisStepSize: 4,
-      yAxisStepSize: (isDownloadPart) ? 50 : 100,
-      lineWidth: 5,
-      xProject: x => (x === 0 ) ? 0 : Math.sign(x) * Math.log2(Math.abs(x)),
-      yProject: y => (y === 0 ) ? 0 : Math.sign(y) * Math.log(Math.abs(y)),
-      xAxisLabels: (x) => (testSizes.indexOf(x) > -1) ? this.humanReadableBytes(x, false, true) : '',
-      yAxisLabels: (y, i) => (i < 10) ? this.humanReadableMilliseconds(y) : ' ',
-    };
+    if (this.ds.checkConfig) {
+      const testSizes = (isDownloadPart) ? this.ds.checkConfig.downloadSpeed.sequenceSizes : this.ds.checkConfig.uploadSpeed.sequenceSizes;
+      const plotterSettings = {
+        css: 'border: 1px solid silver; margin: 2px; width: 100%;',
+        width: 800,
+        height: 240,
+        labelPadding: 4,
+        xAxisMaxValue: 16 + Math.max(...testSizes),
+        xAxisMinValue: Math.min(...testSizes),
+        yAxisMaxValue: (isDownloadPart) ? 1200 : 2500,
+        yAxisMinValue: (isDownloadPart) ? 20 : 100,
+        xAxisStepSize: 4,
+        yAxisStepSize: (isDownloadPart) ? 50 : 100,
+        lineWidth: 5,
+        xProject: x => (x === 0 ) ? 0 : Math.sign(x) * Math.log2(Math.abs(x)),
+        yProject: y => (y === 0 ) ? 0 : Math.sign(y) * Math.log(Math.abs(y)),
+        xAxisLabels: (x) => (testSizes.indexOf(x) > -1) ? this.humanReadableBytes(x, false, true) : '',
+        yAxisLabels: (y, i) => (i < 10) ? this.humanReadableMilliseconds(y) : ' ',
+      };
 
-    if (isDownloadPart) {
-      this.downloadPlotter.reset(plotterSettings);
-    } else {
-      this.uploadPlotter.reset(plotterSettings);
+      if (isDownloadPart) {
+        this.downloadPlotter.reset(plotterSettings);
+      } else {
+        this.uploadPlotter.reset(plotterSettings);
+      }
     }
   }
 
diff --git a/src/app/sys-check/network-check/tc-speed-chart.component.ts b/src/app/sys-check/network-check/tc-speed-chart.component.ts
index 1fdaeb3e..625d7fcd 100644
--- a/src/app/sys-check/network-check/tc-speed-chart.component.ts
+++ b/src/app/sys-check/network-check/tc-speed-chart.component.ts
@@ -87,34 +87,27 @@ export class TcSpeedChartComponent {
   }
 
   public plotData(dataPoints: Array<[number, number]>, color: string = null, style: 'line' | 'dots' = 'line') {
-
     if (!dataPoints.length) {
       return;
     }
-
     color = color || this.randomColor();
-
     const coordinates = this.dataPointsToCoordinates(dataPoints);
-
     color = color || this.randomColor();
     const oldStrokeColor = this.context.strokeStyle;
     const oldFillColor = this.context.fillStyle;
     this.context.strokeStyle = color;
     this.context.fillStyle = color;
-
     if (style === 'line') {
       this.paintLine(coordinates);
     }
     if (style === 'dots') {
       this.paintDots(coordinates);
     }
-
     this.context.strokeStyle = oldStrokeColor;
     this.context.fillStyle = oldFillColor;
   }
 
   private dataPointsToCoordinates(dataPoints: Array<[number, number]>): Array<[number, number]> {
-
     return dataPoints
       .map((xy): [number, number] => [ // apply projection
         this.config.xProject(xy[0]),
diff --git a/src/app/sys-check/report/report.component.ts b/src/app/sys-check/report/report.component.ts
index b970c66d..1a881b0d 100644
--- a/src/app/sys-check/report/report.component.ts
+++ b/src/app/sys-check/report/report.component.ts
@@ -74,7 +74,7 @@ export class ReportComponent implements OnInit {
     setTimeout(() => {
       this.ds.setNewCurrentStep('r');
       this.questionnaireDataWarnings = [];
-      if (this.ds.checkConfig.questions.length > 0) {
+      if (this.ds.checkConfig && this.ds.checkConfig.questions.length > 0) {
         if (this.ds.questionnaireReport.length > 0) {
           this.ds.questionnaireReport.forEach(re => {
             if (re.warning) {
diff --git a/src/app/sys-check/unit-check/unit-check.component.ts b/src/app/sys-check/unit-check/unit-check.component.ts
index ee96e8c1..2775e2ba 100644
--- a/src/app/sys-check/unit-check/unit-check.component.ts
+++ b/src/app/sys-check/unit-check/unit-check.component.ts
@@ -41,57 +41,58 @@ export class UnitCheckComponent implements OnInit, OnDestroy {
   ngOnInit() {
     setTimeout(() => {
       this.ds.setNewCurrentStep('u');
-      this.iFrameHostElement = <HTMLElement>document.querySelector('#iFrameHost');
-      this.postMessageSubscription = this.mds.postMessage$.subscribe((m: MessageEvent) => {
-        const msgData = m.data;
-        const msgType = msgData['type'];
-
-        if ((msgType !== undefined) && (msgType !== null)) {
-          switch (msgType) {
-
-            case 'vopReadyNotification':
-              this.iFrameItemplayer.setAttribute('height', String(Math.trunc(this.iFrameHostElement.clientHeight)));
-              this.postMessageTarget = m.source as Window;
-              if (typeof this.postMessageTarget !== 'undefined') {
-                this.itemplayerSessionId = Math.floor(Math.random() * 20000000 + 10000000).toString();
-                this.postMessageTarget.postMessage({
-                  type: 'vopStartCommand',
-                  sessionId: this.itemplayerSessionId,
-                  unitDefinition: this.pendingUnitDef,
-                  playerConfig: {
-                    logPolicy: 'disabled',
-                    stateReportPolicy: 'none'
-                  }
-                }, '*');
-              }
-              break;
-
-            case 'vopStateChangedNotification':
-              if (msgData['playerState']) {
-                const playerState = msgData['playerState'];
-                this.setPageList(Object.keys(playerState.validPages), playerState.currentPage);
-              }
-              break;
-
-            default:
-              console.log('processMessagePost ignored message: ' + msgType);
-              break;
+      if (this.ds.unitAndPlayerContainer) {
+        this.iFrameHostElement = <HTMLElement>document.querySelector('#iFrameHost');
+        this.postMessageSubscription = this.mds.postMessage$.subscribe((m: MessageEvent) => {
+          const msgData = m.data;
+          const msgType = msgData['type'];
+
+          if ((msgType !== undefined) && (msgType !== null)) {
+            switch (msgType) {
+
+              case 'vopReadyNotification':
+                this.iFrameItemplayer.setAttribute('height', String(Math.trunc(this.iFrameHostElement.clientHeight)));
+                this.postMessageTarget = m.source as Window;
+                if (typeof this.postMessageTarget !== 'undefined') {
+                  this.itemplayerSessionId = Math.floor(Math.random() * 20000000 + 10000000).toString();
+                  this.postMessageTarget.postMessage({
+                    type: 'vopStartCommand',
+                    sessionId: this.itemplayerSessionId,
+                    unitDefinition: this.pendingUnitDef,
+                    playerConfig: {
+                      logPolicy: 'disabled',
+                      stateReportPolicy: 'none'
+                    }
+                  }, '*');
+                }
+                break;
+
+              case 'vopStateChangedNotification':
+                if (msgData['playerState']) {
+                  const playerState = msgData['playerState'];
+                  this.setPageList(Object.keys(playerState.validPages), playerState.currentPage);
+                }
+                break;
+
+              default:
+                console.log('processMessagePost ignored message: ' + msgType);
+                break;
+            }
           }
-        }
-      });
+        });
 
-      while (this.iFrameHostElement.hasChildNodes()) {
-        this.iFrameHostElement.removeChild(this.iFrameHostElement.lastChild);
+        while (this.iFrameHostElement.hasChildNodes()) {
+          this.iFrameHostElement.removeChild(this.iFrameHostElement.lastChild);
+        }
+        this.pendingUnitDef = this.ds.unitAndPlayerContainer.def;
+        this.iFrameItemplayer = <HTMLIFrameElement>document.createElement('iframe');
+        this.iFrameItemplayer.setAttribute('sandbox', 'allow-forms allow-scripts allow-same-origin');
+        this.iFrameItemplayer.setAttribute('class', 'unitHost');
+        this.iFrameItemplayer.setAttribute('height', String(this.iFrameHostElement.clientHeight - 5));
+        this.iFrameHostElement.appendChild(this.iFrameItemplayer);
+        srcDoc.set(this.iFrameItemplayer, this.ds.unitAndPlayerContainer.player);
       }
-      this.pendingUnitDef = this.ds.unitAndPlayerContainer.def;
-      this.iFrameItemplayer = <HTMLIFrameElement>document.createElement('iframe');
-      this.iFrameItemplayer.setAttribute('sandbox', 'allow-forms allow-scripts allow-same-origin');
-      this.iFrameItemplayer.setAttribute('class', 'unitHost');
-      this.iFrameItemplayer.setAttribute('height', String(this.iFrameHostElement.clientHeight - 5));
-      this.iFrameHostElement.appendChild(this.iFrameItemplayer);
-      srcDoc.set(this.iFrameItemplayer, this.ds.unitAndPlayerContainer.player);
     })
-
   }
 
   setPageList(validPages: string[], currentPage: string) {
-- 
GitLab