[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 {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);
}
}
}
}