app.component.ts (dspace-angular-dspace-7.0) | : | app.component.ts (dspace-angular-dspace-7.1) | ||
---|---|---|---|---|
import { delay, distinctUntilChanged, filter, take, withLatestFrom } from 'rxjs/ operators'; | import { distinctUntilChanged, filter, switchMap, take, withLatestFrom } from 'r xjs/operators'; | |||
import { | import { | |||
AfterViewInit, | AfterViewInit, | |||
ChangeDetectionStrategy, | ChangeDetectionStrategy, | |||
Component, | Component, | |||
HostListener, | HostListener, | |||
Inject, | Inject, | |||
OnInit, | OnInit, | |||
Optional, | Optional, | |||
PLATFORM_ID, | PLATFORM_ID, | |||
} from '@angular/core'; | } from '@angular/core'; | |||
import { NavigationCancel, NavigationEnd, NavigationStart, Router } from '@angul | import { | |||
ar/router'; | ActivatedRouteSnapshot, | |||
NavigationCancel, | ||||
NavigationEnd, | ||||
NavigationStart, ResolveEnd, | ||||
Router, | ||||
} from '@angular/router'; | ||||
import { BehaviorSubject, Observable, of } from 'rxjs'; | import { BehaviorSubject, Observable, of } from 'rxjs'; | |||
import { select, Store } from '@ngrx/store'; | import { select, Store } from '@ngrx/store'; | |||
import { TranslateService } from '@ngx-translate/core'; | import { TranslateService } from '@ngx-translate/core'; | |||
import { Angulartics2GoogleAnalytics } from 'angulartics2/ga'; | import { Angulartics2GoogleAnalytics } from 'angulartics2/ga'; | |||
import { MetadataService } from './core/metadata/metadata.service'; | import { MetadataService } from './core/metadata/metadata.service'; | |||
import { HostWindowResizeAction } from './shared/host-window.actions'; | import { HostWindowResizeAction } from './shared/host-window.actions'; | |||
import { HostWindowState } from './shared/search/host-window.reducer'; | import { HostWindowState } from './shared/search/host-window.reducer'; | |||
import { NativeWindowRef, NativeWindowService } from './core/services/window.ser vice'; | import { NativeWindowRef, NativeWindowService } from './core/services/window.ser vice'; | |||
skipping to change at line 74 | skipping to change at line 80 | |||
/** | /** | |||
* Whether or not the app is in the process of rerouting | * Whether or not the app is in the process of rerouting | |||
*/ | */ | |||
isRouteLoading$: BehaviorSubject<boolean> = new BehaviorSubject(true); | isRouteLoading$: BehaviorSubject<boolean> = new BehaviorSubject(true); | |||
/** | /** | |||
* Whether or not the theme is in the process of being swapped | * Whether or not the theme is in the process of being swapped | |||
*/ | */ | |||
isThemeLoading$: BehaviorSubject<boolean> = new BehaviorSubject(false); | isThemeLoading$: BehaviorSubject<boolean> = new BehaviorSubject(false); | |||
isThemeCSSLoading$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(fa | ||||
lse); | ||||
/** | /** | |||
* Whether or not the idle modal is is currently open | * Whether or not the idle modal is is currently open | |||
*/ | */ | |||
idleModalOpen: boolean; | idleModalOpen: boolean; | |||
constructor( | constructor( | |||
@Inject(NativeWindowService) private _window: NativeWindowRef, | @Inject(NativeWindowService) private _window: NativeWindowRef, | |||
@Inject(DOCUMENT) private document: any, | @Inject(DOCUMENT) private document: any, | |||
@Inject(PLATFORM_ID) private platformId: any, | @Inject(PLATFORM_ID) private platformId: any, | |||
private themeService: ThemeService, | private themeService: ThemeService, | |||
skipping to change at line 107 | skipping to change at line 115 | |||
@Optional() private cookiesService: KlaroService, | @Optional() private cookiesService: KlaroService, | |||
@Optional() private googleAnalyticsService: GoogleAnalyticsService, | @Optional() private googleAnalyticsService: GoogleAnalyticsService, | |||
) { | ) { | |||
/* Use models object so all decorators are actually called */ | /* Use models object so all decorators are actually called */ | |||
this.models = models; | this.models = models; | |||
this.themeService.getThemeName$().subscribe((themeName: string) => { | this.themeService.getThemeName$().subscribe((themeName: string) => { | |||
if (isPlatformBrowser(this.platformId)) { | if (isPlatformBrowser(this.platformId)) { | |||
// the theme css will never download server side, so this should only ha ppen on the browser | // the theme css will never download server side, so this should only ha ppen on the browser | |||
this.isThemeLoading$.next(true); | this.isThemeCSSLoading$.next(true); | |||
} | } | |||
if (hasValue(themeName)) { | if (hasValue(themeName)) { | |||
this.setThemeCss(themeName); | this.setThemeCss(themeName); | |||
} else if (hasValue(DEFAULT_THEME_CONFIG)) { | } else if (hasValue(DEFAULT_THEME_CONFIG)) { | |||
this.setThemeCss(DEFAULT_THEME_CONFIG.name); | this.setThemeCss(DEFAULT_THEME_CONFIG.name); | |||
} else { | } else { | |||
this.setThemeCss(BASE_THEME_NAME); | this.setThemeCss(BASE_THEME_NAME); | |||
} | } | |||
}); | }); | |||
skipping to change at line 179 | skipping to change at line 187 | |||
this.cssService.addCSSVariable('sidebarItemsWidth', '250px'); | this.cssService.addCSSVariable('sidebarItemsWidth', '250px'); | |||
this.cssService.addCSSVariable('collapsedSidebarWidth', '53.234px'); | this.cssService.addCSSVariable('collapsedSidebarWidth', '53.234px'); | |||
this.cssService.addCSSVariable('totalSidebarWidth', '303.234px'); | this.cssService.addCSSVariable('totalSidebarWidth', '303.234px'); | |||
// const vars = variables.locals || {}; | // const vars = variables.locals || {}; | |||
// Object.keys(vars).forEach((name: string) => { | // Object.keys(vars).forEach((name: string) => { | |||
// this.cssService.addCSSVariable(name, vars[name]); | // this.cssService.addCSSVariable(name, vars[name]); | |||
// }) | // }) | |||
} | } | |||
ngAfterViewInit() { | ngAfterViewInit() { | |||
this.router.events.pipe( | let resolveEndFound = false; | |||
// This fixes an ExpressionChangedAfterItHasBeenCheckedError from being th | this.router.events.subscribe((event) => { | |||
rown while loading the component | ||||
// More information on this bug-fix: https://blog.angular-university.io/an | ||||
gular-debugging/ | ||||
delay(0) | ||||
).subscribe((event) => { | ||||
if (event instanceof NavigationStart) { | if (event instanceof NavigationStart) { | |||
resolveEndFound = false; | ||||
this.isRouteLoading$.next(true); | this.isRouteLoading$.next(true); | |||
this.isThemeLoading$.next(true); | ||||
} else if (event instanceof ResolveEnd) { | ||||
resolveEndFound = true; | ||||
const activatedRouteSnapShot: ActivatedRouteSnapshot = event.state.root; | ||||
this.themeService.updateThemeOnRouteChange$(event.urlAfterRedirects, act | ||||
ivatedRouteSnapShot).pipe( | ||||
switchMap((changed) => { | ||||
if (changed) { | ||||
return this.isThemeCSSLoading$; | ||||
} else { | ||||
return [false]; | ||||
} | ||||
}) | ||||
).subscribe((changed) => { | ||||
this.isThemeLoading$.next(changed); | ||||
}); | ||||
} else if ( | } else if ( | |||
event instanceof NavigationEnd || | event instanceof NavigationEnd || | |||
event instanceof NavigationCancel | event instanceof NavigationCancel | |||
) { | ) { | |||
if (!resolveEndFound) { | ||||
this.isThemeLoading$.next(false); | ||||
} | ||||
this.isRouteLoading$.next(false); | this.isRouteLoading$.next(false); | |||
} | } | |||
}); | }); | |||
} | } | |||
@HostListener('window:resize', ['$event']) | @HostListener('window:resize', ['$event']) | |||
public onResize(event): void { | public onResize(event): void { | |||
this.dispatchWindowSize(event.target.innerWidth, event.target.innerHeight); | this.dispatchWindowSize(event.target.innerWidth, event.target.innerHeight); | |||
} | } | |||
skipping to change at line 239 | skipping to change at line 263 | |||
// flash of unstyled content | // flash of unstyled content | |||
link.onload = () => { | link.onload = () => { | |||
if (isNotEmpty(currentThemeLinks)) { | if (isNotEmpty(currentThemeLinks)) { | |||
currentThemeLinks.forEach((currentThemeLink: any) => { | currentThemeLinks.forEach((currentThemeLink: any) => { | |||
if (hasValue(currentThemeLink)) { | if (hasValue(currentThemeLink)) { | |||
currentThemeLink.remove(); | currentThemeLink.remove(); | |||
} | } | |||
}); | }); | |||
} | } | |||
// the fact that this callback is used, proves we're on the browser. | // the fact that this callback is used, proves we're on the browser. | |||
this.isThemeLoading$.next(false); | this.isThemeCSSLoading$.next(false); | |||
}; | }; | |||
head.appendChild(link); | head.appendChild(link); | |||
} | } | |||
private trackIdleModal() { | private trackIdleModal() { | |||
const isIdle$ = this.authService.isUserIdle(); | const isIdle$ = this.authService.isUserIdle(); | |||
const isAuthenticated$ = this.authService.isAuthenticated(); | const isAuthenticated$ = this.authService.isAuthenticated(); | |||
isIdle$.pipe(withLatestFrom(isAuthenticated$)) | isIdle$.pipe(withLatestFrom(isAuthenticated$)) | |||
.subscribe(([userIdle, authenticated]) => { | .subscribe(([userIdle, authenticated]) => { | |||
if (userIdle && authenticated) { | if (userIdle && authenticated) { | |||
End of changes. 9 change blocks. | ||||
12 lines changed or deleted | 35 lines changed or added |