]>
Commit | Line | Data |
---|---|---|
f8b2c1b4 | 1 | import { MessageService } from 'primeng/api' |
66357162 | 2 | import { Injectable } from '@angular/core' |
f8b2c1b4 C |
3 | |
4 | @Injectable() | |
5 | export class Notifier { | |
6 | readonly TIMEOUT = 5000 | |
7 | ||
66357162 | 8 | constructor (private messageService: MessageService) { } |
f8b2c1b4 C |
9 | |
10 | info (text: string, title?: string, timeout?: number) { | |
66357162 | 11 | if (!title) title = $localize`Info` |
f8b2c1b4 C |
12 | |
13 | return this.notify('info', text, title, timeout) | |
14 | } | |
15 | ||
16 | error (text: string, title?: string, timeout?: number) { | |
66357162 | 17 | if (!title) title = $localize`Error` |
f8b2c1b4 C |
18 | |
19 | return this.notify('error', text, title, timeout) | |
20 | } | |
21 | ||
22 | success (text: string, title?: string, timeout?: number) { | |
66357162 | 23 | if (!title) title = $localize`Success` |
f8b2c1b4 C |
24 | |
25 | return this.notify('success', text, title, timeout) | |
26 | } | |
27 | ||
28 | private notify (severity: 'success' | 'info' | 'warn' | 'error', text: string, title: string, timeout?: number) { | |
29 | this.messageService.add({ | |
30 | severity, | |
31 | summary: title, | |
32 | detail: text, | |
33 | closable: true, | |
34 | life: timeout || this.TIMEOUT | |
35 | }) | |
36 | } | |
37 | } |