From 7e2704fcfe90b6203cd21ea4add4f032899105bf Mon Sep 17 00:00:00 2001 From: Konstantinos Triantafyllou Date: Mon, 9 Dec 2019 15:20:23 +0000 Subject: [PATCH] [MonitorDashboard]: Fix a bug on app component git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-monitor-portal/trunk/monitor_dashboard@57847 d315682c-612b-4755-9ff5-7f18f6832af3 --- src/app/app.component.ts | 159 ++++++++++++++++++++------------------- 1 file changed, 80 insertions(+), 79 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index ba6fe20..8c13208 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,5 +1,5 @@ import {ChangeDetectorRef, Component, OnDestroy, OnInit} from '@angular/core'; -import {ActivatedRoute, NavigationEnd, Router} from '@angular/router'; +import {ActivatedRoute, NavigationEnd, RouteConfigLoadEnd, Router} from '@angular/router'; import {EnvProperties} from './openaireLibrary/utils/properties/env-properties'; import {EnvironmentSpecificService} from './openaireLibrary/utils/properties/environment-specific.service'; @@ -11,86 +11,87 @@ import {LayoutService} from "./library/sharedComponents/sidebar/layout.service"; @Component({ - selector: 'app-root', - templateUrl: './app.component.html' + selector: 'app-root', + templateUrl: './app.component.html' }) export class AppComponent implements OnInit, OnDestroy { - properties: EnvProperties; - user: User; - loginCheck: boolean = false; - hasSidebar: boolean = false; - hasHeader: boolean = false; - private subscriptions: any[] = []; + properties: EnvProperties; + user: User; + loginCheck: boolean = false; + hasSidebar: boolean = false; + hasHeader: boolean = false; + private subscriptions: any[] = []; - constructor(private route: ActivatedRoute, - private propertiesService: EnvironmentSpecificService, - private router: Router, - private userManagementService: UserManagementService, - private layoutService: LayoutService, - private stakeholderService: StakeholderService, - private cdr: ChangeDetectorRef) { - } - - ngOnInit() { - this.subscriptions.push(this.layoutService.hasSidebar.subscribe(hasSidebar => { - this.hasSidebar = hasSidebar; - this.cdr.detectChanges(); - })); - this.subscriptions.push(this.layoutService.hasHeader.subscribe(hasHeader => { - this.hasHeader = hasHeader; - this.cdr.detectChanges(); - })); - this.propertiesService.loadEnvironment() - .then(properties => { - this.properties = properties; - this.router.events.subscribe(event => { - if (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.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => { - this.user = user; - this.loginCheck = true; - }, error => { - console.log("App couldn't fetch properties"); - console.log(error); - }); - }); - } - - public ngOnDestroy() { - this.subscriptions.forEach(value => { - if (value instanceof Subscriber) { - value.unsubscribe(); - } - }); - } - - public get open() { - return this.layoutService.open; - } - - public toggleOpen(event = null) { - if (!event) { - this.layoutService.setOpen(!this.open); - } else if (event && event['value'] === true) { - this.layoutService.setOpen(false); + constructor(private route: ActivatedRoute, + private propertiesService: EnvironmentSpecificService, + private router: Router, + private userManagementService: UserManagementService, + private layoutService: LayoutService, + private stakeholderService: StakeholderService, + private cdr: ChangeDetectorRef) { + } + + ngOnInit() { + this.subscriptions.push(this.layoutService.hasSidebar.subscribe(hasSidebar => { + this.hasSidebar = hasSidebar; + this.cdr.detectChanges(); + })); + this.subscriptions.push(this.layoutService.hasHeader.subscribe(hasHeader => { + this.hasHeader = hasHeader; + this.cdr.detectChanges(); + })); + 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.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => { + this.user = user; + this.loginCheck = true; + }, error => { + console.log("App couldn't fetch properties"); + console.log(error); + }); + }); + } + + public ngOnDestroy() { + this.subscriptions.forEach(value => { + if (value instanceof Subscriber) { + value.unsubscribe(); + } + }); + } + + public get open() { + return this.layoutService.open; + } + + public toggleOpen(event = null) { + if (!event) { + this.layoutService.setOpen(!this.open); + } else if (event && event['value'] === true) { + this.layoutService.setOpen(false); + } } - } }