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