diff --git a/src/app/app.component.html b/src/app/app.component.html index fc94cb0..591d04e 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -2,25 +2,26 @@
-
@@ -46,4 +47,5 @@
+ diff --git a/src/app/app.component.ts b/src/app/app.component.ts index e0fd17d..c7c22d9 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -4,7 +4,7 @@ import {EnvProperties} from './openaireLibrary/utils/properties/env-properties'; import {Role, Session, User} from './openaireLibrary/login/utils/helper.class'; import {UserManagementService} from "./openaireLibrary/services/user-management.service"; import {StakeholderService} from "./openaireLibrary/monitor/services/stakeholder.service"; -import {BehaviorSubject, Subscriber} from "rxjs"; +import {BehaviorSubject, Subscriber, Subscription} from "rxjs"; import {LayoutService} from "./openaireLibrary/dashboard/sharedComponents/sidebar/layout.service"; import {MenuItem} from "./openaireLibrary/sharedComponents/menu"; import { @@ -33,6 +33,7 @@ import {StringUtils} from "./openaireLibrary/utils/string-utils.class"; export class AppComponent implements OnInit, OnDestroy { properties: EnvProperties = properties; user: User; + updateStakeholder: boolean = true; params: BehaviorSubject = new BehaviorSubject(null); data: BehaviorSubject = new BehaviorSubject(null); hasSidebar: boolean = false; @@ -68,6 +69,7 @@ export class AppComponent implements OnInit, OnDestroy { loading: boolean = true; paramsResolved: boolean = false; innerWidth; + paramsSubscription: Subscription; private subscriptions: any[] = []; constructor(private route: ActivatedRoute, @@ -134,42 +136,7 @@ export class AppComponent implements OnInit, OnDestroy { }); this.layoutService.setSmallScreen((this.innerWidth && this.innerWidth <= 640)); this.layoutService.setOpen(!(this.innerWidth && this.innerWidth <= 640)); - this.subscriptions.push(this.params.subscribe(params => { - if (this.paramsResolved) { - this.loading = true; - if (params && params['stakeholder']) { - if (!this.stakeholder || this.stakeholder.alias !== params['stakeholder']) { - this.subscriptions.push(this.stakeholderService.getStakeholder(params['stakeholder']).subscribe(stakeholder => { - if (stakeholder) { - this.stakeholder = stakeholder; - LinksResolver.setProperties(this.stakeholder.alias); - this.setProperties(this.stakeholder.alias, this.stakeholder.type); - this.buildMenu(); - this.setActives(params); - this.setSideBar(); - this.loading = false; - } else { - this.stakeholder = null; - LinksResolver.resetProperties(); - this.navigateToError(); - this.buildMenu(); - this.loading = false; - } - })); - } else { - this.buildMenu(); - this.setActives(params); - this.loading = false; - } - } else { - LinksResolver.resetProperties(); - this.stakeholderService.setStakeholder(null); - this.stakeholder = null; - this.buildMenu(); - this.loading = false; - } - } - })); + this.subscriptions.push(this.data.subscribe(data => { if (data && data.portal) { this.setProperties(data.portal); @@ -177,18 +144,58 @@ export class AppComponent implements OnInit, OnDestroy { } })); this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => { + this.updateStakeholder = true; if (user) { this.user = user; - this.buildMenu(); if (!this.notificationGroupsInitialized) { this.setNotificationGroups(); } } else if(this.user) { this.user = user; - this.buildMenu(); this.notificationGroupsInitialized = false; this.notificationGroups = []; } + if(this.paramsSubscription) { + this.paramsSubscription.unsubscribe(); + } + this.paramsSubscription = this.params.subscribe(params => { + if (this.paramsResolved) { + this.loading = true; + if (params && params['stakeholder']) { + if (!this.stakeholder || this.stakeholder.alias !== params['stakeholder'] || this.updateStakeholder) { + this.subscriptions.push(this.stakeholderService.getStakeholder(params['stakeholder'], this.updateStakeholder).subscribe(stakeholder => { + if (stakeholder) { + this.stakeholder = stakeholder; + console.log(this.stakeholder); + this.updateStakeholder = false; + LinksResolver.setProperties(this.stakeholder.alias); + this.setProperties(this.stakeholder.alias, this.stakeholder.type); + this.buildMenu(); + this.setActives(params); + this.setSideBar(); + this.loading = false; + } else { + this.stakeholder = null; + LinksResolver.resetProperties(); + this.navigateToError(); + this.buildMenu(); + this.loading = false; + } + })); + } else { + this.buildMenu(); + this.setActives(params); + this.loading = false; + } + } else { + LinksResolver.resetProperties(); + this.stakeholderService.setStakeholder(null); + this.stakeholder = null; + this.buildMenu(); + this.loading = false; + } + } + }); })); } @@ -236,6 +243,9 @@ export class AppComponent implements OnInit, OnDestroy { } public ngOnDestroy() { + if(this.paramsSubscription) { + this.paramsSubscription.unsubscribe(); + } this.subscriptions.forEach(value => { if (value instanceof Subscriber) { value.unsubscribe(); diff --git a/src/app/openaireLibrary b/src/app/openaireLibrary index da144c1..53400f7 160000 --- a/src/app/openaireLibrary +++ b/src/app/openaireLibrary @@ -1 +1 @@ -Subproject commit da144c1c77012fa4489dd84f013d499f9df8f72a +Subproject commit 53400f774505b7461ba5773f3d2d40cfc7091e34