1
|
import {Component, Input, OnDestroy, OnInit} from '@angular/core';
|
2
|
import {ActivatedRoute, Router} from '@angular/router';
|
3
|
import {Session, User} from '../login/utils/helper.class';
|
4
|
import {ConfigurationService} from '../utils/configuration/configuration.service';
|
5
|
import {MenuItem, RootMenuItem} from './menu';
|
6
|
import {EnvProperties} from '../utils/properties/env-properties';
|
7
|
import {Subscription} from 'rxjs';
|
8
|
|
9
|
export interface Header {
|
10
|
route?: string,
|
11
|
url?: string,
|
12
|
title: string,
|
13
|
logoUrl: string,
|
14
|
logoSmallUrl: string,
|
15
|
position: 'left' | 'center' | 'right',
|
16
|
badge: boolean
|
17
|
stickyAnimation?: boolean
|
18
|
}
|
19
|
|
20
|
@Component({
|
21
|
selector: 'navbar',
|
22
|
templateUrl: 'navigationBar.component.html'
|
23
|
})
|
24
|
export class NavigationBarComponent implements OnInit, OnDestroy {
|
25
|
@Input() portal: string = 'connect';
|
26
|
@Input() dark: boolean = false;
|
27
|
@Input() onlyTop: boolean;
|
28
|
@Input() logoPath: string = 'assets/common-assets/';
|
29
|
@Input() userMenu: boolean = true;
|
30
|
@Input() showHomeMenuItem: boolean = false;
|
31
|
@Input() communityId;
|
32
|
@Input() showCommunityName: boolean = false;
|
33
|
@Input() userMenuItems: MenuItem[];
|
34
|
@Input() menuItems: RootMenuItem [];
|
35
|
@Input() header: Header;
|
36
|
@Input() showMenu: boolean = true;
|
37
|
@Input() homeurl: boolean = true;
|
38
|
@Input() properties: EnvProperties;
|
39
|
@Input() user: User;
|
40
|
@Input() enableSearch: boolean = false;
|
41
|
@Input() searchRoute: string = '/search/find';
|
42
|
@Input() searchPlaceHolder: string = 'Search for research results';
|
43
|
@Input() showLogo: boolean = true;
|
44
|
@Input() offCanvasFlip: boolean = false;
|
45
|
keyword: string = '';
|
46
|
public isAuthorized: boolean = false;
|
47
|
subs: Subscription[] = [];
|
48
|
showEntity = {};
|
49
|
showPage = {};
|
50
|
specialAnnouncementContent: string = null;
|
51
|
|
52
|
|
53
|
constructor(private router: Router,
|
54
|
private route: ActivatedRoute,
|
55
|
private config: ConfigurationService) {
|
56
|
}
|
57
|
|
58
|
ngOnInit() {
|
59
|
this.initialize();
|
60
|
}
|
61
|
|
62
|
ngOnDestroy() {
|
63
|
for (let sub of this.subs) {
|
64
|
sub.unsubscribe();
|
65
|
}
|
66
|
}
|
67
|
|
68
|
initialize() {
|
69
|
if ((['provide', 'develop']).indexOf(this.portal) != -1) {
|
70
|
this.header = {
|
71
|
route: '/',
|
72
|
url: null,
|
73
|
title: this.portal,
|
74
|
logoUrl: this.logoPath + 'logo-large-' + this.portal + '.png',
|
75
|
logoSmallUrl: this.logoPath + 'logo-small-' + this.portal + '.png',
|
76
|
position: 'left',
|
77
|
badge: true
|
78
|
};
|
79
|
}
|
80
|
this.isAuthorized = Session.isClaimsCurator(this.user) || Session.isPortalAdministrator(this.user);
|
81
|
if (this.properties.adminToolsAPIURL && this.communityId) {
|
82
|
//this.config.getCommunityInformation(this.properties, this.communityId).subscribe(data => {
|
83
|
this.subs.push(this.config.communityInformationState.subscribe(data => {
|
84
|
if (data) {
|
85
|
if (data['entities']) {
|
86
|
for (var i = 0; i < data['entities'].length; i++) {
|
87
|
|
88
|
this.showEntity['' + data['entities'][i]['pid'] + ''] = data['entities'][i]['isEnabled'];
|
89
|
}
|
90
|
}
|
91
|
if (data['pages']) {
|
92
|
for (var i = 0; i < data['pages'].length; i++) {
|
93
|
this.showPage[data['pages'][i]['route']] = data['pages'][i]['isEnabled'];
|
94
|
|
95
|
}
|
96
|
}
|
97
|
}
|
98
|
},
|
99
|
error => {
|
100
|
this.handleError('Error getting community information (e.g. pages,entities) for community with id: ' + this.communityId, error);
|
101
|
}));
|
102
|
}
|
103
|
}
|
104
|
|
105
|
|
106
|
isEnabled(required, enabled) {
|
107
|
if (!required) {
|
108
|
return true;
|
109
|
}
|
110
|
|
111
|
|
112
|
for (let requiredEntity of required) {
|
113
|
if (typeof enabled[requiredEntity] === 'undefined' || enabled[requiredEntity] == false) {
|
114
|
return false;
|
115
|
}
|
116
|
}
|
117
|
return true;
|
118
|
}
|
119
|
|
120
|
isAtleastOneEnabled(required, enabled) {
|
121
|
if (!required || required.length == 0) {
|
122
|
return true;
|
123
|
}
|
124
|
|
125
|
var count = required.length;
|
126
|
for (let requiredEntity of required) {
|
127
|
if (typeof enabled[requiredEntity] === 'undefined' || enabled[requiredEntity] == false) {
|
128
|
count--;
|
129
|
}
|
130
|
}
|
131
|
return (count > 0) ? true : false;
|
132
|
}
|
133
|
|
134
|
private handleError(message: string, error) {
|
135
|
console.error('NavigationBar (component): ' + message, error);
|
136
|
}
|
137
|
|
138
|
get currentRoute() {
|
139
|
return {
|
140
|
route: this.router.url.split('?')[0].split('#')[0],
|
141
|
fragment: this.route.snapshot.fragment
|
142
|
}
|
143
|
}
|
144
|
|
145
|
isTheActiveMenu(menu: RootMenuItem): boolean {
|
146
|
if (!menu.rootItem.markAsActive) {
|
147
|
return false;
|
148
|
}
|
149
|
if (this.isTheActiveMenuItem(menu.rootItem)) {
|
150
|
return true;
|
151
|
} else if (menu.items.length > 0) {
|
152
|
for (let menuItem of menu.items) {
|
153
|
if (this.isTheActiveMenuItem(menuItem)) {
|
154
|
return true;
|
155
|
}
|
156
|
}
|
157
|
}
|
158
|
return false;
|
159
|
}
|
160
|
|
161
|
isTheActiveMenuItem(menuItem: MenuItem): boolean {
|
162
|
let currentRoute = this.currentRoute;
|
163
|
return (menuItem.route == currentRoute.route || menuItem.route == (currentRoute.route + "/")) &&
|
164
|
currentRoute.fragment == menuItem.fragment;
|
165
|
}
|
166
|
}
|