2021-01-01 22:38:26 +01:00
import { SettingsService } from './services/settings.service' ;
2020-11-07 12:05:15 +01:00
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' ;
2020-10-27 01:10:18 +01:00
@Component ( {
selector : 'app-root' ,
templateUrl : './app.component.html' ,
2020-11-22 14:43:59 +01:00
styleUrls : [ './app.component.scss' ]
2020-10-27 01:10:18 +01:00
} )
2020-11-07 12:05:15 +01:00
export class AppComponent implements OnInit , OnDestroy {
successSubscription : Subscription ;
failedSubscription : Subscription ;
2021-01-04 22:45:56 +01:00
constructor ( private settings : SettingsService , private consumerStatusService : ConsumerStatusService , private toastService : ToastService , private router : Router ) {
2021-01-01 22:38:26 +01:00
let anyWindow = ( window as any )
anyWindow . pdfWorkerSrc = '/assets/js/pdf.worker.min.js' ;
this . settings . updateDarkModeSettings ( )
2020-11-07 12:05:15 +01:00
}
ngOnDestroy ( ) : void {
this . consumerStatusService . disconnect ( )
this . successSubscription . unsubscribe ( )
this . failedSubscription . unsubscribe ( )
2020-10-27 01:10:18 +01:00
}
2020-11-07 12:05:15 +01:00
ngOnInit ( ) : void {
this . consumerStatusService . connect ( )
this . successSubscription = this . consumerStatusService . onDocumentConsumptionFinished ( ) . subscribe ( status = > {
2021-01-04 23:05:16 +01:00
this . toastService . show ( { title : "Document added" , delay : 10000 , content : ` Document ${ status . filename } was added to paperless. ` , actionName : "Open document" , action : ( ) = > {
2021-01-26 00:51:45 +01:00
this . router . navigate ( [ 'documents' , status . documentId ] )
2020-11-07 12:05:15 +01:00
} } )
} )
this . failedSubscription = this . consumerStatusService . onDocumentConsumptionFailed ( ) . subscribe ( status = > {
this . toastService . showError ( ` Could not consume ${ status . filename } : ${ status . message } ` )
} )
}
2020-10-27 01:10:18 +01:00
}