import { Component , Input , OnDestroy , OnInit } from '@angular/core' ; import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap' ; import { Observable , ReplaySubject } from 'rxjs' ; import { takeUntil } from 'rxjs/operators' ; import { FormControl , FormGroup , Validators } from '@angular/forms' ; import { AuthService } from '../../services/auth.service' ; @ Component ( { selector : 'cmdb-session-timeout-notification-modal' , templateUrl : './session-timeout-notification-modal.component.html' , styleUrls : [ './session-timeout-notification-modal.component.scss' ] } ) export class SessionTimeoutNotificationModalComponent implements OnInit , OnDestroy { private private subscriber : ReplaySubject < void > = new ReplaySubject < void > ( ) ; /**
     * Timeout observer of the session timeout service.
     */ @ Input ( ) public remainingTime$ : Observable < string > ; /**
     * Dateformat of the remaining token lifetime.
     */ public remainingTime : string = '' ; /**
     * Renew session password form group.
     */ public form : FormGroup ; /**
     * Error
     */ public error : string ; constructor ( public activeModal , private authService ) { this . form = new FormGroup ( { password : new FormControl ( '' , Validators . required ) } ) ; } /**
     * Entered password from the form.
     */ public get password ( ) : string { return this . form . get ( 'password' ) . value ; } /**
     * On password pass.
     */ public onRenew ( ) { if ( this . form . valid ) { const username = this . authService . currentUserValue . user_name ; this . authService . login ( username , this . password ) . pipe ( takeUntil ( this . subscriber ) ) . subscribe ( ( ) => { this . activeModal . close ( { renewed : true } ) ; } , ( ) => { this . error = 'Could not authenticate, given password was wrong.' ; } ) ; } } public ngOnInit ( ) { this . remainingTime$ . pipe ( takeUntil ( this . subscriber ) ) . subscribe ( ( timeout ) => this . remainingTime = timeout ) ; } public ngOnDestroy ( ) { this . subscriber . next ( ) ; this . subscriber . complete ( ) ; } }