mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
better toasts
This commit is contained in:
parent
27666da4e9
commit
bd3a2306d6
@ -5,7 +5,7 @@ import { Observable } from 'rxjs';
|
|||||||
import { MATCHING_ALGORITHMS } from 'src/app/data/matching-model';
|
import { MATCHING_ALGORITHMS } from 'src/app/data/matching-model';
|
||||||
import { ObjectWithId } from 'src/app/data/object-with-id';
|
import { ObjectWithId } from 'src/app/data/object-with-id';
|
||||||
import { AbstractPaperlessService } from 'src/app/services/rest/abstract-paperless-service';
|
import { AbstractPaperlessService } from 'src/app/services/rest/abstract-paperless-service';
|
||||||
import { Toast, ToastService } from 'src/app/services/toast.service';
|
import { ToastService } from 'src/app/services/toast.service';
|
||||||
|
|
||||||
@Directive()
|
@Directive()
|
||||||
export abstract class EditDialogComponent<T extends ObjectWithId> implements OnInit {
|
export abstract class EditDialogComponent<T extends ObjectWithId> implements OnInit {
|
||||||
@ -66,7 +66,7 @@ export abstract class EditDialogComponent<T extends ObjectWithId> implements OnI
|
|||||||
this.activeModal.close()
|
this.activeModal.close()
|
||||||
this.success.emit(result)
|
this.success.emit(result)
|
||||||
}, error => {
|
}, error => {
|
||||||
this.toastService.showToast(Toast.makeError(`Could not save ${this.entityName}: ${error.error.name}`))
|
this.toastService.showError($localize`Could not save ${this.entityName}: ${error.error.name}`)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ import { HttpEventType } from '@angular/common/http';
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { FileSystemFileEntry, NgxFileDropEntry } from 'ngx-file-drop';
|
import { FileSystemFileEntry, NgxFileDropEntry } from 'ngx-file-drop';
|
||||||
import { DocumentService } from 'src/app/services/rest/document.service';
|
import { DocumentService } from 'src/app/services/rest/document.service';
|
||||||
import { Toast, ToastService } from 'src/app/services/toast.service';
|
import { ToastService } from 'src/app/services/toast.service';
|
||||||
|
|
||||||
|
|
||||||
interface UploadStatus {
|
interface UploadStatus {
|
||||||
@ -60,7 +60,7 @@ export class UploadFileWidgetComponent implements OnInit {
|
|||||||
} else if (event.type == HttpEventType.Response) {
|
} else if (event.type == HttpEventType.Response) {
|
||||||
this.uploadStatus.splice(this.uploadStatus.indexOf(uploadStatusObject), 1)
|
this.uploadStatus.splice(this.uploadStatus.indexOf(uploadStatusObject), 1)
|
||||||
this.completedFiles += 1
|
this.completedFiles += 1
|
||||||
this.toastService.showToast(Toast.make("Information", $localize`The document has been uploaded and will be processed by the consumer shortly.`))
|
this.toastService.showInfo($localize`The document has been uploaded and will be processed by the consumer shortly.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
}, error => {
|
}, error => {
|
||||||
@ -68,11 +68,11 @@ export class UploadFileWidgetComponent implements OnInit {
|
|||||||
this.completedFiles += 1
|
this.completedFiles += 1
|
||||||
switch (error.status) {
|
switch (error.status) {
|
||||||
case 400: {
|
case 400: {
|
||||||
this.toastService.showToast(Toast.makeError($localize`There was an error while uploading the document: ${error.error.document}`))
|
this.toastService.showInfo($localize`There was an error while uploading the document: ${error.error.document}`)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
this.toastService.showToast(Toast.makeError($localize`An error has occurred while uploading the document. Sorry!`))
|
this.toastService.showInfo($localize`An error has occurred while uploading the document. Sorry!`)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ export class DocumentListComponent implements OnInit {
|
|||||||
|
|
||||||
saveViewConfig() {
|
saveViewConfig() {
|
||||||
this.savedViewService.update(this.list.savedView).subscribe(result => {
|
this.savedViewService.update(this.list.savedView).subscribe(result => {
|
||||||
this.toastService.showToast(Toast.make("Information", $localize`View "${this.list.savedView.name}" saved successfully.`))
|
this.toastService.showInfo($localize`View "${this.list.savedView.name}" saved successfully.`)
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ export class DocumentListComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
this.savedViewService.create(savedView).subscribe(() => {
|
this.savedViewService.create(savedView).subscribe(() => {
|
||||||
modal.close()
|
modal.close()
|
||||||
this.toastService.showToast(Toast.make("Information", $localize`View "${savedView.name}" created successfully.`))
|
this.toastService.showInfo($localize`View "${savedView.name}" created successfully.`)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import { PaperlessSavedView } from 'src/app/data/paperless-saved-view';
|
|||||||
import { GENERAL_SETTINGS } from 'src/app/data/storage-keys';
|
import { GENERAL_SETTINGS } from 'src/app/data/storage-keys';
|
||||||
import { DocumentListViewService } from 'src/app/services/document-list-view.service';
|
import { DocumentListViewService } from 'src/app/services/document-list-view.service';
|
||||||
import { SavedViewService } from 'src/app/services/rest/saved-view.service';
|
import { SavedViewService } from 'src/app/services/rest/saved-view.service';
|
||||||
import { Toast, ToastService } from 'src/app/services/toast.service';
|
import { ToastService } from 'src/app/services/toast.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-settings',
|
selector: 'app-settings',
|
||||||
@ -46,14 +46,14 @@ export class SettingsComponent implements OnInit {
|
|||||||
this.savedViewService.delete(savedView).subscribe(() => {
|
this.savedViewService.delete(savedView).subscribe(() => {
|
||||||
this.savedViewGroup.removeControl(savedView.id.toString())
|
this.savedViewGroup.removeControl(savedView.id.toString())
|
||||||
this.savedViews.splice(this.savedViews.indexOf(savedView), 1)
|
this.savedViews.splice(this.savedViews.indexOf(savedView), 1)
|
||||||
this.toastService.showToast(Toast.make("Information", $localize`Saved view "${savedView.name} deleted.`))
|
this.toastService.showInfo($localize`Saved view "${savedView.name} deleted.`)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private saveLocalSettings() {
|
private saveLocalSettings() {
|
||||||
localStorage.setItem(GENERAL_SETTINGS.DOCUMENT_LIST_SIZE, this.settingsForm.value.documentListItemPerPage)
|
localStorage.setItem(GENERAL_SETTINGS.DOCUMENT_LIST_SIZE, this.settingsForm.value.documentListItemPerPage)
|
||||||
this.documentListViewService.updatePageSize()
|
this.documentListViewService.updatePageSize()
|
||||||
this.toastService.showToast(Toast.make("Information", $localize`Settings saved successfully.`))
|
this.toastService.showInfo($localize`Settings saved successfully.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
saveSettings() {
|
saveSettings() {
|
||||||
@ -65,7 +65,7 @@ export class SettingsComponent implements OnInit {
|
|||||||
this.savedViewService.patchMany(x).subscribe(s => {
|
this.savedViewService.patchMany(x).subscribe(s => {
|
||||||
this.saveLocalSettings()
|
this.saveLocalSettings()
|
||||||
}, error => {
|
}, error => {
|
||||||
this.toastService.showToast(Toast.makeError($localize`Error while storing settings on server: ${JSON.stringify(error.error)}`))
|
this.toastService.showError($localize`Error while storing settings on server: ${JSON.stringify(error.error)}`)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
this.saveLocalSettings()
|
this.saveLocalSettings()
|
||||||
|
@ -1,30 +1,13 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Subject, zip } from 'rxjs';
|
import { Subject, zip } from 'rxjs';
|
||||||
|
|
||||||
export class Toast {
|
export interface Toast {
|
||||||
|
|
||||||
static make(title: string, content: string, classname?: string, delay?: number): Toast {
|
|
||||||
let t = new Toast()
|
|
||||||
t.title = title
|
|
||||||
t.content = content
|
|
||||||
t.classname = classname
|
|
||||||
if (delay) {
|
|
||||||
t.delay = delay
|
|
||||||
}
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
|
|
||||||
static makeError(content: string) {
|
|
||||||
return Toast.make("Error", content, null, 10000)
|
|
||||||
}
|
|
||||||
|
|
||||||
title: string
|
title: string
|
||||||
|
|
||||||
classname: string
|
|
||||||
|
|
||||||
content: string
|
content: string
|
||||||
|
|
||||||
delay: number = 5000
|
delay: number
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,11 +22,19 @@ export class ToastService {
|
|||||||
|
|
||||||
private toastsSubject: Subject<Toast[]> = new Subject()
|
private toastsSubject: Subject<Toast[]> = new Subject()
|
||||||
|
|
||||||
showToast(toast: Toast) {
|
show(toast: Toast) {
|
||||||
this.toasts.push(toast)
|
this.toasts.push(toast)
|
||||||
this.toastsSubject.next(this.toasts)
|
this.toastsSubject.next(this.toasts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
showError(content: string, delay: number = 10000) {
|
||||||
|
this.show({title: $localize`Error`, content: content, delay: delay})
|
||||||
|
}
|
||||||
|
|
||||||
|
showInfo(content: string, delay: number = 5000) {
|
||||||
|
this.show({title: $localize`Information`, content: content, delay: delay})
|
||||||
|
}
|
||||||
|
|
||||||
closeToast(toast: Toast) {
|
closeToast(toast: Toast) {
|
||||||
let index = this.toasts.findIndex(t => t == toast)
|
let index = this.toasts.findIndex(t => t == toast)
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user