mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
61 lines
1.1 KiB
TypeScript
61 lines
1.1 KiB
TypeScript
import { Injectable } from '@angular/core'
|
|
import { Subject } from 'rxjs'
|
|
|
|
export interface Toast {
|
|
title: string
|
|
|
|
content: string
|
|
|
|
delay: number
|
|
|
|
action?: any
|
|
|
|
actionName?: string
|
|
|
|
classname?: string
|
|
|
|
error?: any
|
|
}
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class ToastService {
|
|
constructor() {}
|
|
|
|
private toasts: Toast[] = []
|
|
|
|
private toastsSubject: Subject<Toast[]> = new Subject()
|
|
|
|
show(toast: Toast) {
|
|
this.toasts.push(toast)
|
|
this.toastsSubject.next(this.toasts)
|
|
}
|
|
|
|
showError(content: string, error: any = null, delay: number = 10000) {
|
|
this.show({
|
|
title: $localize`Error`,
|
|
content: content,
|
|
delay: delay,
|
|
classname: 'error',
|
|
error,
|
|
})
|
|
}
|
|
|
|
showInfo(content: string, delay: number = 5000) {
|
|
this.show({ title: $localize`Information`, content: content, delay: delay })
|
|
}
|
|
|
|
closeToast(toast: Toast) {
|
|
let index = this.toasts.findIndex((t) => t == toast)
|
|
if (index > -1) {
|
|
this.toasts.splice(index, 1)
|
|
this.toastsSubject.next(this.toasts)
|
|
}
|
|
}
|
|
|
|
getToasts() {
|
|
return this.toastsSubject
|
|
}
|
|
}
|