Load profile after refresh
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good

This commit is contained in:
Willem Dantuma 2023-03-07 14:14:14 +01:00
parent 7c8c16362c
commit 3c7adf012f

View File

@ -1,4 +1,4 @@
import { Component, OnInit, OnDestroy, Inject, Optional,ViewEncapsulation, RendererFactory2, PLATFORM_ID, ChangeDetectionStrategy, HostListener, Input } from '@angular/core'; import { Component, OnInit, OnDestroy, Inject, Optional, ViewEncapsulation, RendererFactory2, PLATFORM_ID, ChangeDetectionStrategy, HostListener, Input } from '@angular/core';
import { Router, NavigationStart, NavigationEnd, RouteConfigLoadStart, RouteConfigLoadEnd, ActivatedRoute, PRIMARY_OUTLET } from '@angular/router'; import { Router, NavigationStart, NavigationEnd, RouteConfigLoadStart, RouteConfigLoadEnd, ActivatedRoute, PRIMARY_OUTLET } from '@angular/router';
import { Meta, Title, MetaDefinition } from '@angular/platform-browser'; import { DOCUMENT } from "@angular/common"; import { Meta, Title, MetaDefinition } from '@angular/platform-browser'; import { DOCUMENT } from "@angular/common";
import { Subscription, Observable } from 'rxjs'; import { Subscription, Observable } from 'rxjs';
@ -6,7 +6,7 @@ import { distinctUntilChanged } from 'rxjs/operators';
import { Store, Action } from '@ngrx/store'; import { Store, Action } from '@ngrx/store';
import { IUser } from '../../models/user'; import { IUser } from '../../models/user';
import { OAuthService, OAuthErrorEvent } from 'angular-oauth2-oidc'; import { OAuthService, OAuthErrorEvent } from 'angular-oauth2-oidc';
import { FM_COMMON_STARTPAGE} from '../../common.module'; import { FM_COMMON_STARTPAGE } from '../../common.module';
//AppCommon //AppCommon
import { IEventMessage } from '../../models/event.message'; import { IEventMessage } from '../../models/event.message';
@ -48,7 +48,7 @@ export class AppComponent implements OnInit, OnDestroy {
public helpMenuVisible: Observable<boolean> = this.store$.select(appReducers.SelectGetHelpMenuVisible); public helpMenuVisible: Observable<boolean> = this.store$.select(appReducers.SelectGetHelpMenuVisible);
public unreadNotifications: Observable<number> = this.store$.select(appReducers.SelectgetUnreadNotifications); public unreadNotifications: Observable<number> = this.store$.select(appReducers.SelectgetUnreadNotifications);
public user: Observable<IUser> = this.store$.select(appReducers.SelectGetUser); public user: Observable<IUser> = this.store$.select(appReducers.SelectGetUser);
public isPageMode: Observable<boolean> = this.store$.select(appReducers.SelectGetIsPageMode); public isPageMode: Observable<boolean> = this.store$.select(appReducers.SelectGetIsPageMode);
@Input() showUploadProgress = true; @Input() showUploadProgress = true;
constructor( constructor(
@ -116,7 +116,7 @@ export class AppComponent implements OnInit, OnDestroy {
} }
async loadItemTypes() { async loadItemTypes() {
await this.itemTypeService$.load(this.appConfig$) await this.itemTypeService$.load(this.appConfig$)
} }
ngOnInit() { ngOnInit() {
@ -155,14 +155,15 @@ export class AppComponent implements OnInit, OnDestroy {
this.router.navigate(['loggedout'], { queryParams: { redirectTo: this.router.url } }); this.router.navigate(['loggedout'], { queryParams: { redirectTo: this.router.url } });
} }
} }
if(event.type == 'token_received') { if (event.type == 'token_received') {
this.oauthService$.loadUserProfile();
this.store$.dispatch(new commonActions.InitUser()); this.store$.dispatch(new commonActions.InitUser());
} }
}); });
if(this.oauthService$.hasValidAccessToken()) { if (this.oauthService$.hasValidAccessToken()) {
this.store$.dispatch(new commonActions.InitUser()); this.store$.dispatch(new commonActions.InitUser());
} else { } else {
if(this.oauthService$.getRefreshToken() !=null) { if (this.oauthService$.getRefreshToken() != null) {
this.oauthService$.refreshToken(); this.oauthService$.refreshToken();
} }
} }
@ -174,7 +175,7 @@ export class AppComponent implements OnInit, OnDestroy {
if (event instanceof RouteConfigLoadStart) { if (event instanceof RouteConfigLoadStart) {
other.store$.dispatch(new commonActions.StartRouteLoading()); other.store$.dispatch(new commonActions.StartRouteLoading());
} }
if (event instanceof NavigationEnd && (event.url == "/" || event.url.startsWith("/content") )) { if (event instanceof NavigationEnd && (event.url == "/" || event.url.startsWith("/content"))) {
other.store$.dispatch(new commonActions.SetPageMode(true)); other.store$.dispatch(new commonActions.SetPageMode(true));
} else if (event instanceof NavigationEnd) { } else if (event instanceof NavigationEnd) {
other.store$.dispatch(new commonActions.SetPageMode(false)); other.store$.dispatch(new commonActions.SetPageMode(false));
@ -197,8 +198,8 @@ export class AppComponent implements OnInit, OnDestroy {
} }
private InstallHealthCheck() { private InstallHealthCheck() {
//check health every 30 seconds //check health every 30 seconds
this.healthCheckService$.check(30000).pipe(distinctUntilChanged()).subscribe((online) => { this.healthCheckService$.check(30000).pipe(distinctUntilChanged()).subscribe((online) => {
if (online) { if (online) {
this.store$.dispatch(new commonActions.Online()); this.store$.dispatch(new commonActions.Online());
} else { } else {