2019-11-13 15:19:04 +01:00
|
|
|
import {ChangeDetectorRef, Component, OnDestroy, OnInit} from '@angular/core';
|
2019-12-21 14:32:43 +01:00
|
|
|
import {ActivatedRoute, NavigationEnd, Params, 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-12-12 15:20:03 +01:00
|
|
|
import {Session, 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 {StakeholderService} from "./services/stakeholder.service";
|
2019-12-21 14:32:43 +01:00
|
|
|
import {BehaviorSubject, Subscriber} from "rxjs";
|
2019-11-27 11:09:14 +01:00
|
|
|
import {LayoutService} from "./library/sharedComponents/sidebar/layout.service";
|
2019-12-12 15:20:03 +01:00
|
|
|
import {MenuItem} from "./openaireLibrary/sharedComponents/menu";
|
2019-12-20 12:48:35 +01:00
|
|
|
import {Item} from "./utils/entities/sidebar";
|
2019-11-24 17:30:04 +01:00
|
|
|
|
2019-10-24 09:44:29 +02:00
|
|
|
|
|
|
|
@Component({
|
2019-12-20 12:48:35 +01:00
|
|
|
selector: 'app-root',
|
|
|
|
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-12-20 12:48:35 +01:00
|
|
|
properties: EnvProperties;
|
|
|
|
user: User;
|
2019-12-21 14:32:43 +01:00
|
|
|
params: BehaviorSubject<Params> = new BehaviorSubject<Params>(null);
|
2019-12-20 12:48:35 +01:00
|
|
|
hasSidebar: boolean = false;
|
|
|
|
hasHeader: boolean = false;
|
2019-12-21 14:32:43 +01:00
|
|
|
userMenuItems: MenuItem[] = [];
|
2019-12-20 12:48:35 +01:00
|
|
|
adminMenuItems: Item[] = [];
|
2019-12-21 14:32:43 +01:00
|
|
|
private subscriptions: any[] = [];
|
|
|
|
|
|
|
|
constructor(private route: ActivatedRoute,
|
2019-12-20 12:48:35 +01:00
|
|
|
private propertiesService: EnvironmentSpecificService,
|
|
|
|
private router: Router,
|
|
|
|
private userManagementService: UserManagementService,
|
|
|
|
private layoutService: LayoutService,
|
|
|
|
private stakeholderService: StakeholderService,
|
|
|
|
private cdr: ChangeDetectorRef) {
|
2019-12-21 14:32:43 +01:00
|
|
|
this.subscriptions.push(this.router.events.subscribe(event => {
|
|
|
|
if (event instanceof NavigationEnd) {
|
|
|
|
let r = this.route;
|
|
|
|
while (r.firstChild) {
|
|
|
|
r = r.firstChild;
|
|
|
|
}
|
|
|
|
let params = r.snapshot.params;
|
|
|
|
this.params.next(params);
|
|
|
|
}
|
|
|
|
}));
|
2019-12-20 12:48:35 +01:00
|
|
|
}
|
2019-12-21 14:32:43 +01:00
|
|
|
|
2019-12-20 12:48:35 +01:00
|
|
|
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;
|
2019-12-21 14:32:43 +01:00
|
|
|
this.subscriptions.push(this.params.subscribe( params => {
|
|
|
|
if (params && 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);
|
|
|
|
});
|
2019-12-20 12:48:35 +01:00
|
|
|
}
|
2019-12-21 14:32:43 +01:00
|
|
|
} else {
|
|
|
|
this.stakeholderService.setStakeholder(null);
|
|
|
|
}
|
2019-12-09 16:20:23 +01:00
|
|
|
}));
|
2019-12-20 12:48:35 +01:00
|
|
|
this.subscriptions.push(this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
|
|
|
|
this.user = user;
|
|
|
|
this.buildMenu();
|
|
|
|
}, error => {
|
|
|
|
console.log("App couldn't fetch properties");
|
|
|
|
console.log(error);
|
2019-12-09 16:20:23 +01:00
|
|
|
}));
|
2019-12-20 12:48:35 +01:00
|
|
|
});
|
|
|
|
}
|
2019-11-13 15:19:04 +01:00
|
|
|
|
2019-12-20 12:48:35 +01:00
|
|
|
public ngOnDestroy() {
|
|
|
|
this.subscriptions.forEach(value => {
|
|
|
|
if (value instanceof Subscriber) {
|
|
|
|
value.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-10-24 09:44:29 +02:00
|
|
|
|
2019-12-20 12:48:35 +01:00
|
|
|
public get open() {
|
|
|
|
return this.layoutService.open;
|
|
|
|
}
|
2019-10-24 09:44:29 +02:00
|
|
|
|
2019-12-20 12:48:35 +01:00
|
|
|
public toggleOpen(event = null) {
|
|
|
|
if (!event) {
|
|
|
|
this.layoutService.setOpen(!this.open);
|
|
|
|
} else if (event && event['value'] === true) {
|
|
|
|
this.layoutService.setOpen(false);
|
2019-11-01 19:30:11 +01:00
|
|
|
}
|
2019-12-20 12:48:35 +01:00
|
|
|
}
|
2019-12-12 15:20:03 +01:00
|
|
|
|
|
|
|
|
2019-12-20 12:48:35 +01:00
|
|
|
buildMenu() {
|
|
|
|
this.userMenuItems = [];
|
|
|
|
if (Session.isPortalAdministrator(this.user)) {
|
|
|
|
this.userMenuItems.push(new MenuItem("", "Manage helptexts",
|
|
|
|
((this.properties.environment == "beta") ? "https://beta.admin.connect.openaire.eu" : "https://admin.explore.openaire.eu") + "/dashboard?communityId=openaire", "", true, [], [], {}))
|
2019-12-12 15:20:03 +01:00
|
|
|
|
|
|
|
}
|
2019-12-20 12:48:35 +01:00
|
|
|
if (this.user) {
|
|
|
|
this.userMenuItems.push(new MenuItem("", "User information", "", "/user-info", false, [], [], {}));
|
|
|
|
}
|
|
|
|
if (this.adminMenuItems.length == 0) {
|
|
|
|
//nstructor(id: string, name: string, route: string, items: Item[], icon, open: boolean) {
|
|
|
|
this.adminMenuItems.push(new Item("stakeholders", "Manage Stakeholders", "/admin", [], null, false));
|
|
|
|
this.adminMenuItems.push(new Item("pages", "Pages", "/pages", [], null, false));
|
|
|
|
this.adminMenuItems.push(new Item("monitor", "Monitor", "/portals", [], null, false));
|
|
|
|
this.adminMenuItems.push(new Item("entities", "Entities", "/entities", [], null, false));
|
|
|
|
this.adminMenuItems.push(new Item("helptexts", "Help texts", "/helptexts?communityId=openaire", [], null, false));
|
|
|
|
}
|
|
|
|
}
|
2019-10-24 09:44:29 +02:00
|
|
|
}
|