mirror of
https://github.com/avatao-content/frontend-tutorial-framework
synced 2024-12-04 19:11:33 +00:00
Poll webservice url for 200 OK on frontend load
This commit is contained in:
parent
4e60bfc8df
commit
62e0a99478
@ -7,7 +7,7 @@
|
||||
<app-messages (newMessageEvent)="scrollMessagesToBottom()"></app-messages>
|
||||
</div>
|
||||
<div class="tfw-web tao-grid-top-left"
|
||||
[ngClass]="{'deploy-blur': deploying || polling}">
|
||||
[ngClass]="{'deploy-blur': deploying || (polling | async)}">
|
||||
<div *ngIf="iframeUrl | async" class="iframe-container">
|
||||
<div *ngIf="showUrlBar | async" class="urlbar-container">
|
||||
<button class="refresh btn btn-sm rounded-circle" (click)="reloadIframe()">↻</button>
|
||||
|
@ -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<boolean>(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() {
|
||||
|
Loading…
Reference in New Issue
Block a user