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";
|
2020-10-12 14:54:57 +02:00
|
|
|
import {MenuItem, RootMenuItem} from "./openaireLibrary/sharedComponents/menu";
|
2020-10-23 15:58:16 +02:00
|
|
|
import {Stakeholder, Topic, Visibility} from "./openaireLibrary/monitor/entities/stakeholder";
|
2020-07-10 10:38:52 +02:00
|
|
|
import {LinksResolver} from "./search/links-resolver";
|
2020-10-19 11:07:43 +02:00
|
|
|
import {Header} from "./openaireLibrary/sharedComponents/navigationBar.component";
|
2020-10-23 15:58:16 +02:00
|
|
|
import {arrow_left} from "./openaireLibrary/utils/icons/icons";
|
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-07-06 11:19:01 +02:00
|
|
|
hasMiniMenu: boolean = false;
|
|
|
|
isFrontPage: boolean = false;
|
|
|
|
isViewPublic: boolean = false;
|
|
|
|
sideBarItems: MenuItem[] = [];
|
2020-10-12 14:54:57 +02:00
|
|
|
specialSideBarMenuItem:MenuItem = null;
|
|
|
|
menuItems: RootMenuItem[] = [];
|
2020-10-19 11:07:43 +02:00
|
|
|
menuHeader: Header = { route: "/", url: null, title: "Default menu header", logoUrl: null, logoSmallUrl:null, position:'center', badge: false };
|
2020-07-06 11:19:01 +02:00
|
|
|
userMenuItems: MenuItem[] = [new MenuItem("", "My profile", "", "", false, [], [], {})];
|
2019-12-23 14:54:37 +01:00
|
|
|
adminMenuItems: MenuItem[] = [];
|
2020-07-06 11:19:01 +02:00
|
|
|
stakeholder: Stakeholder = null;
|
|
|
|
activeTopic: Topic = null;
|
2020-08-04 09:57:51 +02:00
|
|
|
innerWidth;
|
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-08-04 09:57:51 +02:00
|
|
|
if(window) {
|
|
|
|
this.innerWidth = window.innerWidth;
|
|
|
|
}
|
2019-12-20 12:48:35 +01:00
|
|
|
this.subscriptions.push(this.layoutService.hasSidebar.subscribe(hasSidebar => {
|
|
|
|
this.hasSidebar = hasSidebar;
|
2020-07-06 11:19:01 +02:00
|
|
|
if (this.hasSidebar === false) {
|
2019-12-24 15:48:27 +01:00
|
|
|
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-07-06 11:19:01 +02:00
|
|
|
this.route.queryParams.subscribe(params => {
|
|
|
|
this.isViewPublic = (params['view'] == 'public');
|
|
|
|
});
|
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;
|
2020-07-06 11:19:01 +02:00
|
|
|
this.subscriptions.push(this.params.subscribe(params => {
|
2020-07-10 10:38:52 +02:00
|
|
|
let isSearch = this.router.url.includes('search');
|
2019-12-21 14:32:43 +01:00
|
|
|
if (params && params['stakeholder']) {
|
|
|
|
if (!this.stakeholderService.stakeholder ||
|
|
|
|
this.stakeholderService.stakeholder.alias !== params['stakeholder']) {
|
|
|
|
this.stakeholderService.getStakeholder(this.properties.monitorServiceAPIURL, params['stakeholder']).subscribe(stakeholder => {
|
2020-07-14 12:01:01 +02:00
|
|
|
if(stakeholder) {
|
|
|
|
this.stakeholder = stakeholder;
|
2020-10-12 14:54:57 +02:00
|
|
|
this.buildMenu();
|
2020-07-14 12:01:01 +02:00
|
|
|
LinksResolver.setProperties(this.stakeholder.alias);
|
|
|
|
this.stakeholderService.setStakeholder(stakeholder);
|
2020-10-12 14:54:57 +02:00
|
|
|
this.layoutService.setSmallScreen((this.innerWidth && this.innerWidth < 1219));
|
2020-08-04 09:57:51 +02:00
|
|
|
this.layoutService.setOpen(!(this.innerWidth && this.innerWidth < 1219));
|
2020-07-14 12:01:01 +02:00
|
|
|
if (isSearch) {
|
|
|
|
this.activeTopic = null;
|
|
|
|
} else if (params && params['topic'] && !this.activeTopic) {
|
2020-10-23 15:58:16 +02:00
|
|
|
this.activeTopic = this.stakeholder.topics.find(topic => topic.alias === decodeURIComponent(params['topic']) && this.isPublicOrIsMember(topic.visibility));
|
2020-07-14 12:01:01 +02:00
|
|
|
} else {
|
2020-10-23 15:58:16 +02:00
|
|
|
this.activeTopic = this.stakeholder.topics.find(topic => this.isPublicOrIsMember(topic.visibility));
|
2020-07-14 12:01:01 +02:00
|
|
|
}
|
|
|
|
this.setSideBar();
|
2020-07-06 11:19:01 +02:00
|
|
|
} else {
|
2020-07-14 12:01:01 +02:00
|
|
|
this.stakeholderService.setStakeholder(null);
|
|
|
|
LinksResolver.resetProperties();
|
|
|
|
this.navigateToError();
|
2020-10-12 14:54:57 +02:00
|
|
|
this.buildMenu();
|
2020-07-06 11:19:01 +02:00
|
|
|
}
|
2020-06-10 16:03:28 +02:00
|
|
|
}, error => {
|
2020-07-06 11:19:01 +02:00
|
|
|
this.stakeholderService.setStakeholder(null);
|
2020-07-10 10:38:52 +02:00
|
|
|
LinksResolver.resetProperties();
|
2020-06-10 16:03:28 +02:00
|
|
|
this.navigateToError();
|
2020-10-12 14:54:57 +02:00
|
|
|
this.buildMenu();
|
2019-12-21 14:32:43 +01:00
|
|
|
});
|
2020-07-06 11:19:01 +02:00
|
|
|
} else {
|
2020-10-12 14:54:57 +02:00
|
|
|
this.buildMenu();
|
2020-07-10 10:38:52 +02:00
|
|
|
if(isSearch) {
|
|
|
|
this.activeTopic = null;
|
|
|
|
} else if (params && params['topic']) {
|
2020-10-23 15:58:16 +02:00
|
|
|
this.activeTopic = this.stakeholder.topics.find(topic => topic.alias === decodeURIComponent(params['topic']) && this.isPublicOrIsMember(topic.visibility));
|
2020-07-06 11:19:01 +02:00
|
|
|
} else {
|
2020-10-23 15:58:16 +02:00
|
|
|
this.activeTopic = this.stakeholder.topics.find(topic => this.isPublicOrIsMember(topic.visibility));
|
2020-07-06 11:19:01 +02:00
|
|
|
}
|
2020-10-12 14:54:57 +02:00
|
|
|
|
2019-12-20 12:48:35 +01:00
|
|
|
}
|
2019-12-21 14:32:43 +01:00
|
|
|
} else {
|
2020-07-10 10:38:52 +02:00
|
|
|
LinksResolver.resetProperties();
|
2019-12-21 14:32:43 +01:00
|
|
|
this.stakeholderService.setStakeholder(null);
|
2020-08-04 09:57:51 +02:00
|
|
|
this.layoutService.setOpen(!(this.innerWidth && this.innerWidth < 1219));
|
2020-07-06 11:19:01 +02:00
|
|
|
this.stakeholder = null;
|
2020-10-12 14:54:57 +02:00
|
|
|
this.buildMenu();
|
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;
|
2020-10-23 15:58:16 +02:00
|
|
|
if(user){
|
|
|
|
this.buildMenu();
|
|
|
|
}
|
2019-12-20 12:48:35 +01:00
|
|
|
}, 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
|
|
|
});
|
|
|
|
}
|
2020-07-06 11:19:01 +02: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() {
|
2020-09-18 11:19:47 +02:00
|
|
|
this.router.navigate(['/error'], {queryParams: {'page': this.properties.baseLink + this.router.url}});
|
2020-06-10 16:03:28 +02:00
|
|
|
}
|
2020-07-06 11:19:01 +02:00
|
|
|
|
2019-12-20 12:48:35 +01:00
|
|
|
public get open() {
|
|
|
|
return this.layoutService.open;
|
|
|
|
}
|
2020-07-06 11:19:01 +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
|
|
|
}
|
2020-07-06 11:19:01 +02:00
|
|
|
|
|
|
|
private setSideBar() {
|
|
|
|
let items: MenuItem[] = [];
|
|
|
|
this.stakeholder.topics.forEach((topic) => {
|
2020-10-23 15:58:16 +02:00
|
|
|
if (this.isPublicOrIsMember(topic.visibility)) {
|
2020-07-06 11:19:01 +02:00
|
|
|
let topicItem: MenuItem = new MenuItem(topic.alias, topic.name, "", (
|
|
|
|
'/' + this.stakeholder.alias + '/' + topic.alias),
|
|
|
|
null, [], [], {});
|
|
|
|
topicItem.icon = topic.icon;
|
|
|
|
items.push(topicItem);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (items.length === 0) {
|
|
|
|
items.push(new MenuItem('noTopics', 'No topics available yet', "", "", false, [], [], {}));
|
|
|
|
}
|
|
|
|
this.sideBarItems = items;
|
|
|
|
}
|
|
|
|
|
2019-12-20 12:48:35 +01:00
|
|
|
buildMenu() {
|
2020-10-12 14:54:57 +02:00
|
|
|
this.menuItems = [];
|
|
|
|
this.adminMenuItems = [];
|
2019-12-20 12:48:35 +01:00
|
|
|
this.userMenuItems = [];
|
2020-10-12 14:54:57 +02:00
|
|
|
if(this.stakeholder) {
|
|
|
|
if (this.isFrontPage) {
|
|
|
|
this.menuHeader = {
|
|
|
|
route: "/" + this.stakeholder.alias,
|
|
|
|
url: null,
|
|
|
|
title: this.stakeholder.name,
|
|
|
|
logoUrl: null,
|
|
|
|
logoSmallUrl: null,
|
|
|
|
position: 'center',
|
|
|
|
badge: false
|
|
|
|
};
|
|
|
|
// if(this.isAdmin()) {
|
|
|
|
this.menuItems.push({
|
|
|
|
rootItem: new MenuItem("manage", "Manage",
|
|
|
|
"", "/admin", false, [], null, {}), items: []
|
|
|
|
});
|
|
|
|
|
|
|
|
// }
|
|
|
|
this.specialSideBarMenuItem = new MenuItem("search", "Search research outcomes", "", this.properties.searchLinkToResults, false, [], null, {})
|
|
|
|
this.specialSideBarMenuItem.icon = '<span uk-icon="search"></span>';
|
|
|
|
|
|
|
|
} else {
|
|
|
|
this.menuHeader = {
|
|
|
|
route: "/admin/" + this.stakeholder.alias,
|
|
|
|
url: null,
|
|
|
|
title: 'Admin - ' + this.stakeholder.name,
|
|
|
|
logoUrl: null,
|
|
|
|
logoSmallUrl: null,
|
|
|
|
position: 'center',
|
|
|
|
badge: false
|
|
|
|
};
|
|
|
|
this.menuItems.push({
|
|
|
|
rootItem: new MenuItem("", "Dashboard",
|
|
|
|
"", '/'+ this.stakeholder.alias+'/', false, [], null, {}), items: []
|
|
|
|
});
|
2020-10-19 18:46:48 +02:00
|
|
|
this.adminMenuItems.push(new MenuItem("general", "General", "", "/admin/"+this.stakeholder.alias, false, [], [], {}, "<i uk-icon=\"image\"></i>"));
|
2020-10-12 14:54:57 +02:00
|
|
|
this.adminMenuItems.push(new MenuItem("indicators", "Indicators", "", "/admin/"+this.stakeholder.alias + '/indicators', false, [], [], {}, "<i uk-icon=\"image\"></i>"));
|
|
|
|
this.adminMenuItems.push(new MenuItem("users", "Users", "", "/admin/"+this.stakeholder.alias+"/users", false, [], [], {}, "<i uk-icon=\"users\"></i>"));
|
|
|
|
this.specialSideBarMenuItem = new MenuItem("back", "Manage profiles", "", "/admin",false, [], null, {});
|
2020-10-23 15:58:16 +02:00
|
|
|
this.specialSideBarMenuItem.icon = '<span class="uk-icon-button uk-icon portal-button " >' + arrow_left.data + '</span>'; // '<span class="uk-icon-button uk-icon portal-button " uk-icon="chevron-left"></span>';
|
2020-10-12 14:54:57 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
this.userMenuItems = [];
|
|
|
|
/* if (Session.isPortalAdministrator(this.user)) {
|
|
|
|
this.userMenuItems.push(new MenuItem("", "Manage helptexts",
|
|
|
|
"", "/helptexts", true, [], [], {communityId:'openaire'}))
|
|
|
|
|
|
|
|
}*/
|
|
|
|
if (this.isAdmin()) {
|
|
|
|
this.userMenuItems.push(new MenuItem("", "Manage profiles",
|
|
|
|
"", "/admin", true, [], [], {}))
|
|
|
|
}
|
|
|
|
if (this.user) {
|
|
|
|
this.userMenuItems.push(new MenuItem("", "User information", "", "/user-info", false, [], [], {}));
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
if(this.isFrontPage || !this.hasAdminMenu){
|
|
|
|
this.menuHeader = { route: null, url: "https://" + (this.properties.environment =='beta'?'beta.':'')+'monitor.openaire.eu', title: "Monitor", logoUrl: 'assets/common-assets/logo-large-monitor.png', logoSmallUrl:"assets/common-assets/logo-small-monitor.png", position:'left' , badge: true };
|
|
|
|
//TODO monitor menu items?
|
|
|
|
|
|
|
|
}else{
|
|
|
|
this.menuHeader = { route: "/", url: null, title: "Monitor Dashboard", logoUrl: null, logoSmallUrl:null, position:'center' , badge: false };
|
|
|
|
this.adminMenuItems = [];
|
|
|
|
this.specialSideBarMenuItem = null;
|
|
|
|
this.adminMenuItems.push(new MenuItem("stakeholders", "Manage profiles", "", "/admin", false, [], [], {}, "<i uk-icon=\"cog\"></i>"));
|
|
|
|
/*let adminOptions = new MenuItem("adminOptions", "Admin Options", "", "", false, [], [], {})
|
|
|
|
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'}));
|
|
|
|
this.adminMenuItems.push(monitorOptions);*/
|
|
|
|
|
|
|
|
}
|
2019-12-20 12:48:35 +01:00
|
|
|
}
|
2020-10-12 14:54:57 +02:00
|
|
|
|
2019-12-20 12:48:35 +01:00
|
|
|
}
|
2020-07-06 11:19:01 +02:00
|
|
|
|
2020-07-07 16:08:47 +02:00
|
|
|
public isAdmin() {
|
2020-07-06 11:19:01 +02:00
|
|
|
return this.user && (Session.isPortalAdministrator(this.user) || Session.isCommunityCurator(this.user) || Session.isMonitorCurator(this.user));
|
|
|
|
}
|
2020-10-23 15:58:16 +02:00
|
|
|
|
|
|
|
public isPublicOrIsMember(visibility: Visibility): boolean {
|
|
|
|
if(visibility == "PRIVATE"){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (visibility == "PUBLIC") {
|
2020-07-06 11:19:01 +02:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
if (this.isViewPublic) { // preview for not members
|
|
|
|
return false;
|
2020-10-23 15:58:16 +02:00
|
|
|
} else if(this.isAdmin()) {
|
2020-07-06 11:19:01 +02:00
|
|
|
// if user is member, return true
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2020-07-13 11:23:04 +02:00
|
|
|
|
|
|
|
createSearchParameters(){
|
|
|
|
if(!this.stakeholder){
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
if(this.stakeholder.type == "funder"){
|
|
|
|
return { "relfunder":encodeURIComponent("\"" + this.stakeholder.index_id + "||"+this.stakeholder.index_name + "||"+this.stakeholder.index_shortName + "\"" )};
|
|
|
|
}else if(this.stakeholder.type == "ri"){
|
|
|
|
// https://beta.explore.openaire.eu/search/find/research-outcomes?f0=q&fv0=&resultbestaccessright=%22Open%20Access%22&community=%22mes%7C%7CEuropean%20Marine%20Science%22&qf=true
|
|
|
|
return { "community":encodeURIComponent("\"" + this.stakeholder.index_id + "||"+this.stakeholder.index_name + "\"" )};
|
|
|
|
}else if(this.stakeholder.type == "organization"){
|
2020-07-14 10:25:59 +02:00
|
|
|
return { "cf":true};
|
2020-07-13 11:23:04 +02:00
|
|
|
}
|
|
|
|
}
|
2019-10-24 09:44:29 +02:00
|
|
|
}
|