Browse Source

fix(theme-shared): modal component

pull/1572/head
mehmet-erim 7 years ago
parent
commit
9676ea1bed
  1. 8
      npm/ng-packs/packages/theme-shared/src/lib/abstracts/toaster.ts
  2. 5
      npm/ng-packs/packages/theme-shared/src/lib/components/modal/modal.component.html
  3. 27
      npm/ng-packs/packages/theme-shared/src/lib/components/modal/modal.component.ts
  4. 8
      npm/ng-packs/packages/theme-shared/src/lib/services/confirmation.service.ts
  5. 4
      npm/ng-packs/packages/theme-shared/src/lib/services/toaster.service.ts

8
npm/ng-packs/packages/theme-shared/src/lib/abstracts/toaster.ts

@ -2,12 +2,12 @@ import { MessageService } from 'primeng/components/common/messageservice';
import { Observable, Subject } from 'rxjs'; import { Observable, Subject } from 'rxjs';
import { Toaster } from '../models/toaster'; import { Toaster } from '../models/toaster';
export class AbstractToasterClass<T = Toaster.Options> { export class AbstractToaster<T = Toaster.Options> {
protected status$: Subject<Toaster.Status>; status$: Subject<Toaster.Status>;
protected key: string = 'abpToast'; key: string = 'abpToast';
protected sticky: boolean = false; sticky: boolean = false;
constructor(protected messageService: MessageService) {} constructor(protected messageService: MessageService) {}
info(message: string, title: string, options?: T): Observable<Toaster.Status> { info(message: string, title: string, options?: T): Observable<Toaster.Status> {

5
npm/ng-packs/packages/theme-shared/src/lib/components/modal/modal.component.html

@ -1,9 +1,8 @@
<div <div
*ngIf="showModal"
id="abp-modal" id="abp-modal"
tabindex="-1" tabindex="-1"
class="modal fade {{ modalClass }}" class="modal fade {{ modalClass }} d-block show"
[class.show]="visible"
[style.display]="visible ? 'block' : 'none'"
[style.padding-right.px]="'15'" [style.padding-right.px]="'15'"
> >
<div <div

27
npm/ng-packs/packages/theme-shared/src/lib/components/modal/modal.component.ts

@ -27,8 +27,13 @@ export class ModalComponent implements OnDestroy {
return this._visible; return this._visible;
} }
set visible(value: boolean) { set visible(value: boolean) {
if (typeof value !== 'boolean') return;
if (!this.modalContent) { if (!this.modalContent) {
setTimeout(() => (this.visible = value), 0); setTimeout(() => {
this.showModal = value;
this.visible = value;
}, 0);
return; return;
} }
@ -40,7 +45,7 @@ export class ModalComponent implements OnDestroy {
this.renderer.addClass(this.modalContent.nativeElement, 'fade-out-top'); this.renderer.addClass(this.modalContent.nativeElement, 'fade-out-top');
setTimeout(() => { setTimeout(() => {
this.setVisible(value); this.setVisible(value);
this.renderer.removeClass(this.modalContent.nativeElement, 'fade-out-top'); // this.renderer.removeClass(this.modalContent.nativeElement, 'fade-out-top');
this.ngOnDestroy(); this.ngOnDestroy();
}, 350); }, 350);
} }
@ -66,10 +71,12 @@ export class ModalComponent implements OnDestroy {
_visible: boolean = false; _visible: boolean = false;
closable: boolean = false; showModal: boolean = false;
isOpenConfirmation: boolean = false; isOpenConfirmation: boolean = false;
closable: boolean = false;
destroy$ = new Subject<void>(); destroy$ = new Subject<void>();
constructor(private renderer: Renderer2, private confirmationService: ConfirmationService) {} constructor(private renderer: Renderer2, private confirmationService: ConfirmationService) {}
@ -81,6 +88,8 @@ export class ModalComponent implements OnDestroy {
setVisible(value: boolean) { setVisible(value: boolean) {
this._visible = value; this._visible = value;
this.visibleChange.emit(value); this.visibleChange.emit(value);
this.showModal = value;
value value
? timer(500) ? timer(500)
.pipe(take(1)) .pipe(take(1))
@ -93,14 +102,16 @@ export class ModalComponent implements OnDestroy {
.pipe( .pipe(
debounceTime(350), debounceTime(350),
takeUntil(this.destroy$), takeUntil(this.destroy$),
filter( filter((event: MouseEvent) => {
(event: MouseEvent) => const isOpenConfirmation = this.isOpenConfirmation || document.querySelector('p-toastitem');
return (
event && event &&
this.closable && this.closable &&
this.modalContent && this.modalContent &&
!this.isOpenConfirmation && !isOpenConfirmation &&
!this.modalContent.nativeElement.contains(event.target), !this.modalContent.nativeElement.contains(event.target)
), );
}),
) )
.subscribe(_ => { .subscribe(_ => {
this.close(); this.close();

8
npm/ng-packs/packages/theme-shared/src/lib/services/confirmation.service.ts

@ -1,10 +1,10 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { AbstractToasterClass } from '../abstracts/toaster'; import { AbstractToaster } from '../abstracts/toaster';
import { Confirmation } from '../models/confirmation'; import { Confirmation } from '../models/confirmation';
@Injectable({ providedIn: 'root' }) @Injectable({ providedIn: 'root' })
export class ConfirmationService extends AbstractToasterClass<Confirmation.Options> { export class ConfirmationService extends AbstractToaster<Confirmation.Options> {
protected key: string = 'abpConfirmation'; key: string = 'abpConfirmation';
protected sticky: boolean = true; sticky: boolean = true;
} }

4
npm/ng-packs/packages/theme-shared/src/lib/services/toaster.service.ts

@ -1,9 +1,9 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { AbstractToasterClass } from '../abstracts/toaster'; import { AbstractToaster } from '../abstracts/toaster';
import { Message } from 'primeng/components/common/message'; import { Message } from 'primeng/components/common/message';
@Injectable({ providedIn: 'root' }) @Injectable({ providedIn: 'root' })
export class ToasterService extends AbstractToasterClass { export class ToasterService extends AbstractToaster {
addAll(messages: Message[]): void { addAll(messages: Message[]): void {
this.messageService.addAll(messages.map(message => ({ key: this.key, ...message }))); this.messageService.addAll(messages.map(message => ({ key: this.key, ...message })));
} }

Loading…
Cancel
Save