1
|
import {ChangeDetectorRef, Component, OnDestroy, OnInit} from '@angular/core';
|
2
|
import {ActivatedRoute, NavigationEnd, Router} from '@angular/router';
|
3
|
|
4
|
import {EnvProperties} from './openaireLibrary/utils/properties/env-properties';
|
5
|
import {EnvironmentSpecificService} from './openaireLibrary/utils/properties/environment-specific.service';
|
6
|
import {User} from './openaireLibrary/login/utils/helper.class';
|
7
|
import {UserManagementService} from "./openaireLibrary/services/user-management.service";
|
8
|
import {StakeholderService} from "./services/stakeholder.service";
|
9
|
import {Subscriber} from "rxjs";
|
10
|
import {LayoutService} from "./library/sharedComponents/sidebar/layout.service";
|
11
|
|
12
|
|
13
|
@Component({
|
14
|
selector: 'app-root',
|
15
|
templateUrl: './app.component.html'
|
16
|
})
|
17
|
export class AppComponent implements OnInit, OnDestroy {
|
18
|
properties: EnvProperties;
|
19
|
user: User;
|
20
|
loginCheck: boolean = false;
|
21
|
hasSidebar: boolean = false;
|
22
|
hasHeader: boolean = false;
|
23
|
private subscriptions: any[] = [];
|
24
|
|
25
|
constructor(private route: ActivatedRoute,
|
26
|
private propertiesService: EnvironmentSpecificService,
|
27
|
private router: Router,
|
28
|
private userManagementService: UserManagementService,
|
29
|
private layoutService: LayoutService,
|
30
|
private stakeholderService: StakeholderService,
|
31
|
private cdr: ChangeDetectorRef) {
|
32
|
}
|
33
|
|
34
|
ngOnInit() {
|
35
|
this.propertiesService.loadEnvironment()
|
36
|
.then(properties => {
|
37
|
this.properties = properties;
|
38
|
this.router.events.forEach((event) => {
|
39
|
if (event instanceof NavigationEnd) {
|
40
|
let r = this.route;
|
41
|
while (r.firstChild) {
|
42
|
r = r.firstChild;
|
43
|
}
|
44
|
r.params.subscribe(params => {
|
45
|
if (params['stakeholder']) {
|
46
|
if (!this.stakeholderService.stakeholder ||
|
47
|
this.stakeholderService.stakeholder.alias !== params['stakeholder']) {
|
48
|
this.stakeholderService.getStakeholder(this.properties.monitorServiceAPIURL, params['stakeholder']).subscribe(stakeholder => {
|
49
|
this.stakeholderService.setStakeholder(stakeholder);
|
50
|
this.layoutService.setOpen(true);
|
51
|
});
|
52
|
}
|
53
|
} else {
|
54
|
this.stakeholderService.setStakeholder(null);
|
55
|
}
|
56
|
});
|
57
|
}
|
58
|
});
|
59
|
this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
|
60
|
this.user = user;
|
61
|
this.loginCheck = true;
|
62
|
}, error => {
|
63
|
console.log("App couldn't fetch properties");
|
64
|
console.log(error);
|
65
|
});
|
66
|
});
|
67
|
this.subscriptions.push(this.layoutService.hasSidebar.subscribe(hasSidebar => {
|
68
|
this.hasSidebar = hasSidebar;
|
69
|
this.cdr.detectChanges();
|
70
|
}));
|
71
|
this.subscriptions.push(this.layoutService.hasHeader.subscribe(hasHeader => {
|
72
|
this.hasHeader = hasHeader;
|
73
|
console.log(this.hasHeader);
|
74
|
this.cdr.detectChanges();
|
75
|
}));
|
76
|
}
|
77
|
|
78
|
public ngOnDestroy() {
|
79
|
this.subscriptions.forEach(value => {
|
80
|
if (value instanceof Subscriber) {
|
81
|
value.unsubscribe();
|
82
|
}
|
83
|
});
|
84
|
}
|
85
|
|
86
|
public get open() {
|
87
|
return this.layoutService.open;
|
88
|
}
|
89
|
|
90
|
public toggleOpen(event = null) {
|
91
|
if (!event) {
|
92
|
this.layoutService.setOpen(!this.open);
|
93
|
} else if (event && event['value'] === true) {
|
94
|
this.layoutService.setOpen(false);
|
95
|
}
|
96
|
}
|
97
|
}
|