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-07-06 11:19:01 +02:00
|
|
|
import {Stakeholder, Topic} from "./openaireLibrary/monitor/entities/stakeholder";
|
2020-07-10 10:38:52 +02:00
|
|
|
import {LinksResolver} from "./search/links-resolver";
|
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[] = [];
|
|
|
|
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;
|
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;
|
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 => {
|
|
|
|
this.stakeholderService.setStakeholder(stakeholder);
|
|
|
|
this.layoutService.setOpen(true);
|
2020-07-06 11:19:01 +02:00
|
|
|
this.stakeholder = stakeholder;
|
2020-07-10 10:38:52 +02:00
|
|
|
LinksResolver.setProperties(this.stakeholder.alias);
|
|
|
|
if(isSearch) {
|
|
|
|
this.activeTopic = null;
|
|
|
|
} else if (params && params['topic'] && !this.activeTopic) {
|
2020-07-06 11:19:01 +02:00
|
|
|
this.activeTopic = this.stakeholder.topics.find(topic => topic.alias === decodeURIComponent(params['topic']) && this.isPublicOrIsMember(topic.isPublic) && topic.isActive);
|
|
|
|
} else {
|
|
|
|
this.activeTopic = this.stakeholder.topics.find(topic => this.isPublicOrIsMember(topic.isPublic) && topic.isActive);
|
|
|
|
}
|
|
|
|
this.setSideBar();
|
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();
|
2019-12-21 14:32:43 +01:00
|
|
|
});
|
2020-07-06 11:19:01 +02:00
|
|
|
} else {
|
2020-07-10 10:38:52 +02:00
|
|
|
if(isSearch) {
|
|
|
|
this.activeTopic = null;
|
|
|
|
} else if (params && params['topic']) {
|
2020-07-06 11:19:01 +02:00
|
|
|
this.activeTopic = this.stakeholder.topics.find(topic => topic.alias === decodeURIComponent(params['topic']) && this.isPublicOrIsMember(topic.isPublic) && topic.isActive);
|
|
|
|
} else {
|
|
|
|
this.activeTopic = this.stakeholder.topics.find(topic => this.isPublicOrIsMember(topic.isPublic) && topic.isActive);
|
|
|
|
}
|
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);
|
2019-12-23 16:10:27 +01:00
|
|
|
this.layoutService.setOpen(true);
|
2020-07-06 11:19:01 +02: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
|
|
|
});
|
|
|
|
}
|
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() {
|
|
|
|
this.router.navigate(['/error'], {queryParams: {'page': this.router.url}});
|
|
|
|
}
|
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) => {
|
|
|
|
if (this.isPublicOrIsMember(topic.isPublic) && topic.isActive) {
|
|
|
|
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() {
|
|
|
|
this.userMenuItems = [];
|
2020-07-06 11:19:01 +02:00
|
|
|
/* if (Session.isPortalAdministrator(this.user)) {
|
|
|
|
this.userMenuItems.push(new MenuItem("", "Manage helptexts",
|
|
|
|
"", "/helptexts", true, [], [], {communityId:'openaire'}))
|
|
|
|
|
|
|
|
}*/
|
|
|
|
if (this.isAdmin()) {
|
2020-06-25 10:10:42 +02:00
|
|
|
this.userMenuItems.push(new MenuItem("", "Manage profiles",
|
2020-06-04 13:30:26 +02:00
|
|
|
"", "/admin", true, [], [], {}))
|
2020-07-06 11:19:01 +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-25 10:10:42 +02:00
|
|
|
this.adminMenuItems.push(new MenuItem("stakeholders", "Manage profiles", "", "/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
|
|
|
}
|
|
|
|
}
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
public isPublicOrIsMember(isPublic: boolean): boolean {
|
|
|
|
if (isPublic) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
if (this.isViewPublic) { // preview for not members
|
|
|
|
return false;
|
|
|
|
} else if (this.isAdmin()) {
|
|
|
|
// 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
|
|
|
}
|