[Monitor Dashboard]: Fix a bug in app component with router events.

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-monitor-portal/trunk/monitor_dashboard@57857 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
Konstantinos Triantafyllou 2019-12-11 12:41:00 +00:00
parent bbaf91e51b
commit c3bba2ee58
1 changed files with 30 additions and 24 deletions

View File

@ -1,5 +1,12 @@
import {ChangeDetectorRef, Component, OnDestroy, OnInit} from '@angular/core';
import {ActivatedRoute, NavigationEnd, RouteConfigLoadEnd, Router} from '@angular/router';
import {
ActivatedRoute,
NavigationEnd,
NavigationError,
NavigationStart,
RouteConfigLoadEnd,
Router
} from '@angular/router';
import {EnvProperties} from './openaireLibrary/utils/properties/env-properties';
import {EnvironmentSpecificService} from './openaireLibrary/utils/properties/environment-specific.service';
@ -43,35 +50,34 @@ export class AppComponent implements OnInit, OnDestroy {
this.propertiesService.loadEnvironment()
.then(properties => {
this.properties = properties;
this.router.events.subscribe(event => {
if (event instanceof RouteConfigLoadEnd && event.route.path.indexOf('stakeholder') !== -1 ||
event instanceof NavigationEnd) {
let r = this.route;
while (r.firstChild) {
r = r.firstChild;
}
r.params.subscribe(params => {
if (params['stakeholder']) {
if (!this.stakeholderService.stakeholder ||
this.stakeholderService.stakeholder.alias !== params['stakeholder']) {
this.stakeholderService.getStakeholder(this.properties.monitorServiceAPIURL, params['stakeholder']).subscribe(stakeholder => {
this.stakeholderService.setStakeholder(stakeholder);
this.layoutService.setOpen(true);
});
}
} else {
this.stakeholderService.setStakeholder(null);
}
});
this.subscriptions.push(this.router.events.subscribe(() => {
let r = this.route;
while (r.firstChild) {
r = r.firstChild;
}
});
this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
this.subscriptions.push(r.params.subscribe(params => {
if (params['stakeholder'] &&
(!this.stakeholderService.stakeholder ||
this.stakeholderService.stakeholder.alias !== params['stakeholder'])) {
if (!this.stakeholderService.stakeholder ||
this.stakeholderService.stakeholder.alias !== params['stakeholder']) {
this.stakeholderService.getStakeholder(this.properties.monitorServiceAPIURL, params['stakeholder']).subscribe(stakeholder => {
this.stakeholderService.setStakeholder(stakeholder);
this.layoutService.setOpen(true);
});
}
} else {
this.stakeholderService.setStakeholder(null);
}
}));
}));
this.subscriptions.push(this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
this.user = user;
this.loginCheck = true;
}, error => {
console.log("App couldn't fetch properties");
console.log(error);
});
}));
});
}