117 lines
3.3 KiB
TypeScript
117 lines
3.3 KiB
TypeScript
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:boolean ;
|
|
@Input() logoPath:string = "assets/common-assets/";
|
|
@Input() userMenu:boolean = true;
|
|
@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;
|
|
@Input() homeurl:boolean = true;
|
|
@Input() environment:string = "beta";
|
|
|
|
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.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"];
|
|
|
|
}
|
|
|
|
},
|
|
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);
|
|
}
|
|
}
|