openaire-library/sharedComponents/navigationBar.component.ts

126 lines
3.7 KiB
TypeScript
Raw Normal View History

import { Component, Input } from '@angular/core';
// import 'rxjs/Rx';
import {ActivatedRoute, Router} from '@angular/router';
import {Observable} from 'rxjs';
import {Session} from '../login/utils/helper.class';
import { ConfigurationService } from '../utils/configuration/configuration.service';
import{MenuItem,RootMenuItem} from './menu';
import {EnvProperties} from "../utils/properties/env-properties";
@Component({
selector: 'navbar',
templateUrl: 'navigationBar.component.html'
})
export class NavigationBarComponent {
// [APIUrl]="properties.adminToolsAPIURL" [logOutUrl]="properties.logoutUrl" [cookieDomain]="properties.cookieDomain"
@Input() portal:string = "connect";
@Input() onlyTop:boolean ;
@Input() logoPath:string = "assets/common-assets/";
@Input() userMenu:boolean = true;
// @Input() logOutUrl;
// @Input() APIUrl;
@Input() communityId;
@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() enableSearch:boolean = false;
@Input() searchRoute:string = "/search/find";
@Input() searchPlaceHolder:string = "Search for research results";
keyword:string = "";
public isAuthorized: boolean = false;
sub:any;
isClient:boolean = false;
showEntity ={};
showPage ={};
specialAnnouncementContent:string= null;
constructor( private router: Router, private route: ActivatedRoute, private config: ConfigurationService) {
}
ngOnInit() {
//console.log(this.menuItems);
if (typeof document !== 'undefined') {
try{
this.isClient = true;
}catch (e) {
}
}
this.sub = this.route.queryParams.subscribe(params => {
this.initialize();
});
}
ngOnDestroy(){
this.sub.unsubscribe();
}
initialize(){
if(Session.isLoggedIn() && (Session.isClaimsCurator() || Session.isPortalAdministrator())){
this.isAuthorized = true;
}else {
this.isAuthorized = false;
}
if( this.properties.adminToolsAPIURL && this.communityId ){
this.config.getCommunityInformation(this.properties, this.communityId ).subscribe(data => {
for(var i=0; i< data['entities'].length; i++){
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"];
}
},
error => {
this.handleError("Error getting community information (e.g. pages,entities) for community with id: "+this.communityId, error);
});
}
}
onClick(id: string) {
var el: HTMLElement = document.getElementById(id);
el.classList.remove('uk-open');
}
isEnabled(required, enabled){
if(!required ){
return true;
}
for(let requiredEntity of required){
if(typeof enabled[requiredEntity] === "undefined" || enabled[requiredEntity] == false){
return false;
}
}
return true;
}
isAtleastOneEnabled(required, enabled){
if(!required ||required.length == 0){
return true;
}
var count = required.length;
for(let requiredEntity of required){
if(typeof enabled[requiredEntity] === "undefined" || enabled[requiredEntity] == false){
count --;
}
}
return (count > 0)?true:false;
}
private handleError(message: string, error) {
console.error("NavigationBar (component): "+message, error);
}
getCurrentRoute(){
return this.router.url.split('?')[0];
}
}