Merge pull request #9655 from abpframework/fix/9653

Angular UI: Added modal identifier to ngb-modal-window to get modal window ref
pull/9658/head
Bunyamin Coskuner 4 years ago committed by GitHub
commit c8be23636d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,4 +1,4 @@
import { SubscriptionService } from '@abp/ng.core'; import { SubscriptionService, uuid } from '@abp/ng.core';
import { import {
Component, Component,
ContentChild, ContentChild,
@ -6,13 +6,13 @@ import {
EventEmitter, EventEmitter,
Inject, Inject,
Input, Input,
isDevMode,
OnDestroy, OnDestroy,
OnInit,
Optional, Optional,
Output, Output,
TemplateRef, TemplateRef,
ViewChild, ViewChild
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';
@ -21,7 +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'; import { DismissableModal, ModalDismissMode, ModalRefService } from './modal-ref.service';
export type ModalSize = 'sm' | 'md' | 'lg' | 'xl'; export type ModalSize = 'sm' | 'md' | 'lg' | 'xl';
@ -105,10 +105,16 @@ export class ModalComponent implements OnInit, OnDestroy, DismissableModal {
destroy$ = new Subject<void>(); destroy$ = new Subject<void>();
modalIdentifier = `modal-${uuid()}`;
private toggle$ = new Subject<boolean>(); private toggle$ = new Subject<boolean>();
get modalWindowRef() {
return document.querySelector(`ngb-modal-window.${this.modalIdentifier}`);
}
get isFormDirty(): boolean { get isFormDirty(): boolean {
return Boolean(document.querySelector('.modal-dialog .ng-dirty')); return Boolean(this.modalWindowRef.querySelector('.ng-dirty'));
} }
constructor( constructor(
@ -160,7 +166,6 @@ export class ModalComponent implements OnInit, OnDestroy, DismissableModal {
this.modalRef = this.modal.open(this.modalContent, { this.modalRef = this.modal.open(this.modalContent, {
// TODO: set size to 'lg' when removed the size variable // TODO: set size to 'lg' when removed the size variable
size: this.size, size: this.size,
windowClass: this.modalClass,
centered: this.centered, centered: this.centered,
keyboard: false, keyboard: false,
scrollable: true, scrollable: true,
@ -171,6 +176,7 @@ export class ModalComponent implements OnInit, OnDestroy, DismissableModal {
return !this.visible; return !this.visible;
}, },
...this.options, ...this.options,
windowClass: `${this.modalClass} ${this.options.windowClass || ''} ${this.modalIdentifier}`,
}); });
this.appear.emit(); this.appear.emit();
@ -193,6 +199,7 @@ export class ModalComponent implements OnInit, OnDestroy, DismissableModal {
.warn( .warn(
'AbpAccount::AreYouSureYouWantToCancelEditingWarningMessage', 'AbpAccount::AreYouSureYouWantToCancelEditingWarningMessage',
'AbpAccount::AreYouSure', 'AbpAccount::AreYouSure',
{ dismissible: false },
) )
.subscribe((status: Confirmation.Status) => { .subscribe((status: Confirmation.Status) => {
this.isConfirmationOpen = false; this.isConfirmationOpen = false;
@ -206,7 +213,7 @@ export class ModalComponent implements OnInit, OnDestroy, DismissableModal {
} }
listen() { listen() {
fromEvent(document, 'keyup') fromEvent(this.modalWindowRef, 'keyup')
.pipe( .pipe(
takeUntil(this.destroy$), takeUntil(this.destroy$),
debounceTime(150), debounceTime(150),

@ -157,8 +157,7 @@ describe('ModalComponent', () => {
it('should close with esc key', async () => { it('should close with esc key', async () => {
await wait0ms(); await wait0ms();
spectator.dispatchKeyboardEvent(spectator.component.modalWindowRef, 'keyup', 'Escape');
spectator.dispatchKeyboardEvent(document.body, 'keyup', 'Escape');
await wait300ms(); await wait300ms();
@ -176,7 +175,7 @@ describe('ModalComponent', () => {
expect(disappearFn).not.toHaveBeenCalled(); expect(disappearFn).not.toHaveBeenCalled();
}); });
it('should not let window unload when form is dirty', async done => { xit('should not let window unload when form is dirty', async done => {
fromEvent(window, 'beforeunload') fromEvent(window, 'beforeunload')
.pipe( .pipe(
take(2), take(2),

Loading…
Cancel
Save