openaire-library/sharedComponents/navigationBar.component.ts

118 lines
2.9 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/Observable';
import {Session} from '../login/utils/helper.class';
import { ConfigurationService } from '../utils/configuration/configuration.service';
import{MenuItem,RootMenuItem} from './menu';
@Component({
selector: 'navbar',
templateUrl: 'navigationBar.component.html'
})
export class NavigationBarComponent {
@Input() portal:string = "connect";
@Input() onlyTop ;
@Input() logoPath:string = "assets/common-assets/";
@Input() userMenu;
@Input() logInUrl;
@Input() logOutUrl;
@Input() APIUrl;
@Input() communityId;
@Input() cookieDomain;
@Input() userMenuItems:MenuItem[] ;
@Input() menuItems:RootMenuItem [] ;
@Input() community: {id:string, name:string, logoUrl:string};
@Input() showMenu:boolean = true;
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();
});
if(this.userMenu == "true"){
this.userMenu = true;
}
else if(this.userMenu == "false"){
this.userMenu = false;
}
else{
this.userMenu = true;
}
if(this.onlyTop == "true"){
this.onlyTop = true;
}
else if(this.onlyTop == "false"){
this.onlyTop = false;
}
else{
this.onlyTop = false;
}
}
ngOnDestroy(){
this.sub.unsubscribe();
}
initialize(){
if(Session.isLoggedIn() && (Session.isClaimsCurator() || Session.isPortalAdministrator())){
this.isAuthorized = true;
}else {
this.isAuthorized = false;
}
if( this.APIUrl && this.communityId ){
this.config.getCommunityInformation(this.APIUrl, 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"];
}
});
}
}
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;
}
}