From 62e0a99478cd4dea5d0105d6f0268d4affd07e2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Fri, 30 Aug 2019 15:59:49 +0200 Subject: [PATCH] Poll webservice url for 200 OK on frontend load --- src/app/dashboard/dashboard.component.html | 2 +- src/app/dashboard/dashboard.component.ts | 32 ++++++++++++---------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/app/dashboard/dashboard.component.html b/src/app/dashboard/dashboard.component.html index 21f7dc4..e998f0d 100644 --- a/src/app/dashboard/dashboard.component.html +++ b/src/app/dashboard/dashboard.component.html @@ -7,7 +7,7 @@
+ [ngClass]="{'deploy-blur': deploying || (polling | async)}">
diff --git a/src/app/dashboard/dashboard.component.ts b/src/app/dashboard/dashboard.component.ts index 66b0aca..39aaa00 100644 --- a/src/app/dashboard/dashboard.component.ts +++ b/src/app/dashboard/dashboard.component.ts @@ -1,6 +1,6 @@ import { Component, OnDestroy, OnInit, ChangeDetectorRef, ElementRef, ViewChild } from '@angular/core'; import { DeploymentNotificationService } from '../services/deployment-notification.service'; -import { Subscription } from 'rxjs'; +import { Subscription, BehaviorSubject } from 'rxjs'; import { WebSocketService } from '../services/websocket.service'; import { WebSocketMessage } from '../message-types/websocket-message'; import { DashboardConfigService } from '../services/config.service'; @@ -14,7 +14,7 @@ import { delay, retryWhen, tap } from 'rxjs/operators'; }) export class DashboardComponent implements OnInit, OnDestroy { deploying = false; - polling = false; + polling = new BehaviorSubject(false); deploymentNotificationSubscription: Subscription; @ViewChild('webiframe', {static: false}) webiframe: ElementRef; @ViewChild('tfwmessages', {static: false}) messages: ElementRef; @@ -42,12 +42,18 @@ export class DashboardComponent implements OnInit, OnDestroy { ngOnInit() { this.webSocketService.connect(); this.configService.init(); + this.hideIframeUntilResponseOk(); this.subscribeResizeOnLayoutChange(); this.initCommandHandling(); this.initDeploymentNotifications(); this.sendReady(); } + hideIframeUntilResponseOk() { + // TODO: hide iframe and show it after this whole deal... + this.reloadIframeWhenResponseOk(); + } + subscribeResizeOnLayoutChange() { this.configService.layout.subscribe(() => this.emitResizeEvent()); } @@ -64,10 +70,7 @@ export class DashboardComponent implements OnInit, OnDestroy { (deploying) => { this.deploying = deploying; if (!deploying && this.configService.reloadIframeOnDeploy.value) { - if (this.polling) { - this.iframeReloadSubscription.unsubscribe(); - } - this.pollingServerForIframeReload(); + this.reloadIframeWhenResponseOk(); } }); } @@ -142,8 +145,11 @@ export class DashboardComponent implements OnInit, OnDestroy { this.webiframe.nativeElement.contentWindow.frames.location.href = this.urlbar.nativeElement.value; } - pollingServerForIframeReload() { - this.polling = true; + reloadIframeWhenResponseOk() { + if (this.polling.value) { + this.iframeReloadSubscription.unsubscribe(); + } + this.polling.next(true); this.iframeReloadSubscription = this.http.get(this.actualIframeUrl, {observe: 'response'}).pipe( retryWhen(errors => errors.pipe( @@ -151,15 +157,11 @@ export class DashboardComponent implements OnInit, OnDestroy { response => { if (response.status === 200) { this.iframeReloadSubscription.unsubscribe(); - this.polling = false; + this.polling.next(false); this.reloadIframe(); - } - } - ), + }}), delay(1000) - ) - ) - ).subscribe(); + ))).subscribe(); } ngOnDestroy() {