|
|
@ -12,6 +12,7 @@ import { |
|
|
TemplateRef, |
|
|
TemplateRef, |
|
|
ViewChild, |
|
|
ViewChild, |
|
|
isDevMode, |
|
|
isDevMode, |
|
|
|
|
|
OnInit, |
|
|
} from '@angular/core'; |
|
|
} from '@angular/core'; |
|
|
import { NgbModal, NgbModalOptions, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; |
|
|
import { NgbModal, NgbModalOptions, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; |
|
|
import { fromEvent, Subject } from 'rxjs'; |
|
|
import { fromEvent, Subject } from 'rxjs'; |
|
|
@ -20,6 +21,7 @@ import { Confirmation } from '../../models/confirmation'; |
|
|
import { ConfirmationService } from '../../services/confirmation.service'; |
|
|
import { ConfirmationService } from '../../services/confirmation.service'; |
|
|
import { SUPPRESS_UNSAVED_CHANGES_WARNING } from '../../tokens/suppress-unsaved-changes-warning.token'; |
|
|
import { SUPPRESS_UNSAVED_CHANGES_WARNING } from '../../tokens/suppress-unsaved-changes-warning.token'; |
|
|
import { ButtonComponent } from '../button/button.component'; |
|
|
import { ButtonComponent } from '../button/button.component'; |
|
|
|
|
|
import { DismissableModal, ModalRefService, ModalDismissMode } from './modal-ref.service'; |
|
|
|
|
|
|
|
|
export type ModalSize = 'sm' | 'md' | 'lg' | 'xl'; |
|
|
export type ModalSize = 'sm' | 'md' | 'lg' | 'xl'; |
|
|
|
|
|
|
|
|
@ -29,7 +31,7 @@ export type ModalSize = 'sm' | 'md' | 'lg' | 'xl'; |
|
|
styleUrls: ['./modal.component.scss'], |
|
|
styleUrls: ['./modal.component.scss'], |
|
|
providers: [SubscriptionService], |
|
|
providers: [SubscriptionService], |
|
|
}) |
|
|
}) |
|
|
export class ModalComponent implements OnDestroy { |
|
|
export class ModalComponent implements OnInit, OnDestroy, DismissableModal { |
|
|
/** |
|
|
/** |
|
|
* @deprecated Use centered property of options input instead. To be deleted in v5.0. |
|
|
* @deprecated Use centered property of options input instead. To be deleted in v5.0. |
|
|
*/ |
|
|
*/ |
|
|
@ -116,9 +118,26 @@ export class ModalComponent implements OnDestroy { |
|
|
@Inject(SUPPRESS_UNSAVED_CHANGES_WARNING) |
|
|
@Inject(SUPPRESS_UNSAVED_CHANGES_WARNING) |
|
|
private suppressUnsavedChangesWarningToken: boolean, |
|
|
private suppressUnsavedChangesWarningToken: boolean, |
|
|
private modal: NgbModal, |
|
|
private modal: NgbModal, |
|
|
|
|
|
private modalRefService: ModalRefService, |
|
|
) { |
|
|
) { |
|
|
this.initToggleStream(); |
|
|
this.initToggleStream(); |
|
|
} |
|
|
} |
|
|
|
|
|
ngOnInit(): void { |
|
|
|
|
|
this.modalRefService.register(this); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
dismiss(mode: ModalDismissMode) { |
|
|
|
|
|
switch (mode) { |
|
|
|
|
|
case 'hard': |
|
|
|
|
|
this.visible = false; |
|
|
|
|
|
break; |
|
|
|
|
|
case 'soft': |
|
|
|
|
|
this.close(); |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private initToggleStream() { |
|
|
private initToggleStream() { |
|
|
this.subscription.addOne(this.toggle$.pipe(debounceTime(0), distinctUntilChanged()), value => |
|
|
this.subscription.addOne(this.toggle$.pipe(debounceTime(0), distinctUntilChanged()), value => |
|
|
@ -158,6 +177,7 @@ export class ModalComponent implements OnDestroy { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ngOnDestroy(): void { |
|
|
ngOnDestroy(): void { |
|
|
|
|
|
this.modalRefService.unregister(this); |
|
|
this.toggle(false); |
|
|
this.toggle(false); |
|
|
this.destroy$.next(); |
|
|
this.destroy$.next(); |
|
|
} |
|
|
} |
|
|
|