mirror of https://github.com/abpframework/abp.git
3 changed files with 62 additions and 13 deletions
@ -1,10 +1,49 @@ |
|||||
import { Injectable } from '@angular/core'; |
import { Injectable } from '@angular/core'; |
||||
import { AbstractToaster } from '../abstracts/toaster'; |
import { AbstractToaster } from '../abstracts/toaster'; |
||||
import { Confirmation } from '../models/confirmation'; |
import { Confirmation } from '../models/confirmation'; |
||||
|
import { MessageService } from 'primeng/components/common/messageservice'; |
||||
|
import { fromEvent, Observable, Subject } from 'rxjs'; |
||||
|
import { takeUntil, debounceTime, filter } from 'rxjs/operators'; |
||||
|
import { Toaster } from '../models/toaster'; |
||||
|
|
||||
@Injectable({ providedIn: 'root' }) |
@Injectable({ providedIn: 'root' }) |
||||
export class ConfirmationService extends AbstractToaster<Confirmation.Options> { |
export class ConfirmationService extends AbstractToaster<Confirmation.Options> { |
||||
key: string = 'abpConfirmation'; |
key: string = 'abpConfirmation'; |
||||
|
|
||||
sticky: boolean = true; |
sticky: boolean = true; |
||||
|
|
||||
|
destroy$ = new Subject(); |
||||
|
|
||||
|
constructor(protected messageService: MessageService) { |
||||
|
super(messageService); |
||||
|
} |
||||
|
|
||||
|
show( |
||||
|
message: string, |
||||
|
title: string, |
||||
|
severity: Toaster.Severity, |
||||
|
options?: Confirmation.Options, |
||||
|
): Observable<Toaster.Status> { |
||||
|
this.listenToEscape(); |
||||
|
|
||||
|
return super.show(message, title, severity, options); |
||||
|
} |
||||
|
|
||||
|
clear(status?: Toaster.Status) { |
||||
|
super.clear(status); |
||||
|
|
||||
|
this.destroy$.next(); |
||||
|
} |
||||
|
|
||||
|
listenToEscape() { |
||||
|
fromEvent(document, 'keyup') |
||||
|
.pipe( |
||||
|
takeUntil(this.destroy$), |
||||
|
debounceTime(150), |
||||
|
filter((key: KeyboardEvent) => key && key.code === 'Escape'), |
||||
|
) |
||||
|
.subscribe(_ => { |
||||
|
this.clear(); |
||||
|
}); |
||||
|
} |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue