истечение времени простоя сеанса не закрывает всплывающее окно MatDialog.Использование @ ng-idle / core - PullRequest
0 голосов
/ 14 мая 2019

Я использую @ng-idle/core для определения времени простоя в моем угловом приложении.После того, как обратный отсчет достигнет 1, я должен перейти на страницу истечения сеанса.Проблема в том, что хотя в фоновом режиме он переходит на страницу с истекшим сроком действия сессии, всплывающее окно обратного отсчета не закрывается.

, как показано в приведенном ниже URL-адресе, который я пробовал this.appRef.tick();

Возникли проблемы с ng-idle / core onIdleEnd и Mat-Dialog

import { Component, OnInit, OnDestroy, ApplicationRef } from '@angular/core';
import { Router } from '@angular/router';
import { Idle, DEFAULT_INTERRUPTSOURCES } from '@ng-idle/core';
import { MatDialog, MatDialogConfig, MatDialogRef } from '@angular/material';
import { IdleTimeOutComponent } from './components/idle-timeout-warning/idle-timeout.component';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit, OnDestroy {
  idleState = 'Not started.';
  timedOut = false;
  lastPing?: Date = null;
  private idleTimeOutdialogRef: MatDialogRef<IdleTimeOutComponent>


  constructor(
    private router: Router,
    private idle: Idle,
    public idleTimeWarnDialog: MatDialog,
    public sessionExpiredInfoDialog: MatDialog,
    private appRef: ApplicationRef) {


    // sets an idle timeout of 5 seconds, for testing purposes.
    idle.setIdle(5);
    // sets a timeout period of 5 seconds. after 10 seconds of inactivity, the user will be considered timed out.
    idle.setTimeout(5);
    // sets the default interrupts, in this case, things like clicks, scrolls, touches to the document
    idle.setInterrupts(DEFAULT_INTERRUPTSOURCES);

    idle.onIdleEnd.subscribe(() => {
    this.idleState = 'No longer idle.';
      if (idleTimeWarnDialog.openDialogs.length > 0) {
        console.log('dialogs are open');
        //this.idleTimeWarnDialog.closeAll;
        this.idleTimeOutdialogRef.close;
        this.appRef.tick();
      }
    })
    idle.onTimeout.subscribe(() => {
      this.idleState = 'Timed out!';
      this.timedOut = true;
      console.log('timed out before routing');
      this.resetTimeOut;
      this.router.navigate(['/session-expired']);
    });
    idle.onIdleStart.subscribe(() => {
      this.idleState = 'You\'ve gone idle!',
        this.openSessionTimeOutDialog(1);
    });
    //idle.onTimeoutWarning.subscribe((countdown) => this.idleState = 'You will time out in ' + countdown + ' seconds!');

    idle.onTimeoutWarning.subscribe((countdown: any) => {
      this.idleState = 'IDLE_TIME_IN_PROGRESS';

      //this.dialogRef.componentInstance.count = (Math.floor((countdown - 1) / 60) + 1);
      this.idleTimeOutdialogRef.componentInstance.progressCount = this.reverseNumber(countdown);
      this.idleTimeOutdialogRef.componentInstance.countMinutes = (Math.floor(countdown / 60));
      this.idleTimeOutdialogRef.componentInstance.countSeconds = countdown % 60;
    });
    this.reset();
  }

  ngOnInit() { }

  logout() {
    this.authService.logout();
    this.loggedIn = false;
  }

  openSessionTimeOutDialog(count: number) {
    console.log('opening popup');
    const timeOutWarndialogConfig = new MatDialogConfig();
    timeOutWarndialogConfig.disableClose = true;
    timeOutWarndialogConfig.autoFocus = true;
    timeOutWarndialogConfig.panelClass = 'custom-modalbox';
    timeOutWarndialogConfig.data = {
      sessionExpiry: false
    };

    this.idleTimeWarnDialog.closeAll;
    this.idleTimeOutdialogRef = this.idleTimeWarnDialog.open(
      IdleTimeOutComponent,
      timeOutWarndialogConfig
    );

    // this.dialogRef.componentInstance.count = count;
    this.idleTimeOutdialogRef.afterClosed().subscribe((result: any) => {
      if (result !== '' && 'logout' === result) {
        console.log('Logout is initiate');

        const sessionExpdialogConfig = new MatDialogConfig();

        sessionExpdialogConfig.disableClose = true;
        sessionExpdialogConfig.autoFocus = true;
        sessionExpdialogConfig.panelClass = 'custom-modalbox';

        sessionExpdialogConfig.data = {
          sessionExpiry: true
        };
        this.sessionExpiredInfoDialog.closeAll;
        this.sessionExpiredInfoDialog.open(IdleTimeOutComponent, sessionExpdialogConfig);
        //this.logout();
      } else {
        console.log('request to close popup got initiate');
        this.reset();
      }
    });
  }

  reset() {
    this.idle.watch();
    this.idleState = 'Started.';
    this.timedOut = false;
  }

  resetTimeOut() {
    this.idle.stop();
    this.idle.onIdleStart.unsubscribe();
    this.idle.onTimeoutWarning.unsubscribe();
    this.idle.onIdleEnd.unsubscribe();
    this.idle.onIdleEnd.unsubscribe();
  }
}

Я хочу, чтобы idleTimeOutdialogRef был закрыт в четном из onIdleEnd.Кто-нибудь может подсказать, что мне здесь не хватает? /

...