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