openaire-library/sharedComponents/navigationBar.component.ts

193 lines
6.3 KiB
TypeScript
Raw Normal View History

import {Component, Input, OnDestroy, OnInit} 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 {Subscription} from 'rxjs';
import {HelpContentService} from '../services/help-content.service';
import {properties} from "../../../environments/environment";
2022-03-28 10:40:21 +02:00
import {LayoutService} from "../dashboard/sharedComponents/sidebar/layout.service";
2022-02-28 13:38:26 +01:00
declare var UIkit;
export interface Header {
route?: string,
url?: string,
title: string,
logoUrl: string,
logoSmallUrl: string,
position: 'left' | 'center' | 'right',
badge: boolean
stickyAnimation?: boolean
menuPosition?: 'center' | 'right'
}
@Component({
selector: 'navbar',
templateUrl: 'navigationBar.component.html'
})
export class NavigationBarComponent implements OnInit, OnDestroy {
@Input() portal: string = 'connect';
@Input() dark: boolean = false;
@Input() onlyTop: boolean = false;
@Input() logoPath: string = 'assets/common-assets/';
@Input() userMenu: boolean = true;
@Input() showHomeMenuItem: boolean = false;
@Input() communityId;
@Input() showCommunityName: boolean = false;
@Input() userMenuItems: MenuItem[];
@Input() menuItems: RootMenuItem [];
@Input() header: Header;
@Input() showMenu: boolean = true;
@Input() homeurl: boolean = true;
@Input() properties: EnvProperties = properties;
@Input() user: User;
@Input() enableSearch: boolean = false;
@Input() searchRoute: string = '/search/find';
@Input() searchPlaceHolder: string = 'Search for research results';
@Input() showLogo: boolean = true;
@Input() offCanvasFlip: boolean = false;
keyword: string = '';
public isAuthorized: boolean = false;
subs: Subscription[] = [];
showEntity = {};
showPage = {};
public additionalMenuItems: MenuItem[] = [];
public featuredMenuItems: MenuItem[] = [];
constructor(private router: Router,
private route: ActivatedRoute,
private config: ConfigurationService,
2022-03-28 10:40:21 +02:00
private _helpContentService: HelpContentService,
private layoutService: LayoutService) {}
ngOnInit() {
this.initialize();
}
ngOnDestroy() {
for (let sub of this.subs) {
sub.unsubscribe();
[Trunk | Library]: 1. src/assets/common-assets/common/custom.css: Add 'font-display: swap;' in '@font-face' css rules - improve performance. 2. dataProvider.component.html & organizations.component.html & project.component.html & resultLanding.component.html: Add check if 'indexUpdateDate' is initialized. 3. dataProvider.component.ts & organization.component.ts & project.component.ts & resultLanding.component.ts: Initialize 'indexUpdateDate' and tabs counts only if "typeof document !== 'undefined'" (javascript is enabled) - improve performance. 4. resultLanding.component.ts: Get "provenanceActionVocabulary" and "altMetrics" only if "typeof document !== 'undefined'" (javascript is enabled) - improve performance. 5. organization.component.ts: [Bug fix] Get 'indexUpdateDate' from service (not properties) if available. 6. project.component.ts: [Bug fix] Call 'getProjectInfo()' only once (was called twice). 7. project.service.ts: [Bug fix] Add check for rels.rel.to.class=="hasParticipant" (when not array). 8. metrics.component.ts: Get metrics if "typeof document !== 'undefined'" (javascript is enabled) | Show charts only if user clicked on metrics badge | Do not set "width" for <i-frame> elements. 9. iframe.component.ts: Add case when only height is sent as input. 10. searchDataProviders.component.ts & searchOrganizations.component.ts: [Bug fix] Set "firstLoad" to false after getting results (was asking refine filters in paging too). 11. search-tab.component.ts: [Bug fix]: In method "getEntityName()" add cases when 'entityType == "project"' and 'entityType == "dataprovider"' and fix case when 'entityType == "result"'. 12. navigationBar.component.ts: [Bug fix] Do not initialize navbar inside route.queryParams subscription - !!! check it carefully when deployed in all portals !!! . git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@58874 d315682c-612b-4755-9ff5-7f18f6832af3
2020-06-10 13:05:59 +02:00
}
}
2022-02-28 13:38:26 +01:00
closeCanvas(element) {
UIkit.offcanvas(element).hide();
}
initialize() {
if ((['provide', 'develop']).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',
menuPosition: 'right',
badge: true
};
}
this.isAuthorized = Session.isClaimsCurator(this.user) || Session.isPortalAdministrator(this.user);
if ((this.properties.adminToolsAPIURL && this.communityId) || properties.adminToolsPortalType == "community") {
//this.config.getCommunityInformation(this.properties, this.communityId).subscribe(data => {
this.subs.push(this.config.communityInformationState.subscribe(data => {
if (data) {
this.showEntity = {};
this.showPage = {};
if (data['entities']) {
2022-02-28 13:38:26 +01:00
for (let i = 0; i < data['entities'].length; i++) {
this.showEntity['' + data['entities'][i]['pid'] + ''] = data['entities'][i]['isEnabled'];
}
}
if (data['pages']) {
2022-02-28 13:38:26 +01:00
for (let 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);
}));
}
if(this.properties.environment == "development" && this.portal != 'connect' && this.portal != 'connect-admin' && this.properties.adminToolsPortalType == 'community') {
this.subs.push(
this._helpContentService.getMenuItems(this.portal).subscribe(
data => {
// Will divide all the custom menu items into 2 arrays.
// One for the extra(added next to the hardcoded menu items in the existing nav bar) - additionalMenuItems
// One for the featured(new nav bar below the existing one) - featuredMenuItems
data.forEach(menuItem => {
if(menuItem.isFeatured) {
this.featuredMenuItems.push(menuItem);
} else {
// disable additional menu items for now
// this.additionalMenuItems.push(menuItem);
}
});
},
error => this.handleError("Server error fetching custom menu items", error)
)
);
}
}
2022-02-28 13:38:26 +01:00
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--;
}
}
2022-02-28 13:38:26 +01:00
return (count > 0);
}
private handleError(message: string, error) {
console.error('NavigationBar (component): ' + message, error);
}
get isHeaderLeft(): boolean {
return this.header.position === 'left' || (this.header.position === 'center' && this.header.menuPosition === 'center' && this.menuItems.length > 0);
}
get currentRoute() {
return {
route: this.router.url.split('?')[0].split('#')[0],
fragment: this.route.snapshot.fragment
}
}
2022-03-28 10:40:21 +02:00
isTheActiveMenu(menu: MenuItem | RootMenuItem): boolean {
if(menu instanceof MenuItem || !menu.rootItem) {
return MenuItem.isTheActiveMenu(<MenuItem> menu, this.currentRoute, this.layoutService.activeMenuItem);
2022-03-28 10:40:21 +02:00
} else {
let item: MenuItem = menu.rootItem;
item.items = menu.items;
return MenuItem.isTheActiveMenu(item, this.currentRoute, this.layoutService.activeMenuItem);
}
}
}