mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-19 07:53:02 +00:00
[DURACOM-234] Migrate to functional guards WIP
This commit is contained in:
@@ -10,6 +10,10 @@ import {
|
||||
Injectable,
|
||||
TransferState,
|
||||
} from '@angular/core';
|
||||
import {
|
||||
NavigationStart,
|
||||
Router,
|
||||
} from '@angular/router';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import {
|
||||
@@ -30,7 +34,6 @@ import { coreSelector } from '../../app/core/core.selectors';
|
||||
import { RootDataService } from '../../app/core/data/root-data.service';
|
||||
import { LocaleService } from '../../app/core/locale/locale.service';
|
||||
import { MetadataService } from '../../app/core/metadata/metadata.service';
|
||||
import { ServerCheckGuard } from '../../app/core/server-check/server-check.guard';
|
||||
import { CorrelationIdService } from '../../app/correlation-id/correlation-id.service';
|
||||
import { InitService } from '../../app/init.service';
|
||||
import { KlaroService } from '../../app/shared/cookies/klaro.service';
|
||||
@@ -76,7 +79,7 @@ export class BrowserInitService extends InitService {
|
||||
protected themeService: ThemeService,
|
||||
protected menuService: MenuService,
|
||||
private rootDataService: RootDataService,
|
||||
protected serverCheckGuard: ServerCheckGuard,
|
||||
protected router: Router,
|
||||
) {
|
||||
super(
|
||||
store,
|
||||
@@ -198,7 +201,25 @@ export class BrowserInitService extends InitService {
|
||||
*/
|
||||
protected initRouteListeners(): void {
|
||||
super.initRouteListeners();
|
||||
this.serverCheckGuard.listenForRouteChanges();
|
||||
this.listenForRouteChanges();
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen to all router events. Every time a new navigation starts, invalidate the cache
|
||||
* for the root endpoint. That way we retrieve it once per routing operation to ensure the
|
||||
* backend is not down. But if the guard is called multiple times during the same routing
|
||||
* operation, the cached version is used.
|
||||
*/
|
||||
protected listenForRouteChanges(): void {
|
||||
// we'll always be too late for the first NavigationStart event with the router subscribe below,
|
||||
// so this statement is for the very first route operation.
|
||||
this.rootDataService.invalidateRootCache();
|
||||
|
||||
this.router.events.pipe(
|
||||
filter(event => event instanceof NavigationStart),
|
||||
).subscribe(() => {
|
||||
this.rootDataService.invalidateRootCache();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user