openaire-library/sharedComponents/navigationBar.component.ts

147 lines
4.2 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 ;
@Input() logoPath:string = "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;
/*
<li *ngIf="showDataProviders" class="uk-nav-header uk-parent">
Content Providers
<ul class="uk-nav-sub">
<li><a href="https://beta.openaire.eu/oa-policies-mandates" class="uk-offcanvas-close custom-offcanvas-close" >Data Policies</a></li>
<li><a routerLinkActive="uk-link" routerLink="/search/content-providers" class="uk-offcanvas-close custom-offcanvas-close" >Repositories</a></li>
<li><a routerLinkActive="uk-link" routerLink="/search/journals" class="uk-offcanvas-close custom-offcanvas-close" >Journals</a></li>
<li><a routerLinkActive="uk-link" routerLink="/search/entity-registries" class="uk-offcanvas-close custom-offcanvas-close" >Registries/ Databases</a></li>
<li><a routerLinkActive="uk-link" routerLink="/search/find/dataproviders" class="uk-offcanvas-close custom-offcanvas-close" >Browse all</a></li>
</ul>
</li>*/
public isAuthorized: boolean = false;
sub:any;
isClient:boolean = false;
showEntity ={};
showPage ={};
// showPublications:boolean= false;
// showDatasets:boolean= false;
// showSoftware:boolean=false;
// showProjects:boolean= false;
// showDataProviders:boolean= false;
// showOrganizations:boolean= false;
// showDepositDatasets:boolean= false;
// showDepositPublications:boolean= false;
// showLinking:boolean= false;
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.initialize();
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.isUserValid() && (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){
// console.log(requiredEntity)
// console.log(enabled)
if(typeof enabled[requiredEntity] === "undefined" || enabled[requiredEntity] == false){
return false;
}
}
return true;
}
}