monitor/src/app/app.component.ts

111 lines
4.7 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 {properties} from "../environments/environment";
@Component({
selector: 'app-root',
template: `
<div class="monitorApp">
<navbar *ngIf="properties && showMenu" portal="monitor" [onlyTop]=false
[userMenuItems]=userMenuItems [menuItems]=menuItems [user]="user"
[showMenu]=showMenu [properties]="properties"></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="properties && isClient && showMenu" [grantAdvance]="false"
[properties]="properties"></bottom>
</div>
`
})
export class AppComponent {
isClient: boolean = false;
userMenuItems: MenuItem[] = [];
menuItems: RootMenuItem [] = [];
bottomMenuItems: MenuItem[] = [];
properties: EnvProperties;
showMenu: boolean = false;
user: User;
constructor(private route: ActivatedRoute, private propertiesService: EnvironmentSpecificService,
private router: Router, private userManagementService: UserManagementService) {
router.events.forEach((event) => {
if (event instanceof NavigationStart) {
HelperFunctions.scroll();
}
});
}
ngOnInit() {
console.log(properties);
this.propertiesService.loadEnvironment()
.then(es => {
this.properties = this.propertiesService.envSpecific;
this.userManagementService.getUserInfo().subscribe(user => {
this.user = user;
this.buildMenu()
if (typeof document !== 'undefined') {
try {
this.isClient = true;
} catch (e) {
}
}
}, error => {
console.log("App couldn't fetch properties");
console.log(error);
});
});
}
public buildMenu() {
this.menuItems = [];
this.menuItems.push({
rootItem: new MenuItem("about", "About", "", "/about/learn-how", false, [], null, {}),
items: []
});
this.menuItems.push({
rootItem: new MenuItem("stakeholders", "Members in Action", "", "/search/find/stakeholders", false, [], null, {}),
items: []
});
this.menuItems.push({
rootItem: new MenuItem("contact-us", "Contact us", "", "/contact-us", false, [], null, {}),
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) || Session.isMonitorCurator(this.user) || Session.isCommunityCurator(this.user)) {
/*this.userMenuItems.push(new MenuItem("", "Manage Helptexts",
((this.properties.environment == "production") ? "https://admin.explore.openaire.eu" : "https://beta.admin.connect.openaire.eu") + "/dashboard?communityId=connect",
"", false, [], [], {}))*/
this.userMenuItems.push(new MenuItem("", "Manage Stakeholders",
properties.baseLink + "/dashboard/admin", "", true, [], [], {}))
}
this.showMenu = true;
}
}