[Library | Trunk]: Navigation Bar: add Header interface

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59585 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2020-10-14 09:54:21 +00:00
parent 7c02298552
commit fb84b102c0
1 changed files with 79 additions and 45 deletions

View File

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