|
|
@@ -1,19 +1,12 @@
|
|
|
-import { Component, OnInit } from '@angular/core';
|
|
|
+import { Component, HostListener, OnInit } from '@angular/core';
|
|
|
import { Router, RouterModule, RouterOutlet, RoutesRecognized } from '@angular/router';
|
|
|
import { MatModule } from '../dependencies/angularlib/mat.module';
|
|
|
-import { DialogModule } from 'angularlib/dialog/dialog.module';
|
|
|
-import { DialogUtil } from 'angularlib/dialog/dialog.util';
|
|
|
-import { NgxsModule, Store } from '@ngxs/store'
|
|
|
-import { LabelState } from 'angularlib/labels/label.state';
|
|
|
-import { HttpClientModule } from '@angular/common/http';
|
|
|
+import { Store } from '@ngxs/store'
|
|
|
import { Angularlib } from 'angularlib/angularlib.module';
|
|
|
-import { CommonModule } from '@angular/common';
|
|
|
-import { LabelModule } from 'angularlib/labels/label.module';
|
|
|
import { BaseComponent, untilDestroy } from 'angularlib/base.component';
|
|
|
-import { filter, map } from 'rxjs';
|
|
|
+import { Subject, filter, map, repeat, takeUntil, timer } from 'rxjs';
|
|
|
import { Title } from '@angular/platform-browser';
|
|
|
-import { TableModule } from 'angularlib/table/table.module';
|
|
|
-import { ChartModule } from 'angularlib/chart/chart.module';
|
|
|
+import { LoginService } from 'angularlib/login/login.service';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-root',
|
|
|
@@ -22,8 +15,7 @@ import { ChartModule } from 'angularlib/chart/chart.module';
|
|
|
RouterOutlet,
|
|
|
MatModule,
|
|
|
RouterModule,
|
|
|
- Angularlib,
|
|
|
- TableModule
|
|
|
+ Angularlib
|
|
|
],
|
|
|
templateUrl: './app.component.html',
|
|
|
styleUrls: [
|
|
|
@@ -33,15 +25,34 @@ import { ChartModule } from 'angularlib/chart/chart.module';
|
|
|
export class AppComponent extends BaseComponent implements OnInit {
|
|
|
title = 'SwOPT Angular';
|
|
|
|
|
|
+ /**login timeout duration in milliseconds
|
|
|
+ * @default 5 minutes
|
|
|
+ */
|
|
|
+ private duration: number = 300000;
|
|
|
+ private startTimeout$ = new Subject();
|
|
|
+ private stopTimeout$ = new Subject();
|
|
|
+ private timeout = timer(this.duration).pipe(
|
|
|
+ map(() => {if(this.loginService.user)this.loginService.logout();console.warn('session inactive timeout, logging out...');}),
|
|
|
+ takeUntil(this.stopTimeout$),
|
|
|
+ repeat({delay:() => this.startTimeout$})
|
|
|
+ );
|
|
|
+
|
|
|
constructor(
|
|
|
private router: Router,
|
|
|
private store: Store,
|
|
|
+ protected loginService: LoginService,
|
|
|
/**Platform Browser title */
|
|
|
protected pbTitle: Title,
|
|
|
) {
|
|
|
super(store);
|
|
|
}
|
|
|
|
|
|
+ @HostListener('window:mousedown')
|
|
|
+ private refreshTimeout() {
|
|
|
+ this.stopTimeout$.next(null);
|
|
|
+ this.startTimeout$.next(null);
|
|
|
+ }
|
|
|
+
|
|
|
ngOnInit(): void {
|
|
|
this.router.events.pipe(untilDestroy(this),
|
|
|
filter((event) => event instanceof RoutesRecognized),
|
|
|
@@ -53,5 +64,12 @@ export class AppComponent extends BaseComponent implements OnInit {
|
|
|
this.title = title;
|
|
|
this.pbTitle.setTitle(this.title);
|
|
|
});
|
|
|
+
|
|
|
+ /**subsribe user changes and initiate timeout timer */
|
|
|
+ this.loginService.user$.pipe(untilDestroy(this)).subscribe(user => {
|
|
|
+ if (user) {
|
|
|
+ this.timeout.pipe(untilDestroy(this),takeUntil(this.loginService.loggedOut)).subscribe();
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
}
|