2019-09-24 16:55:03 +02:00
|
|
|
import { Injectable } from '@angular/core';
|
2023-10-05 15:58:45 +02:00
|
|
|
import { MatLegacyDialog as MatDialog } from '@angular/material/legacy-dialog';
|
2019-09-24 16:55:03 +02:00
|
|
|
import { CanDeactivate } from '@angular/router';
|
2019-12-11 15:51:03 +01:00
|
|
|
import { CheckDeactivateBaseComponent } from '@app/library/deactivate/deactivate.component';
|
|
|
|
import { BaseComponent } from '@common/base/base.component';
|
|
|
|
import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component';
|
2019-09-24 16:55:03 +02:00
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2019-12-11 15:51:03 +01:00
|
|
|
import { Observable } from 'rxjs';
|
2019-09-24 16:55:03 +02:00
|
|
|
import { map } from 'rxjs/operators';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class CanDeactivateGuard extends BaseComponent implements CanDeactivate<CheckDeactivateBaseComponent> {
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private dialog: MatDialog,
|
|
|
|
public language: TranslateService
|
|
|
|
) {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
canDeactivate(component: CheckDeactivateBaseComponent): boolean | Observable<boolean> {
|
|
|
|
|
|
|
|
if (component.canDeactivate()) {
|
2019-12-11 15:51:03 +01:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
|
|
|
|
maxWidth: '700px',
|
|
|
|
data: {
|
2019-09-24 16:55:03 +02:00
|
|
|
message: this.language.instant('GENERAL.CONFIRMATION-DIALOG.LEAVE-PAGE'),
|
|
|
|
warning: this.language.instant('GENERAL.CONFIRMATION-DIALOG.LEAVE-WARNING'),
|
2019-12-11 15:51:03 +01:00
|
|
|
cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL'),
|
2019-09-24 16:55:03 +02:00
|
|
|
confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.LEAVE'),
|
2021-07-23 16:03:29 +02:00
|
|
|
// icon: 'error_outline'
|
2019-12-11 15:51:03 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return dialogRef.afterClosed().pipe(map(x => x ? true : false));
|
|
|
|
}
|
2019-09-24 16:55:03 +02:00
|
|
|
}
|
|
|
|
}
|