fix(theme-shared): fix closing confirmation with esc

pull/2606/head
mehmet-erim 6 years ago
parent 75b32f21bc
commit 5246e60647

@ -38,12 +38,11 @@ export class ConfirmationComponent {
) { ) {
this.confirmationService.confirmation$.subscribe(confirmation => { this.confirmationService.confirmation$.subscribe(confirmation => {
this.data = confirmation; this.data = confirmation;
this.visible = true; this.visible = !!confirmation;
}); });
} }
close(status: Toaster.Status) { close(status: Toaster.Status) {
this.confirmationService.clear(status); this.confirmationService.clear(status);
this.visible = false;
} }
} }

@ -2,6 +2,7 @@ import { Component, Input, OnInit } from '@angular/core';
import { Toaster } from '../../models'; import { Toaster } from '../../models';
import { ToasterService } from '../../services/toaster.service'; import { ToasterService } from '../../services/toaster.service';
import { LocalizationService } from '@abp/ng.core'; import { LocalizationService } from '@abp/ng.core';
import snq from 'snq';
@Component({ @Component({
selector: 'abp-toast', selector: 'abp-toast',
@ -38,8 +39,8 @@ export class ToastComponent implements OnInit {
) {} ) {}
ngOnInit() { ngOnInit() {
if (this.toast.options && this.toast.options.sticky) return; if (snq(() => this.toast.options.sticky)) return;
const timeout = this.toast.options.life || 5000; const timeout = snq(() => this.toast.options.life) || 5000;
setTimeout(() => { setTimeout(() => {
this.close(); this.close();
}, timeout); }, timeout);

@ -60,6 +60,7 @@ export class ConfirmationService {
} }
clear(status?: Toaster.Status) { clear(status?: Toaster.Status) {
this.confirmation$.next();
this.status$.next(status || Toaster.Status.dismiss); this.status$.next(status || Toaster.Status.dismiss);
} }

@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
import { Toaster } from '../models'; import { Toaster } from '../models';
import { ReplaySubject } from 'rxjs'; import { ReplaySubject } from 'rxjs';
import { Config } from '@abp/ng.core'; import { Config } from '@abp/ng.core';
import snq from 'snq';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
@ -81,7 +82,7 @@ export class ToasterService {
message: Config.LocalizationParam, message: Config.LocalizationParam,
title: Config.LocalizationParam = null, title: Config.LocalizationParam = null,
severity: Toaster.Severity = 'neutral', severity: Toaster.Severity = 'neutral',
options: Partial<Toaster.ToastOptions> = null, options = {} as Partial<Toaster.ToastOptions>,
) { ) {
const id = ++this.lastId; const id = ++this.lastId;
this.toasts.push({ this.toasts.push({
@ -99,7 +100,7 @@ export class ToasterService {
* @param id ID of the toast to be removed. * @param id ID of the toast to be removed.
*/ */
remove(id: number) { remove(id: number) {
this.toasts = this.toasts.filter(toast => toast.options.id !== id); this.toasts = this.toasts.filter(toast => snq(() => toast.options.id) !== id);
this.toasts$.next(this.toasts); this.toasts$.next(this.toasts);
} }
@ -107,7 +108,9 @@ export class ToasterService {
* Removes all open toasts at once. * Removes all open toasts at once.
*/ */
clear(key?: string) { clear(key?: string) {
this.toasts = !key ? [] : this.toasts.filter(toast => toast.options.containerKey !== key); this.toasts = !key
? []
: this.toasts.filter(toast => snq(() => toast.options.containerKey) !== key);
this.toasts$.next(this.toasts); this.toasts$.next(this.toasts);
} }
} }

Loading…
Cancel
Save