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";
|
2020-06-03 15:44:03 +02:00
|
|
|
import {StakeholderService} from "./openaireLibrary/monitor/services/stakeholder.service";
|
2019-12-21 14:32:43 +01:00
|
|
|
import {BehaviorSubject, Subscriber} from "rxjs";
|
2019-12-23 14:54:37 +01:00
|
|
|
import {LayoutService} from "./openaireLibrary/dashboard/sharedComponents/sidebar/layout.service";
|
2019-12-12 15:20:03 +01:00
|
|
|
import {MenuItem} from "./openaireLibrary/sharedComponents/menu";
|
2020-06-03 15:44:03 +02:00
|
|
|
import {Stakeholder} from "./openaireLibrary/monitor/entities/stakeholder";
|
2020-06-11 17:52:41 +02:00
|
|
|
import {properties} from "../environments/environment";
|
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-23 14:54:37 +01:00
|
|
|
hasAdminMenu: boolean = false;
|
2020-06-04 13:30:26 +02:00
|
|
|
hasMiniMenu:boolean = false;
|
|
|
|
isFrontPage:boolean = false;
|
2019-12-21 14:32:43 +01:00
|
|
|
userMenuItems: MenuItem[] = [];
|
2019-12-23 14:54:37 +01:00
|
|
|
adminMenuItems: MenuItem[] = [];
|
2020-01-09 15:31:55 +01:00
|
|
|
stakeHolder:Stakeholder = null;
|
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() {
|
2020-06-11 17:52:41 +02:00
|
|
|
console.log(properties);
|
2019-12-20 12:48:35 +01:00
|
|
|
this.subscriptions.push(this.layoutService.hasSidebar.subscribe(hasSidebar => {
|
|
|
|
this.hasSidebar = hasSidebar;
|
2019-12-24 15:48:27 +01:00
|
|
|
if(this.hasSidebar === false) {
|
|
|
|
this.layoutService.setOpen(false);
|
|
|
|
}
|
2019-12-20 12:48:35 +01:00
|
|
|
this.cdr.detectChanges();
|
|
|
|
}));
|
|
|
|
this.subscriptions.push(this.layoutService.hasHeader.subscribe(hasHeader => {
|
|
|
|
this.hasHeader = hasHeader;
|
|
|
|
this.cdr.detectChanges();
|
|
|
|
}));
|
2019-12-23 14:54:37 +01:00
|
|
|
this.subscriptions.push(this.layoutService.hasAdminMenu.subscribe(hasAdminMenu => {
|
|
|
|
this.hasAdminMenu = hasAdminMenu;
|
|
|
|
this.cdr.detectChanges();
|
|
|
|
}));
|
2020-06-04 13:30:26 +02:00
|
|
|
this.subscriptions.push(this.layoutService.hasMiniMenu.subscribe(hasMiniMenu => {
|
|
|
|
this.hasMiniMenu = hasMiniMenu;
|
|
|
|
this.cdr.detectChanges();
|
|
|
|
}));
|
|
|
|
this.subscriptions.push(this.layoutService.isFrontPage.subscribe(isFrontPage => {
|
|
|
|
this.isFrontPage = isFrontPage;
|
|
|
|
this.cdr.detectChanges();
|
|
|
|
}));
|
2020-01-08 12:00:50 +01:00
|
|
|
this.layoutService.setOpen(false);
|
2019-12-20 12:48:35 +01:00
|
|
|
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);
|
2020-01-09 15:31:55 +01:00
|
|
|
this.stakeHolder = stakeholder;
|
2020-06-10 16:03:28 +02:00
|
|
|
}, error => {
|
|
|
|
this.navigateToError();
|
2019-12-21 14:32:43 +01:00
|
|
|
});
|
2019-12-20 12:48:35 +01:00
|
|
|
}
|
2019-12-21 14:32:43 +01:00
|
|
|
} else {
|
|
|
|
this.stakeholderService.setStakeholder(null);
|
2019-12-23 16:10:27 +01:00
|
|
|
this.layoutService.setOpen(true);
|
2020-01-09 15:31:55 +01:00
|
|
|
this.stakeHolder = null;
|
2019-12-21 14:32:43 +01:00
|
|
|
}
|
2019-12-09 16:20:23 +01:00
|
|
|
}));
|
2019-12-23 16:10:27 +01:00
|
|
|
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
|
2019-12-20 12:48:35 +01:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-06-10 16:03:28 +02:00
|
|
|
|
|
|
|
private navigateToError() {
|
|
|
|
this.router.navigate(['/error'], {queryParams: {'page': this.router.url}});
|
|
|
|
}
|
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-24 15:48:27 +01:00
|
|
|
public toggleOpen(event: MouseEvent) {
|
|
|
|
event.preventDefault();
|
|
|
|
this.layoutService.setOpen(!this.open);
|
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 = [];
|
2020-06-02 14:45:08 +02:00
|
|
|
/* if (Session.isPortalAdministrator(this.user)) {
|
2019-12-20 12:48:35 +01:00
|
|
|
this.userMenuItems.push(new MenuItem("", "Manage helptexts",
|
2020-01-09 15:31:55 +01:00
|
|
|
"", "/helptexts", true, [], [], {communityId:'openaire'}))
|
2019-12-12 15:20:03 +01:00
|
|
|
|
2020-06-02 14:45:08 +02:00
|
|
|
}*/
|
|
|
|
if (Session.isPortalAdministrator(this.user) || Session.isMonitorCurator(this.user) || Session.isCommunityCurator(this.user)) {
|
|
|
|
this.userMenuItems.push(new MenuItem("", "Manage Stakeholders",
|
2020-06-04 13:30:26 +02:00
|
|
|
"", "/admin", true, [], [], {}))
|
2020-06-02 14:45:08 +02:00
|
|
|
|
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) {
|
2020-06-12 12:46:11 +02:00
|
|
|
this.adminMenuItems.push(new MenuItem("stakeholders", "Manage Stakeholders", "", "/admin", false, [], [], {}, "<i class=\"material-icons md-24\">settings</i>"));
|
2020-05-13 10:46:22 +02:00
|
|
|
/*let adminOptions = new MenuItem("adminOptions", "Admin Options", "", "", false, [], [], {})
|
2019-12-23 14:54:37 +01:00
|
|
|
adminOptions.items.push(new MenuItem("pages", "Pages", "", "/pages", false, [], [], {}));
|
|
|
|
adminOptions.items.push(new MenuItem("portals", "Portals", "", "/portals", false, [], [], {}));
|
|
|
|
adminOptions.items.push(new MenuItem("entities", "Entities", "", "/entities", false, [], [], {}));
|
|
|
|
adminOptions.items.push(new MenuItem("classes", "Class help texts", "", "/classes", false, [], [], {}));
|
|
|
|
this.adminMenuItems.push(adminOptions);
|
|
|
|
let monitorOptions = new MenuItem("monitorOptions", "Monitor Options", "", "", false, [], [], {})
|
|
|
|
monitorOptions.items.push(new MenuItem("pages", "Pages", "", "/pages", false, [], [], {communityId: 'openaire'}));
|
|
|
|
monitorOptions.items.push(new MenuItem("entities", "Entities", "", "/entities", false, [], [], {communityId: 'openaire'}));
|
|
|
|
monitorOptions.items.push(new MenuItem("classes", "Class help texts", "", "/classContents", false, [], [], {communityId: 'openaire'}));
|
|
|
|
monitorOptions.items.push(new MenuItem("helptexts", "Help texts", "", "/helptexts", false, [], [], {communityId: 'openaire'}));
|
2020-05-13 10:46:22 +02:00
|
|
|
this.adminMenuItems.push(monitorOptions);*/
|
2019-12-20 12:48:35 +01:00
|
|
|
}
|
|
|
|
}
|
2019-10-24 09:44:29 +02:00
|
|
|
}
|