]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/core/notification/notifier.service.ts
Fix confirm modal containing 2 inputs
[github/Chocobozzz/PeerTube.git] / client / src / app / core / notification / notifier.service.ts
1 import { MessageService } from 'primeng/api'
2 import { Injectable } from '@angular/core'
3 import { logger } from '@root-helpers/logger'
4
5 @Injectable()
6 export class Notifier {
7 readonly TIMEOUT = 5000
8
9 constructor (private messageService: MessageService) { }
10
11 info (text: string, title?: string, timeout?: number, sticky?: boolean) {
12 if (!title) title = $localize`Info`
13
14 logger.info(`${title}: ${text}`)
15 return this.notify('info', text, title, timeout, sticky)
16 }
17
18 error (text: string, title?: string, timeout?: number, sticky?: boolean) {
19 if (!title) title = $localize`Error`
20
21 logger.error(`${title}: ${text}`)
22 return this.notify('error', text, title, timeout, sticky)
23 }
24
25 success (text: string, title?: string, timeout?: number, sticky?: boolean) {
26 if (!title) title = $localize`Success`
27
28 logger.info(`${title}: ${text}`)
29 return this.notify('success', text, title, timeout, sticky)
30 }
31
32 private notify (severity: 'success' | 'info' | 'warn' | 'error', text: string, title: string, timeout?: number, sticky?: boolean) {
33 this.messageService.add({
34 severity,
35 summary: title,
36 detail: text,
37 closable: true,
38 life: timeout || this.TIMEOUT,
39 sticky
40 })
41 }
42 }