2018-01-11 11:55:54 +01:00
|
|
|
import { Component, Input } from '@angular/core';
|
2017-12-19 13:53:46 +01:00
|
|
|
// import 'rxjs/Rx';
|
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
2019-06-03 15:20:36 +02:00
|
|
|
import {Observable} from 'rxjs';
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
import {Session} from '../login/utils/helper.class';
|
|
|
|
import { ConfigurationService } from '../utils/configuration/configuration.service';
|
2018-02-05 14:14:59 +01:00
|
|
|
import{MenuItem,RootMenuItem} from './menu';
|
2019-06-05 15:33:18 +02:00
|
|
|
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-06-05 15:33:18 +02:00
|
|
|
// [APIUrl]="properties.adminToolsAPIURL" [logOutUrl]="properties.logoutUrl" [cookieDomain]="properties.cookieDomain"
|
2018-01-11 11:55:54 +01:00
|
|
|
@Input() portal:string = "connect";
|
2018-12-07 12:07:19 +01:00
|
|
|
@Input() onlyTop:boolean ;
|
2018-05-11 13:33:50 +02:00
|
|
|
@Input() logoPath:string = "assets/common-assets/";
|
2018-12-07 12:07:19 +01:00
|
|
|
@Input() userMenu:boolean = true;
|
2019-06-05 15:33:18 +02:00
|
|
|
// @Input() logOutUrl;
|
|
|
|
// @Input() APIUrl;
|
2018-02-05 14:14:59 +01:00
|
|
|
@Input() communityId;
|
2019-06-12 16:13:56 +02:00
|
|
|
@Input() showCommunityName:boolean = false;
|
2018-02-05 14:14:59 +01:00
|
|
|
@Input() userMenuItems:MenuItem[] ;
|
|
|
|
@Input() menuItems:RootMenuItem [] ;
|
|
|
|
@Input() community: {id:string, name:string, logoUrl:string};
|
2018-03-16 09:56:42 +01:00
|
|
|
@Input() showMenu:boolean = true;
|
2018-12-07 13:36:19 +01:00
|
|
|
@Input() homeurl:boolean = true;
|
2019-06-05 15:33:18 +02:00
|
|
|
@Input() properties:EnvProperties;
|
2018-01-11 16:20:43 +01:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
public isAuthorized: boolean = false;
|
|
|
|
sub:any;
|
|
|
|
isClient:boolean = false;
|
2018-02-05 14:14:59 +01:00
|
|
|
showEntity ={};
|
|
|
|
showPage ={};
|
2017-12-19 13:53:46 +01:00
|
|
|
specialAnnouncementContent:string= null;
|
|
|
|
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
constructor( private router: Router, private route: ActivatedRoute, private config: ConfigurationService) {
|
|
|
|
}
|
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') {
|
|
|
|
try{
|
|
|
|
this.isClient = true;
|
|
|
|
}catch (e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.sub = this.route.queryParams.subscribe(params => {
|
|
|
|
this.initialize();
|
|
|
|
});
|
2018-01-11 11:55:54 +01:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
ngOnDestroy(){
|
|
|
|
this.sub.unsubscribe();
|
|
|
|
}
|
|
|
|
initialize(){
|
2018-06-12 13:15:42 +02:00
|
|
|
if(Session.isLoggedIn() && (Session.isClaimsCurator() || Session.isPortalAdministrator())){
|
2017-12-19 13:53:46 +01:00
|
|
|
this.isAuthorized = true;
|
|
|
|
}else {
|
|
|
|
this.isAuthorized = false;
|
|
|
|
}
|
|
|
|
|
2019-06-05 15:33:18 +02:00
|
|
|
if( this.properties.adminToolsAPIURL && this.communityId ){
|
|
|
|
this.config.getCommunityInformation(this.properties, this.communityId ).subscribe(data => {
|
2019-06-03 15:20:36 +02:00
|
|
|
for(var i=0; i< data['entities'].length; i++){
|
2018-02-05 14:14:59 +01:00
|
|
|
|
2019-06-03 15:20:36 +02:00
|
|
|
this.showEntity[""+data['entities'][i]["pid"]+""] = data['entities'][i]["isEnabled"];
|
2018-02-05 14:14:59 +01:00
|
|
|
}
|
2019-06-03 15:20:36 +02:00
|
|
|
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-02-18 15:00:43 +01:00
|
|
|
},
|
|
|
|
error => {
|
|
|
|
this.handleError("Error getting community information (e.g. pages,entities) for community with id: "+this.communityId, error);
|
2018-02-05 14:14:59 +01:00
|
|
|
});
|
2018-02-05 16:13:55 +01:00
|
|
|
}
|
2018-02-05 14:14:59 +01:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
onClick(id: string) {
|
|
|
|
var el: HTMLElement = document.getElementById(id);
|
|
|
|
el.classList.remove('uk-open');
|
2018-12-07 12:07:19 +01:00
|
|
|
}
|
|
|
|
isEnabled(required, enabled){
|
2018-02-05 14:14:59 +01:00
|
|
|
if(!required ){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for(let requiredEntity of required){
|
|
|
|
if(typeof enabled[requiredEntity] === "undefined" || enabled[requiredEntity] == false){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2018-12-07 12:07:19 +01:00
|
|
|
isAtleastOneEnabled(required, enabled){
|
|
|
|
if(!required ||required.length == 0){
|
|
|
|
return true;
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2018-12-07 12:07:19 +01:00
|
|
|
var count = required.length;
|
|
|
|
for(let requiredEntity of required){
|
|
|
|
if(typeof enabled[requiredEntity] === "undefined" || enabled[requiredEntity] == false){
|
|
|
|
count --;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (count > 0)?true:false;
|
|
|
|
}
|
2019-02-18 15:00:43 +01:00
|
|
|
|
|
|
|
private handleError(message: string, error) {
|
|
|
|
console.error("NavigationBar (component): "+message, error);
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|