Skip to content
Snippets Groups Projects
Commit e485b696 authored by OZGCloud's avatar OZGCloud
Browse files

move retry-in-time-dialog to own file

parent 71365233
No related branches found
No related tags found
No related merge requests found
import { NoopScrollStrategy } from '@angular/cdk/overlay';
import { ComponentType } from "@angular/cdk/portal"; import { ComponentType } from "@angular/cdk/portal";
import { Injectable } from "@angular/core"; import { Injectable } from "@angular/core";
import { MatDialog, MatDialogConfig, MatDialogRef } from '@angular/material/dialog'; import { MatDialog, MatDialogConfig, MatDialogRef } from '@angular/material/dialog';
import { ApiError } from "@goofy-client/tech-shared"; import { ApiError } from "@goofy-client/tech-shared";
import { FixedDialogComponent } from "@goofy-client/ui"; 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 { 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' }) @Injectable({ providedIn: 'root' })
export class DialogService { export class DialogService {
...@@ -42,52 +41,14 @@ export class DialogService { ...@@ -42,52 +41,14 @@ export class DialogService {
} }
public getRetryDialog(): RetryInTimeDialog { public getRetryDialog(): RetryInTimeDialog {
return new RetryInTimeDialog(this, this.dialog); return new RetryInTimeDialog(this);
} }
public closeAll(): void { public closeAll(): void {
this.dialog.closeAll(); 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 { public closeById(dialogId: string): void {
this.startTime = new Date().getTime(); this.dialog.getDialogById(dialogId).close();
}
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);
} }
} }
\ No newline at end of file
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment