2019-11-13 15:19:04 +01:00
|
|
|
import {ChangeDetectorRef, Component, OnDestroy, OnInit} from '@angular/core';
|
2019-11-01 19:30:11 +01:00
|
|
|
import {ActivatedRoute, NavigationEnd, Router} from '@angular/router';
|
2019-10-24 09:44:29 +02:00
|
|
|
|
|
|
|
import {EnvProperties} from './openaireLibrary/utils/properties/env-properties';
|
|
|
|
import {EnvironmentSpecificService} from './openaireLibrary/utils/properties/environment-specific.service';
|
2019-11-01 19:30:11 +01:00
|
|
|
import {User} from './openaireLibrary/login/utils/helper.class';
|
2019-10-24 09:44:29 +02:00
|
|
|
import {UserManagementService} from "./openaireLibrary/services/user-management.service";
|
2019-11-01 19:30:11 +01:00
|
|
|
import {SideBarService} from "./library/sharedComponents/sidebar/sideBar.service";
|
|
|
|
import {StakeholderService} from "./services/stakeholder.service";
|
2019-11-13 15:19:04 +01:00
|
|
|
import {Subscriber} from "rxjs";
|
2019-11-24 17:30:04 +01:00
|
|
|
|
2019-10-24 09:44:29 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-root',
|
2019-11-01 19:30:11 +01:00
|
|
|
templateUrl: './app.component.html'
|
2019-10-24 09:44:29 +02:00
|
|
|
})
|
2019-11-24 17:30:04 +01:00
|
|
|
export class AppComponent implements OnInit, OnDestroy {
|
2019-10-24 09:44:29 +02:00
|
|
|
properties: EnvProperties;
|
|
|
|
user: User;
|
|
|
|
loginCheck: boolean = false;
|
2019-11-01 19:30:11 +01:00
|
|
|
hasSidebar: boolean = false;
|
2019-11-13 15:19:04 +01:00
|
|
|
public subscriptions: any[] = [];
|
2019-11-01 19:30:11 +01:00
|
|
|
|
|
|
|
constructor(private route: ActivatedRoute,
|
|
|
|
private propertiesService: EnvironmentSpecificService,
|
|
|
|
private router: Router,
|
|
|
|
private userManagementService: UserManagementService,
|
2019-11-12 16:55:37 +01:00
|
|
|
private sidebarService: SideBarService,
|
2019-11-01 19:30:11 +01:00
|
|
|
private stakeholderService: StakeholderService,
|
|
|
|
private cdr: ChangeDetectorRef) {
|
2019-10-24 09:44:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.propertiesService.loadEnvironment()
|
2019-11-01 19:30:11 +01:00
|
|
|
.then(properties => {
|
|
|
|
this.properties = properties;
|
2019-11-05 15:59:06 +01:00
|
|
|
this.router.events.forEach((event) => {
|
|
|
|
if (event instanceof NavigationEnd) {
|
|
|
|
let r = this.route;
|
|
|
|
while (r.firstChild) {
|
|
|
|
r = r.firstChild;
|
|
|
|
}
|
|
|
|
r.params.subscribe(params => {
|
2019-11-24 17:30:04 +01:00
|
|
|
if (params['stakeholder']) {
|
|
|
|
if (!this.stakeholderService.stakeholder ||
|
2019-11-05 15:59:06 +01:00
|
|
|
this.stakeholderService.stakeholder.alias !== params['stakeholder']) {
|
2019-11-24 17:30:04 +01:00
|
|
|
this.stakeholderService.getStakeholder(this.properties.monitorServiceAPIURL, params['stakeholder']).subscribe(stakeholder => {
|
|
|
|
this.stakeholderService.setStakeholder(stakeholder);
|
|
|
|
console.log(stakeholder);
|
2019-11-12 16:55:37 +01:00
|
|
|
this.sidebarService.setOpen(true);
|
2019-11-24 17:30:04 +01:00
|
|
|
});
|
2019-11-05 15:59:06 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.stakeholderService.setStakeholder(null);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2019-11-01 19:30:11 +01:00
|
|
|
this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
|
2019-10-24 09:44:29 +02:00
|
|
|
this.user = user;
|
|
|
|
this.loginCheck = true;
|
|
|
|
}, error => {
|
|
|
|
console.log("App couldn't fetch properties");
|
|
|
|
console.log(error);
|
|
|
|
});
|
2019-11-01 19:30:11 +01:00
|
|
|
});
|
2019-11-13 15:19:04 +01:00
|
|
|
this.subscriptions.push(this.sidebarService.hasSidebar.subscribe(hasSidebar => {
|
2019-11-01 19:30:11 +01:00
|
|
|
this.hasSidebar = hasSidebar;
|
|
|
|
this.cdr.detectChanges();
|
2019-11-13 15:19:04 +01:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnDestroy() {
|
2019-11-24 17:30:04 +01:00
|
|
|
this.subscriptions.forEach(value => {
|
|
|
|
if (value instanceof Subscriber) {
|
2019-11-13 15:19:04 +01:00
|
|
|
value.unsubscribe();
|
|
|
|
}
|
2019-11-01 19:30:11 +01:00
|
|
|
});
|
2019-10-24 09:44:29 +02:00
|
|
|
}
|
|
|
|
|
2019-11-01 19:30:11 +01:00
|
|
|
public get open() {
|
2019-11-12 16:55:37 +01:00
|
|
|
return this.sidebarService.open;
|
2019-11-01 19:30:11 +01:00
|
|
|
}
|
2019-10-24 09:44:29 +02:00
|
|
|
|
2019-11-01 19:30:11 +01:00
|
|
|
public toggleOpen(event = null) {
|
2019-11-24 17:30:04 +01:00
|
|
|
if (!event) {
|
2019-11-12 16:55:37 +01:00
|
|
|
this.sidebarService.setOpen(!this.open);
|
2019-11-24 17:30:04 +01:00
|
|
|
} else if (event && event['value'] === true) {
|
2019-11-12 16:55:37 +01:00
|
|
|
this.sidebarService.setOpen(false);
|
2019-11-01 19:30:11 +01:00
|
|
|
}
|
2019-10-24 09:44:29 +02:00
|
|
|
}
|
|
|
|
}
|