2019-07-01 16:22:11 +02:00
|
|
|
import {Component, Input} from '@angular/core';
|
2017-12-19 13:53:46 +01:00
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
2019-09-13 09:01:19 +02:00
|
|
|
import {Session, User} from '../login/utils/helper.class';
|
2019-07-01 16:22:11 +02:00
|
|
|
import {ConfigurationService} from '../utils/configuration/configuration.service';
|
|
|
|
import {MenuItem, RootMenuItem} from './menu';
|
|
|
|
import {EnvProperties} from '../utils/properties/env-properties';
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
@Component({
|
|
|
|
selector: 'navbar',
|
|
|
|
templateUrl: 'navigationBar.component.html'
|
|
|
|
})
|
|
|
|
export class NavigationBarComponent {
|
2019-09-13 09:01:19 +02:00
|
|
|
@Input() portal: string = "connect";
|
|
|
|
@Input() onlyTop: boolean;
|
|
|
|
@Input() logoPath: string = "assets/common-assets/";
|
|
|
|
@Input() userMenu: boolean = true;
|
|
|
|
@Input() showHomeMenuItem: boolean = false;
|
2018-02-05 14:14:59 +01:00
|
|
|
@Input() communityId;
|
2019-09-13 09:01:19 +02:00
|
|
|
@Input() showCommunityName: boolean = false;
|
|
|
|
@Input() userMenuItems: MenuItem[];
|
|
|
|
@Input() menuItems: RootMenuItem [];
|
|
|
|
@Input() community: { id: string, name: string, logoUrl: string };
|
|
|
|
@Input() showMenu: boolean = true;
|
|
|
|
@Input() homeurl: boolean = true;
|
|
|
|
@Input() properties: EnvProperties;
|
|
|
|
@Input() user: User;
|
|
|
|
@Input() enableSearch: boolean = false;
|
|
|
|
@Input() searchRoute: string = "/search/find";
|
|
|
|
@Input() searchPlaceHolder: string = "Search for research results";
|
|
|
|
keyword: string = "";
|
2019-06-20 15:29:43 +02:00
|
|
|
|
2018-01-11 16:20:43 +01:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
public isAuthorized: boolean = false;
|
2019-09-13 09:01:19 +02:00
|
|
|
sub: any;
|
|
|
|
isClient: boolean = false;
|
|
|
|
showEntity = {};
|
|
|
|
showPage = {};
|
|
|
|
specialAnnouncementContent: string = null;
|
2019-06-25 15:26:24 +02:00
|
|
|
activeRouteEnabled = false;
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
|
2019-09-13 09:01:19 +02:00
|
|
|
constructor(private router: Router,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private config: ConfigurationService) {
|
2018-02-05 14:14:59 +01:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
ngOnInit() {
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.log(this.menuItems);
|
2017-12-19 13:53:46 +01:00
|
|
|
if (typeof document !== 'undefined') {
|
2019-09-13 09:01:19 +02:00
|
|
|
try {
|
2017-12-19 13:53:46 +01:00
|
|
|
this.isClient = true;
|
2019-09-13 09:01:19 +02:00
|
|
|
} catch (e) {
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
}
|
2019-06-25 15:26:24 +02:00
|
|
|
this.activeRouteEnabled = false;
|
2019-09-13 09:01:19 +02:00
|
|
|
this.sub = this.route.queryParams.subscribe(params => {
|
2017-12-19 13:53:46 +01:00
|
|
|
this.initialize();
|
|
|
|
});
|
2018-01-11 11:55:54 +01:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-09-13 09:01:19 +02:00
|
|
|
|
|
|
|
ngOnDestroy() {
|
2017-12-19 13:53:46 +01:00
|
|
|
this.sub.unsubscribe();
|
|
|
|
}
|
|
|
|
|
2019-09-13 09:01:19 +02:00
|
|
|
initialize() {
|
|
|
|
this.activeRouteEnabled = false;
|
|
|
|
this.isAuthorized = Session.isClaimsCurator(this.user) || Session.isPortalAdministrator(this.user);
|
|
|
|
if (this.properties.adminToolsAPIURL && this.communityId) {
|
|
|
|
this.config.getCommunityInformation(this.properties, this.communityId).subscribe(data => {
|
|
|
|
for (var i = 0; i < data['entities'].length; i++) {
|
2018-02-05 14:14:59 +01:00
|
|
|
|
2019-09-13 09:01:19 +02:00
|
|
|
this.showEntity["" + data['entities'][i]["pid"] + ""] = data['entities'][i]["isEnabled"];
|
|
|
|
}
|
|
|
|
for (var i = 0; i < data['pages'].length; i++) {
|
|
|
|
this.showPage[data['pages'][i]["route"]] = data['pages'][i]["isEnabled"];
|
2018-02-05 14:14:59 +01:00
|
|
|
|
2019-09-13 09:01:19 +02:00
|
|
|
}
|
2018-02-05 14:14:59 +01:00
|
|
|
|
2019-09-13 09:01:19 +02:00
|
|
|
},
|
|
|
|
error => {
|
|
|
|
this.handleError("Error getting community information (e.g. pages,entities) for community with id: " + this.communityId, error);
|
|
|
|
});
|
2018-02-05 16:13:55 +01:00
|
|
|
}
|
2018-02-05 14:14:59 +01:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-09-13 09:01:19 +02:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
onClick(id: string) {
|
2019-09-13 09:01:19 +02:00
|
|
|
var el: HTMLElement = document.getElementById(id);
|
|
|
|
el.classList.remove('uk-open');
|
2018-12-07 12:07:19 +01:00
|
|
|
}
|
2018-02-05 14:14:59 +01:00
|
|
|
|
2019-09-13 09:01:19 +02:00
|
|
|
isEnabled(required, enabled) {
|
|
|
|
if (!required) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-02-05 14:14:59 +01:00
|
|
|
|
2019-09-13 09:01:19 +02:00
|
|
|
|
|
|
|
for (let requiredEntity of required) {
|
|
|
|
if (typeof enabled[requiredEntity] === "undefined" || enabled[requiredEntity] == false) {
|
|
|
|
return false;
|
2018-02-05 14:14:59 +01:00
|
|
|
}
|
2019-09-13 09:01:19 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
isAtleastOneEnabled(required, enabled) {
|
|
|
|
if (!required || required.length == 0) {
|
2018-02-05 14:14:59 +01:00
|
|
|
return true;
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-09-13 09:01:19 +02:00
|
|
|
var count = required.length;
|
|
|
|
for (let requiredEntity of required) {
|
|
|
|
if (typeof enabled[requiredEntity] === "undefined" || enabled[requiredEntity] == false) {
|
|
|
|
count--;
|
2018-12-07 12:07:19 +01:00
|
|
|
}
|
|
|
|
}
|
2019-09-13 09:01:19 +02:00
|
|
|
return (count > 0) ? true : false;
|
|
|
|
}
|
2019-02-18 15:00:43 +01:00
|
|
|
|
2019-09-13 09:01:19 +02:00
|
|
|
private handleError(message: string, error) {
|
|
|
|
console.error("NavigationBar (component): " + message, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
getCurrentRoute() {
|
2019-06-20 15:29:43 +02:00
|
|
|
return this.router.url.split('?')[0];
|
2019-09-13 09:01:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
isTheActiveMenu(menu: RootMenuItem): boolean {
|
|
|
|
let currentRoute = this.getCurrentRoute();
|
|
|
|
if (!menu.rootItem.markAsActive) {
|
|
|
|
return false;
|
2019-06-20 15:29:43 +02:00
|
|
|
}
|
2019-09-13 09:01:19 +02:00
|
|
|
if (currentRoute == menu.rootItem.route) {
|
|
|
|
this.activeRouteEnabled = true;
|
|
|
|
return true;
|
|
|
|
} else if (menu.items.length > 0) {
|
|
|
|
for (let menuItem of menu.items) {
|
|
|
|
if (menuItem.route == currentRoute) {
|
|
|
|
this.activeRouteEnabled = true;
|
|
|
|
return true;
|
2019-06-25 15:26:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-09-13 09:01:19 +02:00
|
|
|
return false;
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|