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