Squashed commit of the following:
commit ca11dd079dca884634ead2696899cfedbfc826f1
Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se>
Date: Wed Nov 10 14:45:48 2021 +0100
Made changes after PR
commit a8a51ecdabf0d32aa67b814eee530c9a01d405a9
Merge: b1677aff 3b6ce438
Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se>
Date: Wed Nov 10 12:47:54 2021 +0100
Merge branch 'develop' into feature/TV-535-idle-functionality
commit b1677aff5210288f4a86ba235dd1acb5d415f71f
Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se>
Date: Wed Nov 10 09:17:55 2021 +0100
Added better check to avoid blank screens
commit 0129f3f6a1d4884d3f669b109bc9b8667fc6281c
Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se>
Date: Wed Nov 10 09:12:55 2021 +0100
Added idle functionality
58 lines
1.9 KiB
TypeScript
58 lines
1.9 KiB
TypeScript
import { DOCUMENT } from '@angular/common';
|
|
import { ChangeDetectionStrategy, Component, Inject } from '@angular/core';
|
|
import { Title } from '@angular/platform-browser';
|
|
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
|
|
import { environment } from '@msfa-environment';
|
|
import { AuthenticationService } from '@msfa-services/api/authentication.service';
|
|
import { IdleService } from '@msfa-services/api/idle.service';
|
|
import { Observable } from 'rxjs';
|
|
import { filter, map, switchMap } from 'rxjs/operators';
|
|
|
|
@Component({
|
|
selector: 'msfa-root',
|
|
templateUrl: './app.component.html',
|
|
styleUrls: ['./app.component.scss'],
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
})
|
|
export class AppComponent {
|
|
userIsIdle$: Observable<boolean> = this.idleService.isIdle$;
|
|
timeLeftBeforeLogout$: Observable<string> = this.idleService.timeLeftBeforeLogout$;
|
|
|
|
constructor(
|
|
@Inject(DOCUMENT) private document: Document,
|
|
private router: Router,
|
|
private activatedRoute: ActivatedRoute,
|
|
private titleService: Title,
|
|
private idleService: IdleService,
|
|
private authenticationService: AuthenticationService
|
|
) {
|
|
this.document.body.dataset.version = environment.version;
|
|
|
|
this.router.events
|
|
.pipe(
|
|
filter(event => event instanceof NavigationEnd),
|
|
map(() => traverseUntilNoChildRoute(this.activatedRoute)),
|
|
switchMap((route: ActivatedRoute) => route.data)
|
|
)
|
|
.subscribe((routeData: { [title: string]: string }) => {
|
|
const pageTitle = routeData.title;
|
|
this.titleService.setTitle(`${pageTitle ? `${pageTitle} - ` : ''}Mina sidor för fristående aktörer`);
|
|
});
|
|
}
|
|
|
|
logout(): void {
|
|
this.authenticationService.logout();
|
|
}
|
|
|
|
setUserAsActive(): void {
|
|
this.idleService.setActive();
|
|
}
|
|
}
|
|
|
|
function traverseUntilNoChildRoute(route: ActivatedRoute): ActivatedRoute {
|
|
while (route.firstChild) {
|
|
route = route.firstChild;
|
|
}
|
|
return route;
|
|
}
|