settings and localization

This commit is contained in:
jonaswinkler
2021-01-27 17:28:11 +01:00
parent 5a4cb5fe4a
commit 91f7c4e685
7 changed files with 214 additions and 49 deletions

View File

@@ -1,9 +1,9 @@
import { SettingsService } from './services/settings.service';
import { SettingsService, SETTINGS_KEYS } from './services/settings.service';
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { Subscription } from 'rxjs';
import { ConsumerStatusService } from './services/consumer-status.service';
import { Toast, ToastService } from './services/toast.service';
import { ToastService } from './services/toast.service';
@Component({
selector: 'app-root',
@@ -12,6 +12,7 @@ import { Toast, ToastService } from './services/toast.service';
})
export class AppComponent implements OnInit, OnDestroy {
newDocumentSubscription: Subscription;
successSubscription: Subscription;
failedSubscription: Subscription;
@@ -23,23 +24,47 @@ export class AppComponent implements OnInit, OnDestroy {
ngOnDestroy(): void {
this.consumerStatusService.disconnect()
this.successSubscription.unsubscribe()
this.failedSubscription.unsubscribe()
if (this.successSubscription) {
this.successSubscription.unsubscribe()
}
if (this.failedSubscription) {
this.failedSubscription.unsubscribe()
}
if (this.newDocumentSubscription) {
this.newDocumentSubscription.unsubscribe()
}
}
private showNotification(key) {
if (this.router.url == '/dashboard' && this.settings.get(SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_SUPPRESS_ON_DASHBOARD)) {
return false
}
return this.settings.get(key)
}
ngOnInit(): void {
this.consumerStatusService.connect()
this.successSubscription = this.consumerStatusService.onDocumentConsumptionFinished().subscribe(status => {
this.toastService.show({title: "Document added", delay: 10000, content: `Document ${status.filename} was added to paperless.`, actionName: "Open document", action: () => {
this.router.navigate(['documents', status.documentId])
}})
if (this.showNotification(SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_SUCCESS)) {
this.toastService.show({title: $localize`Document added`, delay: 10000, content: $localize`Document ${status.filename} was added to paperless.`, actionName: $localize`Open document`, action: () => {
this.router.navigate(['documents', status.documentId])
}})
}
})
this.failedSubscription = this.consumerStatusService.onDocumentConsumptionFailed().subscribe(status => {
this.toastService.showError(`Could not consume ${status.filename}: ${status.message}`)
if (this.showNotification(SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_FAILED)) {
this.toastService.showError($localize`Could not add ${status.filename}\: ${status.message}`)
}
})
this.newDocumentSubscription = this.consumerStatusService.onDocumentDetected().subscribe(status => {
if (this.showNotification(SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_NEW_DOCUMENT)) {
this.toastService.show({title: $localize`New document detected`, delay: 5000, content: $localize`Document ${status.filename} is being processed by paperless.`})
}
})
}
}