]>
Commit | Line | Data |
---|---|---|
1 | import { first } from 'rxjs/operators' | |
2 | import { Injectable } from '@angular/core' | |
3 | import { Subject } from 'rxjs' | |
4 | ||
5 | type ConfirmOptions = { | |
6 | title: string | |
7 | message: string | |
8 | inputLabel?: string | |
9 | expectedInputValue?: string | |
10 | confirmButtonText?: string | |
11 | } | |
12 | ||
13 | @Injectable() | |
14 | export class ConfirmService { | |
15 | showConfirm = new Subject<ConfirmOptions>() | |
16 | confirmResponse = new Subject<boolean>() | |
17 | ||
18 | confirm (message: string, title = '', confirmButtonText?: string) { | |
19 | this.showConfirm.next({ title, message, confirmButtonText }) | |
20 | ||
21 | return this.confirmResponse.asObservable() | |
22 | .pipe(first()) | |
23 | .toPromise() | |
24 | } | |
25 | ||
26 | confirmWithInput (message: string, inputLabel: string, expectedInputValue: string, title = '', confirmButtonText?: string) { | |
27 | this.showConfirm.next({ title, message, inputLabel, expectedInputValue, confirmButtonText }) | |
28 | ||
29 | return this.confirmResponse.asObservable() | |
30 | .pipe(first()) | |
31 | .toPromise() | |
32 | } | |
33 | } |