[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
This commit is contained in:
Konstantinos Triantafyllou 2019-12-09 15:20:23 +00:00
parent c5229ca8fb
commit 7e2704fcfe
1 changed files with 80 additions and 79 deletions

View File

@ -1,5 +1,5 @@
import {ChangeDetectorRef, Component, OnDestroy, OnInit} from '@angular/core'; 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 {EnvProperties} from './openaireLibrary/utils/properties/env-properties';
import {EnvironmentSpecificService} from './openaireLibrary/utils/properties/environment-specific.service'; import {EnvironmentSpecificService} from './openaireLibrary/utils/properties/environment-specific.service';
@ -11,86 +11,87 @@ import {LayoutService} from "./library/sharedComponents/sidebar/layout.service";
@Component({ @Component({
selector: 'app-root', selector: 'app-root',
templateUrl: './app.component.html' templateUrl: './app.component.html'
}) })
export class AppComponent implements OnInit, OnDestroy { export class AppComponent implements OnInit, OnDestroy {
properties: EnvProperties; properties: EnvProperties;
user: User; user: User;
loginCheck: boolean = false; loginCheck: boolean = false;
hasSidebar: boolean = false; hasSidebar: boolean = false;
hasHeader: boolean = false; hasHeader: boolean = false;
private subscriptions: any[] = []; private subscriptions: any[] = [];
constructor(private route: ActivatedRoute, constructor(private route: ActivatedRoute,
private propertiesService: EnvironmentSpecificService, private propertiesService: EnvironmentSpecificService,
private router: Router, private router: Router,
private userManagementService: UserManagementService, private userManagementService: UserManagementService,
private layoutService: LayoutService, private layoutService: LayoutService,
private stakeholderService: StakeholderService, private stakeholderService: StakeholderService,
private cdr: ChangeDetectorRef) { private cdr: ChangeDetectorRef) {
} }
ngOnInit() { ngOnInit() {
this.subscriptions.push(this.layoutService.hasSidebar.subscribe(hasSidebar => { this.subscriptions.push(this.layoutService.hasSidebar.subscribe(hasSidebar => {
this.hasSidebar = hasSidebar; this.hasSidebar = hasSidebar;
this.cdr.detectChanges(); this.cdr.detectChanges();
})); }));
this.subscriptions.push(this.layoutService.hasHeader.subscribe(hasHeader => { this.subscriptions.push(this.layoutService.hasHeader.subscribe(hasHeader => {
this.hasHeader = hasHeader; this.hasHeader = hasHeader;
this.cdr.detectChanges(); this.cdr.detectChanges();
})); }));
this.propertiesService.loadEnvironment() this.propertiesService.loadEnvironment()
.then(properties => { .then(properties => {
this.properties = properties; this.properties = properties;
this.router.events.subscribe(event => { this.router.events.subscribe(event => {
if (event instanceof NavigationEnd) { if (event instanceof RouteConfigLoadEnd && event.route.path.indexOf('stakeholder') !== -1 ||
let r = this.route; event instanceof NavigationEnd) {
while (r.firstChild) { let r = this.route;
r = r.firstChild; while (r.firstChild) {
} r = r.firstChild;
r.params.subscribe(params => { }
if (params['stakeholder']) { r.params.subscribe(params => {
if (!this.stakeholderService.stakeholder || if (params['stakeholder']) {
this.stakeholderService.stakeholder.alias !== params['stakeholder']) { if (!this.stakeholderService.stakeholder ||
this.stakeholderService.getStakeholder(this.properties.monitorServiceAPIURL, params['stakeholder']).subscribe(stakeholder => { this.stakeholderService.stakeholder.alias !== params['stakeholder']) {
this.stakeholderService.setStakeholder(stakeholder); this.stakeholderService.getStakeholder(this.properties.monitorServiceAPIURL, params['stakeholder']).subscribe(stakeholder => {
this.layoutService.setOpen(true); this.stakeholderService.setStakeholder(stakeholder);
}); this.layoutService.setOpen(true);
} });
} else { }
this.stakeholderService.setStakeholder(null); } else {
} this.stakeholderService.setStakeholder(null);
}); }
} });
}); }
this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => { });
this.user = user; this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
this.loginCheck = true; this.user = user;
}, error => { this.loginCheck = true;
console.log("App couldn't fetch properties"); }, error => {
console.log(error); console.log("App couldn't fetch properties");
}); console.log(error);
}); });
} });
}
public ngOnDestroy() {
this.subscriptions.forEach(value => { public ngOnDestroy() {
if (value instanceof Subscriber) { this.subscriptions.forEach(value => {
value.unsubscribe(); if (value instanceof Subscriber) {
} value.unsubscribe();
}); }
} });
}
public get open() {
return this.layoutService.open; public get open() {
} return this.layoutService.open;
}
public toggleOpen(event = null) {
if (!event) { public toggleOpen(event = null) {
this.layoutService.setOpen(!this.open); if (!event) {
} else if (event && event['value'] === true) { this.layoutService.setOpen(!this.open);
this.layoutService.setOpen(false); } else if (event && event['value'] === true) {
this.layoutService.setOpen(false);
}
} }
}
} }