explore-services/explore/src/app/app.component.ts

145 lines
6.9 KiB
TypeScript

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 {Session, User} from './openaireLibrary/login/utils/helper.class';
import {HelperFunctions} from "./openaireLibrary/utils/HelperFunctions.class";
import {UserManagementService} from "./openaireLibrary/services/user-management.service";
import {ConfigurationService} from "./openaireLibrary/utils/configuration/configuration.service";
@Component({
//changeDetection: ChangeDetectionStrategy.Default,
//encapsulation: ViewEncapsulation.Emulated,
selector: 'app-root',
styles: [`
`],
template: `
<navbar *ngIf="properties" [portal]="properties.dashboard" [properties]=properties [onlyTop]=false [user]="user"
[communityId]="properties.adminToolsCommunity" [userMenuItems]=userMenuItems [menuItems]=menuItems></navbar>
<div class="custom-main-content">
<main>
<router-outlet></router-outlet>
</main>
</div>
<cookie-law *ngIf="isClient" position="bottom">
OpenAIRE uses cookies in order to function properly.<br>
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. <a
href="//ec.europa.eu/ipg/basics/legal/cookies/index_en.htm" target="_blank"> Read more <span class="uk-icon">
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="chevron-right"
ratio="1"><polyline fill="none" stroke="#000" stroke-width="1.03" points="7 4 13 10 7 16"></polyline></svg>
</span></a>
</cookie-law>
<bottom *ngIf="isClient && properties" [properties]="properties"></bottom>
`
})
export class AppComponent {
isClient: boolean = false;
clientLoad = 0;
userMenuItems: MenuItem[] = [new MenuItem("", "My profile", "", "", false, [], [], {}),
new MenuItem("", "My links", "", "/myclaims", false, [], ["/myclaims"], {})]
menuItems: RootMenuItem [] = [];
feedbackmail: string;
properties: EnvProperties;
user: User;
constructor(private route: ActivatedRoute, private propertiesService: EnvironmentSpecificService,
private router: Router, private userManagementService: UserManagementService,
private configurationService: ConfigurationService) {
router.events.forEach((event) => {
if (event instanceof NavigationStart) {
// console.log(event.url);
HelperFunctions.scroll();
}
});
}
ngOnInit() {
if (typeof document !== 'undefined') {
try {
this.isClient = true;
} catch (e) {
}
}
this.propertiesService.loadEnvironment()
.then(es => {
this.propertiesService.setEnvProperties(es);
this.properties = this.propertiesService.envSpecific;
this.configurationService.initCommunityInformation(this.properties, this.properties.adminToolsCommunity);
this.feedbackmail = this.properties.feedbackmail;
this.userManagementService.getUserInfo().subscribe(user => {
this.user = user;
this.buildMenu();
});
//console.log(this.properties.loginUrl);
}, error => {
console.log("App couldn't fetch properties");
console.log(error);
});
}
buildMenu() {
//TODO add check for research results route
this.menuItems = [
{
rootItem: new MenuItem("search", "Search", "", "/search/find", false, [], ["/search/find"], {}),
items: [
new MenuItem("", "Research Outcomes", "", "/search/find/research-outcomes", false, [], ["/search/find/research-outcomes"], {qf:true}),
new MenuItem("", "Projects", "", "/search/find/projects/", false, ["project"], ["/search/find/projects"], {}),
new MenuItem("", "Content Providers", "", "/search/find/dataproviders", false, ["datasource"], ["/search/find/dataproviders"], {}),
new MenuItem("", "Organizations", "", "/search/find/organizations/", false, ["organization"], ["/search/find/organizations"], {})
]
},
{
rootItem: new MenuItem("deposit", "Deposit", "", "/participate/deposit/learn-how", false, [], ["/participate/deposit/learn-how"], {}),
//rootItem: new MenuItem("deposit", "Deposit", "", "/participate/deposit/learn-how", false, [], ["/participate/deposit/learn-how"], {}),
items: []
//rootItem: new MenuItem("share", "Share", "", "", false, [], ["/participate/deposit-publications", "/participate/deposit-datasets"], {}),
//items: [new MenuItem("", "Publications", "", "/participate/deposit-publications", false, ["publication"], ["/participate/deposit-publications"], {}),
// new MenuItem("", "Research Data", "", "/participate/deposit-datasets", false, ["dataset"], ["/participate/deposit-datasets"], {})]
},
{
rootItem: new MenuItem("link", "Link", "", "/participate/claim", false, [], ["/participate/claim"], {}),
items: [new MenuItem("", "Start linking", "", "/participate/claim", false, [], ["/participate/claim"], {}),
new MenuItem("", "Learn more", this.properties.claimsInformationLink, "", false, [], [], {})]
},
{
rootItem: new MenuItem("datasources", "Content Providers", "", "", false, ["datasource"], [], {}),
items: [new MenuItem("", "Data Policies", "https://beta.openaire.eu/oa-policies-mandates", "", false, ["datasource"], [""], {}),
new MenuItem("", "Repositories", "", "/search/content-providers", false, ["datasource"], ["/search/content-providers"], {}),
new MenuItem("", "Journals", "", "/search/journals", false, ["datasource"], ["/search/journals"], {}),
new MenuItem("", "Registries", "", "/search/entity-registries", false, ["datasource"], ["/search/entity-registries"], {}),
new MenuItem("", "Browse all", "", "/search/find/dataproviders", false, ["datasource"], ["/search/find/dataproviders"], {})]
}
];
if (Session.isPortalAdministrator(this.user)) {
this.userMenuItems.push(new MenuItem("", "Manage all links", "", "/claims", false, [], ["/claims"], {}));
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, [], [], {}))
} else if (Session.isClaimsCurator(this.user)) {
this.userMenuItems.push(new MenuItem("", "Manage all links", "", "/claims", false, [], ["/claims"], {}));
}
if(this.user) {
this.userMenuItems.push(new MenuItem("", "User information", "", "/user-info", false, [], [], {}));
}
}
}