1 |
56300
|
argiro.kok
|
import {Component, Input} 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 |
59007
|
k.triantaf
|
import {Stakeholder} from "../monitor/entities/stakeholder";
|
8 |
59074
|
konstantin
|
import {Subscription} from "rxjs";
|
9 |
50169
|
argiro.kok
|
|
10 |
|
|
@Component({
|
11 |
|
|
selector: 'navbar',
|
12 |
|
|
templateUrl: 'navigationBar.component.html'
|
13 |
|
|
})
|
14 |
|
|
export class NavigationBarComponent {
|
15 |
57058
|
k.triantaf
|
@Input() portal: string = "connect";
|
16 |
59221
|
k.triantaf
|
@Input() dark: boolean = false;
|
17 |
57058
|
k.triantaf
|
@Input() onlyTop: boolean;
|
18 |
|
|
@Input() logoPath: string = "assets/common-assets/";
|
19 |
|
|
@Input() userMenu: boolean = true;
|
20 |
|
|
@Input() showHomeMenuItem: boolean = false;
|
21 |
50586
|
argiro.kok
|
@Input() communityId;
|
22 |
59007
|
k.triantaf
|
@Input() stakeholder: Stakeholder;
|
23 |
57058
|
k.triantaf
|
@Input() showCommunityName: boolean = false;
|
24 |
|
|
@Input() userMenuItems: MenuItem[];
|
25 |
|
|
@Input() menuItems: RootMenuItem [];
|
26 |
|
|
@Input() community: { id: string, name: string, logoUrl: string };
|
27 |
|
|
@Input() showMenu: boolean = true;
|
28 |
|
|
@Input() homeurl: boolean = true;
|
29 |
|
|
@Input() properties: EnvProperties;
|
30 |
|
|
@Input() user: User;
|
31 |
|
|
@Input() enableSearch: boolean = false;
|
32 |
|
|
@Input() searchRoute: string = "/search/find";
|
33 |
|
|
@Input() searchPlaceHolder: string = "Search for research results";
|
34 |
58944
|
k.triantaf
|
@Input() showLogo: boolean = true;
|
35 |
57058
|
k.triantaf
|
keyword: string = "";
|
36 |
50286
|
argiro.kok
|
|
37 |
58582
|
argiro.kok
|
logosrc: string = "";
|
38 |
|
|
logoUrl:string;
|
39 |
|
|
logoRoute:string;
|
40 |
|
|
logoName:string;
|
41 |
56137
|
argiro.kok
|
|
42 |
58582
|
argiro.kok
|
|
43 |
50169
|
argiro.kok
|
public isAuthorized: boolean = false;
|
44 |
59074
|
konstantin
|
subs: Subscription[] = [];
|
45 |
|
|
|
46 |
57058
|
k.triantaf
|
showEntity = {};
|
47 |
|
|
showPage = {};
|
48 |
|
|
specialAnnouncementContent: string = null;
|
49 |
56199
|
argiro.kok
|
activeRouteEnabled = false;
|
50 |
50169
|
argiro.kok
|
|
51 |
|
|
|
52 |
57058
|
k.triantaf
|
constructor(private router: Router,
|
53 |
|
|
private route: ActivatedRoute,
|
54 |
|
|
private config: ConfigurationService) {
|
55 |
50586
|
argiro.kok
|
}
|
56 |
50169
|
argiro.kok
|
|
57 |
|
|
ngOnInit() {
|
58 |
56199
|
argiro.kok
|
this.activeRouteEnabled = false;
|
59 |
58874
|
konstantin
|
//this.sub = this.route.queryParams.subscribe(params => {
|
60 |
|
|
//console.log("params: ",params);
|
61 |
50169
|
argiro.kok
|
this.initialize();
|
62 |
58874
|
konstantin
|
//});
|
63 |
50169
|
argiro.kok
|
}
|
64 |
57058
|
k.triantaf
|
|
65 |
|
|
ngOnDestroy() {
|
66 |
59074
|
konstantin
|
for (let sub of this.subs) {
|
67 |
|
|
sub.unsubscribe();
|
68 |
58874
|
konstantin
|
}
|
69 |
50169
|
argiro.kok
|
}
|
70 |
57058
|
k.triantaf
|
|
71 |
|
|
initialize() {
|
72 |
56199
|
argiro.kok
|
this.activeRouteEnabled = false;
|
73 |
57058
|
k.triantaf
|
this.isAuthorized = Session.isClaimsCurator(this.user) || Session.isPortalAdministrator(this.user);
|
74 |
|
|
if (this.properties.adminToolsAPIURL && this.communityId) {
|
75 |
59074
|
konstantin
|
//this.config.getCommunityInformation(this.properties, this.communityId).subscribe(data => {
|
76 |
|
|
this.subs.push(this.config.communityInformationState.subscribe(data => {
|
77 |
|
|
if(data) {
|
78 |
57058
|
k.triantaf
|
for (var i = 0; i < data['entities'].length; i++) {
|
79 |
50169
|
argiro.kok
|
|
80 |
57058
|
k.triantaf
|
this.showEntity["" + data['entities'][i]["pid"] + ""] = data['entities'][i]["isEnabled"];
|
81 |
|
|
}
|
82 |
|
|
for (var i = 0; i < data['pages'].length; i++) {
|
83 |
|
|
this.showPage[data['pages'][i]["route"]] = data['pages'][i]["isEnabled"];
|
84 |
50586
|
argiro.kok
|
|
85 |
57058
|
k.triantaf
|
}
|
86 |
59074
|
konstantin
|
}
|
87 |
|
|
},
|
88 |
|
|
error => {
|
89 |
|
|
this.handleError("Error getting community information (e.g. pages,entities) for community with id: " + this.communityId, error);
|
90 |
|
|
}));
|
91 |
50591
|
argiro.kok
|
}
|
92 |
58582
|
argiro.kok
|
if(!this.community){
|
93 |
|
|
this.logosrc = this.logoPath + "logo-large-"+this.portal+".png";
|
94 |
|
|
this.logoRoute = "/";
|
95 |
|
|
this.logoName = "OpenAIRE";
|
96 |
50586
|
argiro.kok
|
|
97 |
58582
|
argiro.kok
|
}else if( this.community){
|
98 |
|
|
this.logosrc = this.community.logoUrl;
|
99 |
|
|
if(this.homeurl){
|
100 |
|
|
this.logoRoute = "/";
|
101 |
|
|
}else{
|
102 |
|
|
this.logoUrl = 'https://'+(this.properties.environment =='beta'?'beta.':'')+this.community.id+'.openaire.eu';
|
103 |
|
|
}
|
104 |
|
|
this.logoName = this.community.name;
|
105 |
|
|
}
|
106 |
|
|
|
107 |
50169
|
argiro.kok
|
}
|
108 |
57058
|
k.triantaf
|
|
109 |
50169
|
argiro.kok
|
onClick(id: string) {
|
110 |
57058
|
k.triantaf
|
var el: HTMLElement = document.getElementById(id);
|
111 |
|
|
el.classList.remove('uk-open');
|
112 |
54206
|
argiro.kok
|
}
|
113 |
50169
|
argiro.kok
|
|
114 |
57058
|
k.triantaf
|
isEnabled(required, enabled) {
|
115 |
|
|
if (!required) {
|
116 |
|
|
return true;
|
117 |
|
|
}
|
118 |
50586
|
argiro.kok
|
|
119 |
57058
|
k.triantaf
|
|
120 |
|
|
for (let requiredEntity of required) {
|
121 |
|
|
if (typeof enabled[requiredEntity] === "undefined" || enabled[requiredEntity] == false) {
|
122 |
|
|
return false;
|
123 |
50586
|
argiro.kok
|
}
|
124 |
57058
|
k.triantaf
|
}
|
125 |
|
|
return true;
|
126 |
|
|
}
|
127 |
|
|
|
128 |
|
|
isAtleastOneEnabled(required, enabled) {
|
129 |
|
|
if (!required || required.length == 0) {
|
130 |
50586
|
argiro.kok
|
return true;
|
131 |
|
|
}
|
132 |
|
|
|
133 |
57058
|
k.triantaf
|
var count = required.length;
|
134 |
|
|
for (let requiredEntity of required) {
|
135 |
|
|
if (typeof enabled[requiredEntity] === "undefined" || enabled[requiredEntity] == false) {
|
136 |
|
|
count--;
|
137 |
54206
|
argiro.kok
|
}
|
138 |
|
|
}
|
139 |
57058
|
k.triantaf
|
return (count > 0) ? true : false;
|
140 |
|
|
}
|
141 |
54848
|
konstantin
|
|
142 |
57058
|
k.triantaf
|
private handleError(message: string, error) {
|
143 |
|
|
console.error("NavigationBar (component): " + message, error);
|
144 |
|
|
}
|
145 |
|
|
|
146 |
|
|
getCurrentRoute() {
|
147 |
56137
|
argiro.kok
|
return this.router.url.split('?')[0];
|
148 |
57058
|
k.triantaf
|
}
|
149 |
|
|
|
150 |
|
|
isTheActiveMenu(menu: RootMenuItem): boolean {
|
151 |
|
|
let currentRoute = this.getCurrentRoute();
|
152 |
|
|
if (!menu.rootItem.markAsActive) {
|
153 |
|
|
return false;
|
154 |
56137
|
argiro.kok
|
}
|
155 |
57058
|
k.triantaf
|
if (currentRoute == menu.rootItem.route) {
|
156 |
|
|
this.activeRouteEnabled = true;
|
157 |
|
|
return true;
|
158 |
|
|
} else if (menu.items.length > 0) {
|
159 |
|
|
for (let menuItem of menu.items) {
|
160 |
|
|
if (menuItem.route == currentRoute) {
|
161 |
|
|
this.activeRouteEnabled = true;
|
162 |
|
|
return true;
|
163 |
56199
|
argiro.kok
|
}
|
164 |
|
|
}
|
165 |
|
|
}
|
166 |
57058
|
k.triantaf
|
return false;
|
167 |
|
|
}
|
168 |
50169
|
argiro.kok
|
}
|