mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-12 12:33:07 +00:00
79700: Feedback 2021-06-15 applied
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { delay, distinctUntilChanged, filter, take } from 'rxjs/operators';
|
||||
import { delay, distinctUntilChanged, filter, take, withLatestFrom } from 'rxjs/operators';
|
||||
import {
|
||||
AfterViewInit,
|
||||
ChangeDetectionStrategy,
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
} from '@angular/core';
|
||||
import { NavigationCancel, NavigationEnd, NavigationStart, Router } from '@angular/router';
|
||||
|
||||
import { BehaviorSubject, Observable, of } from 'rxjs';
|
||||
import { BehaviorSubject, combineLatest as observableCombineLatest, Observable, of } from 'rxjs';
|
||||
import { select, Store } from '@ngrx/store';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { Angulartics2GoogleAnalytics } from 'angulartics2/ga';
|
||||
@@ -38,6 +38,8 @@ import { ThemeService } from './shared/theme-support/theme.service';
|
||||
import { BASE_THEME_NAME } from './shared/theme-support/theme.constants';
|
||||
import { DEFAULT_THEME_CONFIG } from './shared/theme-support/theme.effects';
|
||||
import { BreadcrumbsService } from './breadcrumbs/breadcrumbs.service';
|
||||
import { IdleModalComponent } from './shared/idle-modal/idle-modal.component';
|
||||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-app',
|
||||
@@ -70,6 +72,11 @@ export class AppComponent implements OnInit, AfterViewInit {
|
||||
isThemeLoading$: BehaviorSubject<boolean> = new BehaviorSubject(false);
|
||||
|
||||
|
||||
/**
|
||||
* Whether or not the idle modal is is currently open
|
||||
*/
|
||||
idleModalOpen: boolean;
|
||||
|
||||
constructor(
|
||||
@Inject(NativeWindowService) private _window: NativeWindowRef,
|
||||
@Inject(DOCUMENT) private document: any,
|
||||
@@ -87,6 +94,7 @@ export class AppComponent implements OnInit, AfterViewInit {
|
||||
private windowService: HostWindowService,
|
||||
private localeService: LocaleService,
|
||||
private breadcrumbsService: BreadcrumbsService,
|
||||
private modalService: NgbModal,
|
||||
@Optional() private cookiesService: KlaroService,
|
||||
@Optional() private googleAnalyticsService: GoogleAnalyticsService,
|
||||
) {
|
||||
@@ -108,6 +116,11 @@ export class AppComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
});
|
||||
|
||||
if (isPlatformBrowser(this.platformId)) {
|
||||
this.authService.trackTokenExpiration();
|
||||
this.trackIdleModal();
|
||||
}
|
||||
|
||||
// Load all the languages that are defined as active from the config file
|
||||
translate.addLangs(environment.languages.filter((LangConfig) => LangConfig.active === true).map((a) => a.code));
|
||||
|
||||
@@ -130,7 +143,6 @@ export class AppComponent implements OnInit, AfterViewInit {
|
||||
console.info(environment);
|
||||
}
|
||||
this.storeCSSVariables();
|
||||
this.authService.trackTokenExpiration();
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
@@ -229,4 +241,23 @@ export class AppComponent implements OnInit, AfterViewInit {
|
||||
};
|
||||
head.appendChild(link);
|
||||
}
|
||||
|
||||
private trackIdleModal() {
|
||||
const isIdle$ = this.authService.isUserIdle();
|
||||
const isAuthenticated$ = this.authService.isAuthenticated();
|
||||
isIdle$.pipe(withLatestFrom(isAuthenticated$))
|
||||
.subscribe(([userIdle, authenticated]) => {
|
||||
if (userIdle && authenticated) {
|
||||
if (!this.idleModalOpen) {
|
||||
const modalRef = this.modalService.open(IdleModalComponent);
|
||||
this.idleModalOpen = true;
|
||||
modalRef.componentInstance.response.pipe(take(1)).subscribe((closed: boolean) => {
|
||||
if (closed) {
|
||||
this.idleModalOpen = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user