import {Component} from '@angular/core';
import {ActivatedRoute, NavigationStart, Router} from '@angular/router';
import {EnvProperties} from './openaireLibrary/utils/properties/env-properties';
import {MenuItem, RootMenuItem} from './openaireLibrary/sharedComponents/menu';
import {EnvironmentSpecificService} from './openaireLibrary/utils/properties/environment-specific.service';
import {CommunitiesService} from "./openaireLibrary/connect/communities/communities.service";
import {Session, User} from './openaireLibrary/login/utils/helper.class';
import {ConnectHelper} from './openaireLibrary/connect/connectHelper';
import {HelperFunctions} from "./openaireLibrary/utils/HelperFunctions.class";
import {UserManagementService} from "./openaireLibrary/services/user-management.service";
import {ConfigurationService} from "./openaireLibrary/utils/configuration/configuration.service";
import {properties} from '../environments/environment';
import {Header} from "./openaireLibrary/sharedComponents/navigationBar.component";
import {Subscriber} from "rxjs";
import {CommunityService} from "./openaireLibrary/connect/community/community.service";
import {CommunityInfo} from "./openaireLibrary/connect/community/communityInfo";
import {StringUtils} from "./openaireLibrary/utils/string-utils.class";
@Component({
//changeDetection: ChangeDetectionStrategy.Default,
//encapsulation: ViewEncapsulation.Emulated,
selector: 'app-root',
styles: [`
`],
template: `
0" [properties]="properties"
[communityId]="communityId">
0 && community"
[URL]="properties.domain + properties.baseLink"
[logoURL]="community.logoUrl" type="home" [searchActionRoute]="properties.searchLinkToResults"
[name]="community.name" [description]="community.description">
OpenAIRE uses cookies in order to function properly.
Cookies are small pieces of data that websites store in your browser to allow us to give you the best browsing
experience possible.
By using the OpenAIRE portal you accept our use of cookies. Read more
`
})
export class AppComponent {
isClient: boolean = false;
userMenuItems: MenuItem[] = [];
menuItems: RootMenuItem [] = [];
bottomMenuItems: MenuItem[] = [];
public community = null;
properties: EnvProperties;
showMenu: boolean = false;
communities = null;
subscriberOfCommunities = false;
user: User;
communityId: string = "";
header: Header;
logoPath: string = 'assets/common-assets/';
subscriptions = [];
// community: {id:string, name:string, logoUrl:string};
constructor(private route: ActivatedRoute, private propertiesService: EnvironmentSpecificService,
private _communitiesService: CommunitiesService,
private router: Router, private userManagementService: UserManagementService,
private configurationService: ConfigurationService, private _communityService: CommunityService) {
this.subscriptions.push(router.events.forEach((event) => {
if (event instanceof NavigationStart) {
HelperFunctions.scroll();
}
}));
}
ngOnDestroy() {
this.subscriptions.forEach(subscription => {
if (subscription instanceof Subscriber) {
subscription.unsubscribe();
}
});
this._communitiesService.clearSubscriptions();
this.userManagementService.clearSubscriptions();
this.configurationService.clearSubscriptions();
this._communityService.clearSubscriptions();
}
ngOnInit() {
this.properties = properties;
this._communitiesService.updateCommunities(this.properties, this.properties.communitiesAPI);
if (typeof document !== 'undefined') {
try {
this.isClient = true;
} catch (e) {
}
}
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
this.user = user;
this.init();
},error => this.init()));
}
get isManager() {
return Session.isCommunityCurator(this.user) || Session.isPortalAdministrator(this.user) || (this.communityId && Session.isManager('community', this.communityId, this.user))
}
private init() {
let communityId: string = "";
if (this.properties.environment == "development") {
this.showMenu = false;
this.subscriptions.push(this.route.queryParams.subscribe(params => {
communityId = (params['communityId']) ? params['communityId'] : ConnectHelper.getCommunityFromDomain(this.properties.domain);
if(communityId) {
this.properties.adminToolsPortalType = "community";
}
this.configurationService.initCommunityInformation(this.properties, (communityId)?communityId:this.properties.adminToolsPortalType);
this.buildMenu(communityId);
}));
} else {
this.showMenu = false;
communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
if(communityId) {
this.properties.adminToolsPortalType = "community";
}
this.configurationService.initCommunityInformation(this.properties, (communityId)?communityId:this.properties.adminToolsPortalType);
this.buildMenu(communityId);
}
this.communityId = communityId;
}
public buildMenu(communityId: string) {
if(communityId) {
if (!this.community || this.community.communityId !== communityId) {
this.subscriptions.push(this._communityService.getCommunity(communityId).subscribe(community => {
if (community && community.status !== 'hidden') {
this.community = {
id: community.communityId,
name: (community.shortTitle) ? community.shortTitle : community.title,
logoUrl: (community.isUpload) ? (properties.utilsService + '/download/' + community.logoUrl):(StringUtils.urlPrefix(community.logoUrl) + community.logoUrl),
description:community.description
};
this.header = {
// url: 'https://' + (this.properties.environment == 'beta' ? 'beta.' : '') + this.community.id + '.openaire.eu',
route: "/",
title: this.community.name,
logoUrl: this.community.logoUrl,
logoSmallUrl: this.community.logoUrl,
position: 'left',
badge: true
};
this.menuItems = [];
this.menuItems.push({
rootItem: new MenuItem("deposit", "Deposit", "", "/participate/deposit/learn-how", false, [], ["/participate/deposit/learn-how"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
items: []
});
this.menuItems.push(
{
rootItem: new MenuItem("link", "Link", "", "/participate/claim", false, [], ["/participate/claim"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
items: [
new MenuItem("", "Start linking", "", "/participate/claim", false, [], ["/participate/claim"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
new MenuItem("", "Learn more", this.properties.claimsInformationLink, "", false, [], [], {})
]
});
this.menuItems.push(
{
rootItem: new MenuItem("search", "Search", "", "/search/find", false, [], ["/search/find", "/search/find/publications", "/search/find/datasets", "/search/find/software", "/search/find/other", "/search/find/projects", "/search/find/dataproviders"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
items: [
new MenuItem("", "Research outcomes", "", "/search/find/research-outcomes", false, [], ["/search/find/research-outcomes"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
new MenuItem("", "Projects", "", "/search/find/projects/", false, ["project"], ["/search/find/projects"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
new MenuItem("", "Content Providers", "", "/search/find/dataproviders", false, ["datasource"], ["/search/find/dataproviders"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
]
});
this.menuItems.push(
{
rootItem: new MenuItem("about", "About", "", "", false, [], [], {}),
items: [
new MenuItem("", "Supporting organizations", "", "/organizations", false, [], ["/organizations"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
new MenuItem("", "Curators", "", "/curators", false, [], ["/curators"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
new MenuItem("", "Sources and methodology", "", "/content", false, [], ["/content"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
new MenuItem("", "National Bulletins", "", "/national-bulletins", false, [], ["/national-bulletins"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
new MenuItem("", "Subjects", "", "/subjects", false, [], ["/subjects"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
new MenuItem("", "Projects and funding Opportunities", "", "/projects", false, [], ["/projects"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
]
});
if (this.isManager) {
this.menuItems.push(
{
rootItem: new MenuItem("manage", "Manage", this.properties.adminPortalURL + '/' + community.communityId, "", false, [], [], {}),
items: []
});
}
this.bottomMenuItems = [
new MenuItem("", "Supporting organizations", "", "/organizations", false, [], ["/organizations"], this.properties.environment != "development" ? {} : {communityId: community.communityId})
];
if (this.properties.showContent) {
this.bottomMenuItems.push(new MenuItem("", "Sources and methodology", "", "/content", false, [], [], {}));
}
if(this.user) {
this.userMenuItems = [ /*new MenuItem("","My profile","","",false,[],[],{}),*/
new MenuItem("", "My links", "", "/myclaims", false, [], ["/myclaims"], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
new MenuItem("", "Invite users", "", "/invite", false, [], [], this.properties.environment != "development" ? {} : {communityId: community.communityId}),
];
if (this.isManager) {
this.userMenuItems.push(new MenuItem("", "Support", "https://openaire-connect.d4science.org/group/openaire-connect-gateway/explore?siteId=172366611", "", false, [], [], {}))
}
}
this.showMenu = true;
} else {
this.navigateToError();
}
}));
} else {
this.showMenu = true;
}
} else {
this.header = {
route: "/",
url: null,
title: 'connect',
logoUrl: this.logoPath + 'logo-large-connect.png',
logoSmallUrl:this.logoPath + 'logo-small-connect.png',
position:'left',
badge:true
};
this.menuItems = [];
this.menuItems.push({
rootItem: new MenuItem("about", "About", "", "/about/learn-how", false, [], ["/about/learn-how"], {}),
items: [
new MenuItem("", "Learn the process", "", "/about/learn-how", false, [], ["/about/learn-in-depth"], {}),
new MenuItem("", "Publications", "", "/publications", false, [], ["/publications"], {}),
new MenuItem("", "Roadmap", "https://trello.com/b/yfzUz0kp/openaire-connect-dashboard", "", false, [], [], {}),
new MenuItem("", "FAQs", "", "/about/faq", false, [], ["/about/faq"], {})
]
});
this.menuItems.push({
rootItem: new MenuItem("communities", "Communities", "", "/search/find/communities", false, [], ['/search/find/communities'], {}),
items: []
});
this.menuItems.push({
rootItem: new MenuItem("contact-us", "Contact us", "", "/contact-us", false, [], ['/contact-us'], {}),
items: []
});
this.bottomMenuItems = [
new MenuItem("", "About", "https://beta.openaire.eu/project-factsheets", "", false, [], [], {}),
new MenuItem("", "News - Events", "https://beta.openaire.eu/news-events", "", false, [], [], {}),
new MenuItem("", "Blog", "https://blogs.openaire.eu/", "", false, [], [], {}),
new MenuItem("", "Contact us", "https://beta.openaire.eu/contact-us", "", false, [], [], {})
];
this.userMenuItems = [];
if (Session.isPortalAdministrator(this.user)) {
this.userMenuItems.push(new MenuItem("", "Manage Helptexts",
properties.adminPortalURL + "/" + communityId + '/pages',
"", false, [], [], {}))
}
if (this.user) {
this.userMenuItems.push(new MenuItem("my-communities", "My Communities", "",
"/myCommunities", false, [], [], {}));
}
this.showMenu = true;
}
}
private navigateToError() {
this.router.navigate(['/error'], {queryParams: {'page': this.properties.baseLink + this.router.url}});
}
}