diff --git a/goofy-client/libs/ui/src/lib/ui/dialog/dialog.service.ts b/goofy-client/libs/ui/src/lib/ui/dialog/dialog.service.ts index 50d208e98ce2f81c2373323f6af66c6057c5ce10..999545e375592ed12f6b9d2de8b77bbbb188d1ff 100644 --- a/goofy-client/libs/ui/src/lib/ui/dialog/dialog.service.ts +++ b/goofy-client/libs/ui/src/lib/ui/dialog/dialog.service.ts @@ -1,12 +1,11 @@ +import { NoopScrollStrategy } from '@angular/cdk/overlay'; import { ComponentType } from "@angular/cdk/portal"; import { Injectable } from "@angular/core"; import { MatDialog, MatDialogConfig, MatDialogRef } from '@angular/material/dialog'; import { ApiError } from "@goofy-client/tech-shared"; import { FixedDialogComponent } from "@goofy-client/ui"; -import { ConnectionTimeoutRetryDialogComponent } from "../http-error-dialog/connection-timeout-retry-dialog/connection-timeout-retry-dialog.component"; -import { ConnectionTimeoutRetryFailDialogComponent } from "../http-error-dialog/connection-timeout-retry-fail-dialog/connection-timeout-retry-fail-dialog.component"; import { InternalServerErrorDialogComponent } from "../notification/internal-server-error-dialog/internal-server-error-dialog.component"; -import { NoopScrollStrategy } from '@angular/cdk/overlay'; +import { RetryInTimeDialog } from './retry-in-time.dialog'; @Injectable({ providedIn: 'root' }) export class DialogService { @@ -42,52 +41,14 @@ export class DialogService { } public getRetryDialog(): RetryInTimeDialog { - return new RetryInTimeDialog(this, this.dialog); + return new RetryInTimeDialog(this); } public closeAll(): void { this.dialog.closeAll(); } -} - -export class RetryInTimeDialog { - - readonly RETRY_DIALOG_CONFIG = { - disableClose: true - }; - - private readonly retryTime = 300000; - private startTime: number; - - constructor(private dialogService: DialogService, private dialog: MatDialog) { } - - public show(): void { - this.startTimer(); - this.open(); - } - private startTimer(): void { - this.startTime = new Date().getTime(); - } - - private open(): void { - this.dialogService.open(ConnectionTimeoutRetryDialogComponent, this.RETRY_DIALOG_CONFIG); - } - - public shouldRetry(): boolean { - if (this.isTimeOver()) { - this.finish(); - return false; - } - return true; - } - - private isTimeOver(): boolean { - return new Date().getTime() > (this.startTime + this.retryTime); - } - - private finish(): void { - this.dialog.closeAll(); - this.dialogService.open(ConnectionTimeoutRetryFailDialogComponent); + public closeById(dialogId: string): void { + this.dialog.getDialogById(dialogId).close(); } -} +} \ No newline at end of file diff --git a/goofy-client/libs/ui/src/lib/ui/dialog/retry-in-time.dialog.ts b/goofy-client/libs/ui/src/lib/ui/dialog/retry-in-time.dialog.ts new file mode 100644 index 0000000000000000000000000000000000000000..00f4b962e63381dc6cafcdeb6de884ca13cbb1bc --- /dev/null +++ b/goofy-client/libs/ui/src/lib/ui/dialog/retry-in-time.dialog.ts @@ -0,0 +1,44 @@ +import { DialogService } from "@goofy-client/ui"; +import { ConnectionTimeoutRetryDialogComponent } from "../http-error-dialog/connection-timeout-retry-dialog/connection-timeout-retry-dialog.component"; +import { ConnectionTimeoutRetryFailDialogComponent } from "../http-error-dialog/connection-timeout-retry-fail-dialog/connection-timeout-retry-fail-dialog.component"; + +export class RetryInTimeDialog { + + public static ID = 'RETRY_DIALOG_ID'; + + readonly RETRY_DIALOG_CONFIG = { + disableClose: true, + id: RetryInTimeDialog.ID + }; + + private readonly retryTime = 60000;// = 1min + private startTime: number; + + constructor(private dialogService: DialogService) { } + + public show(): void { + this.startTimer(); + this.open(); + } + + private startTimer(): void { + this.startTime = new Date().getTime(); + } + + private open(): void { + this.dialogService.open(ConnectionTimeoutRetryDialogComponent, this.RETRY_DIALOG_CONFIG); + } + + public shouldRetry(): boolean { + return !this.isTimeOver(); + } + + private isTimeOver(): boolean { + return new Date().getTime() > (this.startTime + this.retryTime); + } + + public finish(): void { + this.dialogService.closeById(RetryInTimeDialog.ID); + this.dialogService.open(ConnectionTimeoutRetryFailDialogComponent); + } +} \ No newline at end of file