diff --git a/sharedComponents/navigationBar.component.ts b/sharedComponents/navigationBar.component.ts index 790d3f25..bea02d15 100644 --- a/sharedComponents/navigationBar.component.ts +++ b/sharedComponents/navigationBar.component.ts @@ -1,21 +1,31 @@ -import {Component, Input} from '@angular/core'; +import {Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges} from '@angular/core'; import {ActivatedRoute, Router} from '@angular/router'; import {Session, User} from '../login/utils/helper.class'; import {ConfigurationService} from '../utils/configuration/configuration.service'; import {MenuItem, RootMenuItem} from './menu'; import {EnvProperties} from '../utils/properties/env-properties'; -import {Stakeholder} from "../monitor/entities/stakeholder"; -import {Subscription} from "rxjs"; +import {Stakeholder} from '../monitor/entities/stakeholder'; +import {Subscription} from 'rxjs'; + +export interface Header { + route?: string, + url?: string, + title: string, + logoUrl: string, + logoSmallUrl: string, + position: 'left' | 'center' | 'right', + badge: boolean +} @Component({ selector: 'navbar', templateUrl: 'navigationBar.component.html' }) -export class NavigationBarComponent { - @Input() portal: string = "connect"; +export class NavigationBarComponent implements OnInit, OnDestroy{ + @Input() portal: string = 'connect'; @Input() dark: boolean = false; @Input() onlyTop: boolean; - @Input() logoPath: string = "assets/common-assets/"; + @Input() logoPath: string = 'assets/common-assets/'; @Input() userMenu: boolean = true; @Input() showHomeMenuItem: boolean = false; @Input() communityId; @@ -24,22 +34,22 @@ export class NavigationBarComponent { @Input() userMenuItems: MenuItem[]; @Input() menuItems: RootMenuItem []; @Input() community: { id: string, name: string, logoUrl: string }; - @Input() header: { route: string, url: string, title: string, logoUrl: string, logoSmallUrl:string, position:'left'|'center'|'right' , badge: boolean }; + @Input() header: Header; @Input() showMenu: boolean = true; @Input() homeurl: boolean = true; @Input() properties: EnvProperties; @Input() user: User; @Input() enableSearch: boolean = false; - @Input() searchRoute: string = "/search/find"; - @Input() searchPlaceHolder: string = "Search for research results"; + @Input() searchRoute: string = '/search/find'; + @Input() searchPlaceHolder: string = 'Search for research results'; @Input() showLogo: boolean = true; @Input() offCanvasFlip: boolean = false; - keyword: string = ""; + keyword: string = ''; - logosrc: string = ""; - logoUrl:string; - logoRoute:string; - logoName:string; + logosrc: string = ''; + logoUrl: string; + logoRoute: string; + logoName: string; public isAuthorized: boolean = false; @@ -59,8 +69,8 @@ export class NavigationBarComponent { ngOnInit() { this.activeRouteEnabled = false; //this.sub = this.route.queryParams.subscribe(params => { - //console.log("params: ",params); - this.initialize(); + //console.log("params: ",params); + this.initialize(); //}); } @@ -71,44 +81,68 @@ export class NavigationBarComponent { } initialize() { - if((['explore','connect','monitor','provide','develop', 'usage-counts', 'graph']).indexOf(this.portal)!=-1){ - this.header = { route: "/", url: null, title: this.portal, logoUrl: this.logoPath + 'logo-large-' + this.portal + '.png', logoSmallUrl:this.logoPath + 'logo-small-' + this.portal + '.png', position:'left', badge:true }; - }else if(this.community){ - this.header = { route: (this.homeurl?"/":null), url: (!this.homeurl?'https://'+(this.properties.environment =='beta'?'beta.':'')+this.community.id+'.openaire.eu':null), title: this.community.name, logoUrl: this.community.logoUrl, logoSmallUrl:this.community.logoUrl, position:'left', badge:true }; - }else if (this.stakeholder){ - this.header = { route:"", url: null, title: this.stakeholder.name, logoUrl: this.stakeholder.logoUrl, logoSmallUrl:this.stakeholder.logoUrl, position:'left', badge:true }; + if ((['explore', 'connect', 'monitor', 'provide', 'develop', 'usage-counts', 'graph']).indexOf(this.portal) != -1) { + this.header = { + route: '/', + url: null, + title: this.portal, + logoUrl: this.logoPath + 'logo-large-' + this.portal + '.png', + logoSmallUrl: this.logoPath + 'logo-small-' + this.portal + '.png', + position: 'left', + badge: true + }; + } else if (this.community) { + this.header = { + route: (this.homeurl ? '/' : null), + url: (!this.homeurl ? 'https://' + (this.properties.environment == 'beta' ? 'beta.' : '') + this.community.id + '.openaire.eu' : null), + title: this.community.name, + logoUrl: this.community.logoUrl, + logoSmallUrl: this.community.logoUrl, + position: 'left', + badge: true + }; + } else if (this.stakeholder) { + this.header = { + route: '', + url: null, + title: this.stakeholder.name, + logoUrl: this.stakeholder.logoUrl, + logoSmallUrl: this.stakeholder.logoUrl, + position: 'left', + badge: true + }; } this.activeRouteEnabled = false; this.isAuthorized = Session.isClaimsCurator(this.user) || Session.isPortalAdministrator(this.user); if (this.properties.adminToolsAPIURL && this.communityId) { //this.config.getCommunityInformation(this.properties, this.communityId).subscribe(data => { this.subs.push(this.config.communityInformationState.subscribe(data => { - if(data) { - for (var i = 0; i < data['entities'].length; i++) { + if (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"]; + 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); - })); + }, + error => { + this.handleError('Error getting community information (e.g. pages,entities) for community with id: ' + this.communityId, error); + })); } - if(!this.community){ - this.logosrc = this.logoPath + "logo-large-"+this.portal+".png"; - this.logoRoute = "/"; - this.logoName = "OpenAIRE"; + if (!this.community) { + this.logosrc = this.logoPath + 'logo-large-' + this.portal + '.png'; + this.logoRoute = '/'; + this.logoName = 'OpenAIRE'; - }else if( this.community){ + } else if (this.community) { this.logosrc = this.community.logoUrl; - if(this.homeurl){ - this.logoRoute = "/"; - }else{ - this.logoUrl = 'https://'+(this.properties.environment =='beta'?'beta.':'')+this.community.id+'.openaire.eu'; + if (this.homeurl) { + this.logoRoute = '/'; + } else { + this.logoUrl = 'https://' + (this.properties.environment == 'beta' ? 'beta.' : '') + this.community.id + '.openaire.eu'; } this.logoName = this.community.name; } @@ -127,7 +161,7 @@ export class NavigationBarComponent { for (let requiredEntity of required) { - if (typeof enabled[requiredEntity] === "undefined" || enabled[requiredEntity] == false) { + if (typeof enabled[requiredEntity] === 'undefined' || enabled[requiredEntity] == false) { return false; } } @@ -141,7 +175,7 @@ export class NavigationBarComponent { var count = required.length; for (let requiredEntity of required) { - if (typeof enabled[requiredEntity] === "undefined" || enabled[requiredEntity] == false) { + if (typeof enabled[requiredEntity] === 'undefined' || enabled[requiredEntity] == false) { count--; } } @@ -149,7 +183,7 @@ export class NavigationBarComponent { } private handleError(message: string, error) { - console.error("NavigationBar (component): " + message, error); + console.error('NavigationBar (component): ' + message, error); } getCurrentRoute() {