-import { Injectable } from '@angular/core'
import { MessageService } from 'primeng/api'
-import { I18n } from '@ngx-translate/i18n-polyfill'
+import { Injectable } from '@angular/core'
+import { logger } from '@root-helpers/logger'
@Injectable()
export class Notifier {
readonly TIMEOUT = 5000
- constructor (
- private i18n: I18n,
- private messageService: MessageService) {
- }
+ constructor (private messageService: MessageService) { }
- info (text: string, title?: string, timeout?: number) {
- if (!title) title = this.i18n('Info')
+ info (text: string, title?: string, timeout?: number, sticky?: boolean) {
+ if (!title) title = $localize`Info`
- return this.notify('info', text, title, timeout)
+ logger.info(`${title}: ${text}`)
+ return this.notify('info', text, title, timeout, sticky)
}
- error (text: string, title?: string, timeout?: number) {
- if (!title) title = this.i18n('Error')
+ error (text: string, title?: string, timeout?: number, sticky?: boolean) {
+ if (!title) title = $localize`Error`
- return this.notify('error', text, title, timeout)
+ logger.error(`${title}: ${text}`)
+ return this.notify('error', text, title, timeout, sticky)
}
- success (text: string, title?: string, timeout?: number) {
- if (!title) title = this.i18n('Success')
+ success (text: string, title?: string, timeout?: number, sticky?: boolean) {
+ if (!title) title = $localize`Success`
- return this.notify('success', text, title, timeout)
+ logger.info(`${title}: ${text}`)
+ return this.notify('success', text, title, timeout, sticky)
}
- private notify (severity: 'success' | 'info' | 'warn' | 'error', text: string, title: string, timeout?: number) {
+ private notify (severity: 'success' | 'info' | 'warn' | 'error', text: string, title: string, timeout?: number, sticky?: boolean) {
this.messageService.add({
severity,
summary: title,
detail: text,
closable: true,
- life: timeout || this.TIMEOUT
+ life: timeout || this.TIMEOUT,
+ sticky
})
}
}