1
|
import {ChangeDetectorRef, Component, HostListener, OnDestroy, OnInit} from '@angular/core';
|
2
|
import {ActivatedRoute, NavigationEnd, Params, Router} from '@angular/router';
|
3
|
import {EnvProperties} from './openaireLibrary/utils/properties/env-properties';
|
4
|
import {EnvironmentSpecificService} from './openaireLibrary/utils/properties/environment-specific.service';
|
5
|
import {Session, User} from './openaireLibrary/login/utils/helper.class';
|
6
|
import {UserManagementService} from "./openaireLibrary/services/user-management.service";
|
7
|
import {StakeholderService} from "./openaireLibrary/monitor/services/stakeholder.service";
|
8
|
import {BehaviorSubject, Subscriber} from "rxjs";
|
9
|
import {LayoutService} from "./openaireLibrary/dashboard/sharedComponents/sidebar/layout.service";
|
10
|
import {MenuItem, RootMenuItem} from "./openaireLibrary/sharedComponents/menu";
|
11
|
import {Stakeholder, Topic, Visibility} from "./openaireLibrary/monitor/entities/stakeholder";
|
12
|
import {LinksResolver} from "./search/links-resolver";
|
13
|
import {Header} from "./openaireLibrary/sharedComponents/navigationBar.component";
|
14
|
import {arrow_left} from "./openaireLibrary/utils/icons/icons";
|
15
|
import {properties} from "../environments/environment";
|
16
|
import {ConfigurationService} from "./openaireLibrary/utils/configuration/configuration.service";
|
17
|
|
18
|
|
19
|
@Component({
|
20
|
selector: 'app-root',
|
21
|
templateUrl: './app.component.html'
|
22
|
})
|
23
|
export class AppComponent implements OnInit, OnDestroy {
|
24
|
properties: EnvProperties = properties;
|
25
|
user: User;
|
26
|
params: BehaviorSubject<Params> = new BehaviorSubject<Params>(null);
|
27
|
hasSidebar: boolean = false;
|
28
|
hasHeader: boolean = false;
|
29
|
hasAdminMenu: boolean = false;
|
30
|
hasMiniMenu: boolean = false;
|
31
|
isFrontPage: boolean = false;
|
32
|
isDashboard: boolean = false;
|
33
|
isViewPublic: boolean = false;
|
34
|
sideBarItems: MenuItem[] = [];
|
35
|
specialSideBarMenuItem: MenuItem = null;
|
36
|
menuItems: RootMenuItem[] = [];
|
37
|
menuHeader: Header = {
|
38
|
route: "/",
|
39
|
url: null,
|
40
|
title: "Default menu header",
|
41
|
logoUrl: null,
|
42
|
logoSmallUrl: null,
|
43
|
position: 'center',
|
44
|
badge: false,
|
45
|
stickyAnimation: false
|
46
|
};
|
47
|
|
48
|
userMenuItems: MenuItem[] = [];
|
49
|
adminMenuItems: MenuItem[] = [];
|
50
|
stakeholder: Stakeholder = null;
|
51
|
activeTopic: Topic = null;
|
52
|
loading: boolean = true;
|
53
|
paramsResolved: boolean = false;
|
54
|
innerWidth;
|
55
|
private subscriptions: any[] = [];
|
56
|
|
57
|
constructor(private route: ActivatedRoute,
|
58
|
private propertiesService: EnvironmentSpecificService,
|
59
|
private router: Router,
|
60
|
private userManagementService: UserManagementService,
|
61
|
private layoutService: LayoutService,
|
62
|
private stakeholderService: StakeholderService,
|
63
|
private cdr: ChangeDetectorRef, private configurationService: ConfigurationService) {
|
64
|
this.subscriptions.push(this.router.events.subscribe(event => {
|
65
|
if (event instanceof NavigationEnd) {
|
66
|
let r = this.route;
|
67
|
while (r.firstChild) {
|
68
|
r = r.firstChild;
|
69
|
}
|
70
|
let params = r.snapshot.params;
|
71
|
this.paramsResolved = true;
|
72
|
this.params.next(params);
|
73
|
}
|
74
|
}));
|
75
|
}
|
76
|
|
77
|
@HostListener('window:resize', ['$event'])
|
78
|
onResize(event) {
|
79
|
if (this.layoutService.isSmallScreen && event.target.innerWidth > 1219) {
|
80
|
this.layoutService.setSmallScreen(false);
|
81
|
} else if (!this.layoutService.isSmallScreen && event.target.innerWidth < 1219) {
|
82
|
this.layoutService.setSmallScreen(true);
|
83
|
this.layoutService.setOpen(false);
|
84
|
}
|
85
|
}
|
86
|
|
87
|
ngOnInit() {
|
88
|
if (typeof document !== 'undefined' && window) {
|
89
|
this.innerWidth = window.innerWidth;
|
90
|
}
|
91
|
this.subscriptions.push(this.layoutService.hasSidebar.subscribe(hasSidebar => {
|
92
|
this.hasSidebar = hasSidebar;
|
93
|
this.cdr.detectChanges();
|
94
|
}));
|
95
|
this.subscriptions.push(this.layoutService.hasHeader.subscribe(hasHeader => {
|
96
|
this.hasHeader = hasHeader;
|
97
|
this.cdr.detectChanges();
|
98
|
}));
|
99
|
this.subscriptions.push(this.layoutService.hasAdminMenu.subscribe(hasAdminMenu => {
|
100
|
this.hasAdminMenu = hasAdminMenu;
|
101
|
this.cdr.detectChanges();
|
102
|
}));
|
103
|
this.subscriptions.push(this.layoutService.hasMiniMenu.subscribe(hasMiniMenu => {
|
104
|
this.hasMiniMenu = hasMiniMenu;
|
105
|
this.cdr.detectChanges();
|
106
|
}));
|
107
|
this.subscriptions.push(this.layoutService.isFrontPage.subscribe(isFrontPage => {
|
108
|
this.isFrontPage = isFrontPage;
|
109
|
this.cdr.detectChanges();
|
110
|
}));
|
111
|
this.subscriptions.push(this.layoutService.isDashboard.subscribe(isDashboard => {
|
112
|
this.isDashboard = isDashboard;
|
113
|
this.cdr.detectChanges();
|
114
|
}));
|
115
|
this.route.queryParams.subscribe(params => {
|
116
|
this.isViewPublic = (params['view'] == 'public');
|
117
|
});
|
118
|
this.layoutService.setOpen(false);
|
119
|
this.layoutService.setSmallScreen((this.innerWidth && this.innerWidth < 1219));
|
120
|
this.layoutService.setOpen(!(this.innerWidth && this.innerWidth < 1219));
|
121
|
this.subscriptions.push(this.params.subscribe(params => {
|
122
|
if (this.paramsResolved) {
|
123
|
this.loading = true;
|
124
|
let isSearch = this.router.url.includes('/search/');
|
125
|
if (params && params['stakeholder']) {
|
126
|
// this.stakeholder = this.stakeholderService.stakeholder;
|
127
|
if (!this.stakeholder || this.stakeholder.alias !== params['stakeholder']) {
|
128
|
this.subscriptions.push(this.stakeholderService.getStakeholder(params['stakeholder']).subscribe(stakeholder => {
|
129
|
if (stakeholder) {
|
130
|
this.stakeholder = stakeholder;
|
131
|
LinksResolver.setProperties(this.stakeholder.alias);
|
132
|
this.setProperties(this.stakeholder.type, this.stakeholder.alias);
|
133
|
if (isSearch) {
|
134
|
this.activeTopic = null;
|
135
|
} else if (params && params['topic'] && !this.activeTopic) {
|
136
|
this.activeTopic = this.stakeholder.topics.find(topic => topic.alias === decodeURIComponent(params['topic']) && this.isPublicOrIsMember(topic.visibility));
|
137
|
} else {
|
138
|
this.activeTopic = this.stakeholder.topics.find(topic => this.isPublicOrIsMember(topic.visibility));
|
139
|
}
|
140
|
this.setSideBar();
|
141
|
this.buildMenu();
|
142
|
this.loading = false;
|
143
|
} else {
|
144
|
this.stakeholder = null;
|
145
|
LinksResolver.resetProperties();
|
146
|
this.resetProperties();
|
147
|
this.navigateToError();
|
148
|
this.buildMenu();
|
149
|
this.loading = false;
|
150
|
}
|
151
|
}, error => {
|
152
|
this.stakeholder = null;
|
153
|
LinksResolver.resetProperties();
|
154
|
this.resetProperties();
|
155
|
if (error && error.status && error.status === 404) {
|
156
|
this.navigateToError();
|
157
|
}
|
158
|
this.buildMenu();
|
159
|
this.loading = false;
|
160
|
}));
|
161
|
} else {
|
162
|
this.buildMenu();
|
163
|
if (isSearch) {
|
164
|
this.activeTopic = null;
|
165
|
} else if (params && params['topic']) {
|
166
|
this.activeTopic = this.stakeholder.topics.find(topic => topic.alias === decodeURIComponent(params['topic']) && this.isPublicOrIsMember(topic.visibility));
|
167
|
} else {
|
168
|
this.activeTopic = this.stakeholder.topics.find(topic => this.isPublicOrIsMember(topic.visibility));
|
169
|
}
|
170
|
this.loading = false;
|
171
|
}
|
172
|
} else {
|
173
|
LinksResolver.resetProperties();
|
174
|
this.stakeholderService.setStakeholder(null);
|
175
|
this.layoutService.setOpen(!(this.innerWidth && this.innerWidth < 1219));
|
176
|
this.stakeholder = null;
|
177
|
this.buildMenu();
|
178
|
this.loading = false;
|
179
|
this.resetProperties();
|
180
|
}
|
181
|
}
|
182
|
}));
|
183
|
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
|
184
|
this.user = user;
|
185
|
if (user) {
|
186
|
this.buildMenu();
|
187
|
}
|
188
|
}, error => {
|
189
|
console.log("App couldn't fetch properties");
|
190
|
console.log(error);
|
191
|
}));
|
192
|
}
|
193
|
|
194
|
public ngOnDestroy() {
|
195
|
this.subscriptions.forEach(value => {
|
196
|
if (value instanceof Subscriber) {
|
197
|
value.unsubscribe();
|
198
|
}
|
199
|
});
|
200
|
this.userManagementService.clearSubscriptions();
|
201
|
this.layoutService.clearSubscriptions();
|
202
|
this.stakeholderService.clearSubscriptions();
|
203
|
this.configurationService.clearSubscriptions();
|
204
|
}
|
205
|
|
206
|
private navigateToError() {
|
207
|
this.router.navigate(['/error'], {queryParams: {'page': this.properties.baseLink + this.router.url}});
|
208
|
}
|
209
|
|
210
|
public get open() {
|
211
|
return this.layoutService.open;
|
212
|
}
|
213
|
|
214
|
public toggleOpen(event: MouseEvent) {
|
215
|
event.preventDefault();
|
216
|
this.layoutService.setOpen(!this.open);
|
217
|
}
|
218
|
|
219
|
private setSideBar() {
|
220
|
let items: MenuItem[] = [];
|
221
|
if (this.isPublicOrIsMember(this.stakeholder.visibility)) {
|
222
|
this.stakeholder.topics.forEach((topic) => {
|
223
|
if (this.isPublicOrIsMember(topic.visibility)) {
|
224
|
let topicItem: MenuItem = new MenuItem(topic.alias, topic.name, "", (
|
225
|
'/' + this.stakeholder.alias + '/' + topic.alias),
|
226
|
null, [], [], {});
|
227
|
topicItem.icon = topic.icon;
|
228
|
items.push(topicItem);
|
229
|
}
|
230
|
});
|
231
|
if (items.length === 0) {
|
232
|
items.push(new MenuItem('noTopics', 'No topics available yet', "", "", false, [], [], {}));
|
233
|
}
|
234
|
} else {
|
235
|
let topicItem: MenuItem = new MenuItem("private", "Private Data", "", "", null, [], [], {});
|
236
|
items.push(topicItem);
|
237
|
}
|
238
|
this.sideBarItems = items;
|
239
|
}
|
240
|
|
241
|
buildMenu() {
|
242
|
this.menuItems = [];
|
243
|
this.adminMenuItems = [];
|
244
|
this.userMenuItems = [];
|
245
|
if (this.user) {
|
246
|
if (this.isCurator()) {
|
247
|
this.userMenuItems.push(new MenuItem("", "Manage profiles",
|
248
|
"", "/admin", false, [], [], {}));
|
249
|
}
|
250
|
if(Session.isPortalAdministrator(this.user) ) {
|
251
|
this.userMenuItems.push( new MenuItem("adminOptions", "Super Admin options","", "/admin-tools/portals", false, [], [], {}));
|
252
|
this.userMenuItems.push(new MenuItem("monitorOptions", "Monitor portal options","", "/admin-tools/pages", false, [], [], {communityId: 'monitor'}));
|
253
|
|
254
|
}
|
255
|
this.userMenuItems.push(new MenuItem("", "User information", "", "/user-info", false, [], [], {}));
|
256
|
}
|
257
|
if (this.stakeholder) {
|
258
|
if (!this.isDashboard) {
|
259
|
this.menuHeader = {
|
260
|
route: null,
|
261
|
url: "https://" + (this.properties.environment == 'beta' ? 'beta.' : '') + 'monitor.openaire.eu',
|
262
|
title: "Monitor",
|
263
|
logoUrl: 'assets/common-assets/logo-large-monitor.png',
|
264
|
logoSmallUrl: "assets/common-assets/logo-small-monitor.png",
|
265
|
position: 'left',
|
266
|
badge: true,
|
267
|
stickyAnimation: false
|
268
|
};
|
269
|
this.menuItems.push({
|
270
|
rootItem: new MenuItem("dashboard", "Dashboard",
|
271
|
"", "/" + this.stakeholder.alias, false, [], null, {}), items: []
|
272
|
});
|
273
|
if(this.stakeholder.type === "funder") {
|
274
|
this.menuItems.push({
|
275
|
rootItem: new MenuItem("develop", "Develop",
|
276
|
"", "/" + this.stakeholder.alias + "/develop", false, [], null, {}), items: []
|
277
|
});
|
278
|
}
|
279
|
if (this.isCurator()) {
|
280
|
this.menuItems.push({
|
281
|
rootItem: new MenuItem("manage", "Manage",
|
282
|
"", "/admin", false, [], null, {}), items: []
|
283
|
});
|
284
|
}
|
285
|
}
|
286
|
else if (this.isFrontPage) {
|
287
|
this.menuHeader = {
|
288
|
route: "/" + this.stakeholder.alias,
|
289
|
url: null,
|
290
|
title: this.stakeholder.name,
|
291
|
logoUrl: null,
|
292
|
logoSmallUrl: null,
|
293
|
position: 'center',
|
294
|
badge: false,
|
295
|
stickyAnimation: false
|
296
|
};
|
297
|
if(this.stakeholder.type === "funder") {
|
298
|
this.menuItems.push({
|
299
|
rootItem: new MenuItem("develop", "Develop",
|
300
|
"", "/" + this.stakeholder.alias + "/develop", false, [], null, {}), items: []
|
301
|
});
|
302
|
}
|
303
|
if (this.isCurator()) {
|
304
|
this.menuItems.push({
|
305
|
rootItem: new MenuItem("manage", "Manage",
|
306
|
"", "/admin", false, [], null, {}), items: []
|
307
|
});
|
308
|
}
|
309
|
|
310
|
if (this.isPublicOrIsMember(this.stakeholder.visibility)) {
|
311
|
this.specialSideBarMenuItem = new MenuItem("search", "Search research outcomes", "", this.properties.searchLinkToResults, false, [], null, {});
|
312
|
this.specialSideBarMenuItem.icon = '<span uk-icon="search"></span>';
|
313
|
} else {
|
314
|
this.specialSideBarMenuItem = null;
|
315
|
}
|
316
|
} else {
|
317
|
this.menuHeader = {
|
318
|
route: "/admin/" + this.stakeholder.alias,
|
319
|
url: null,
|
320
|
title: 'Admin - ' + this.stakeholder.name,
|
321
|
logoUrl: null,
|
322
|
logoSmallUrl: null,
|
323
|
position: 'center',
|
324
|
badge: false,
|
325
|
stickyAnimation: false
|
326
|
};
|
327
|
this.menuItems.push({
|
328
|
rootItem: new MenuItem("", "Dashboard",
|
329
|
"", '/' + this.stakeholder.alias + '/', false, [], null, {}), items: []
|
330
|
});
|
331
|
this.adminMenuItems.push(new MenuItem("general", "General", "", "/admin/" + this.stakeholder.alias, false, [], [], {}, "<i uk-icon=\"image\"></i>"));
|
332
|
this.adminMenuItems.push(new MenuItem("indicators", "Indicators", "", "/admin/" + this.stakeholder.alias + '/indicators', false, [], [], {}, "<i uk-icon=\"image\"></i>"));
|
333
|
this.adminMenuItems.push(new MenuItem("users", "Users", "", "/admin/" + this.stakeholder.alias + "/users", false, [], [], {}, "<i uk-icon=\"users\"></i>"));
|
334
|
if(Session.isPortalAdministrator(this.user) ) {
|
335
|
this.adminMenuItems.push(new MenuItem("monitorOptions", "Pages & Entities", "", "/admin-tools/" + this.stakeholder.alias + "/pages", false, [], [], {communityId:this.stakeholder.alias}));
|
336
|
}
|
337
|
this.specialSideBarMenuItem = new MenuItem("back", "Manage profiles", "", "/admin", false, [], null, {});
|
338
|
this.specialSideBarMenuItem.icon = '<span class="uk-icon-button small uk-icon uk-button-secondary">' + arrow_left.data + '</span>'; // '<span class="uk-icon-button uk-icon portal-button " uk-icon="chevron-left"></span>';
|
339
|
this.specialSideBarMenuItem.customClass = 'uk-text-uppercase uk-text-bold uk-text-secondary';
|
340
|
}
|
341
|
} else {
|
342
|
if (this.isFrontPage || !this.hasAdminMenu) {
|
343
|
this.menuHeader = {
|
344
|
route: null,
|
345
|
url: "https://" + (this.properties.environment == 'beta' ? 'beta.' : '') + 'monitor.openaire.eu',
|
346
|
title: "Monitor",
|
347
|
logoUrl: 'assets/common-assets/logo-large-monitor.png',
|
348
|
logoSmallUrl: "assets/common-assets/logo-small-monitor.png",
|
349
|
position: 'left',
|
350
|
badge: true,
|
351
|
stickyAnimation: false
|
352
|
};
|
353
|
this.menuItems.push({
|
354
|
rootItem: new MenuItem("about", "About",
|
355
|
"https://" + (this.properties.environment == 'beta' ? 'beta.' : '') + 'monitor.openaire.eu/about/learn-how', "", false, [], null, {}),
|
356
|
items: []
|
357
|
});
|
358
|
this.menuItems.push({
|
359
|
rootItem: new MenuItem("browse", "Browse",
|
360
|
"https://" + (this.properties.environment == 'beta' ? 'beta.' : '') + 'monitor.openaire.eu/browse', "", false, [], null, {}),
|
361
|
items: []
|
362
|
});
|
363
|
this.menuItems.push({
|
364
|
rootItem: new MenuItem("contact", "Contact us",
|
365
|
"https://" + (this.properties.environment == 'beta' ? 'beta.' : '') + 'monitor.openaire.eu/contact-us', "", false, [], null, {}),
|
366
|
items: []
|
367
|
});
|
368
|
} else {
|
369
|
this.menuHeader = {
|
370
|
route: "/",
|
371
|
url: null,
|
372
|
title: "Monitor Dashboard",
|
373
|
logoUrl: null,
|
374
|
logoSmallUrl: null,
|
375
|
position: 'center',
|
376
|
badge: false,
|
377
|
stickyAnimation: false
|
378
|
};
|
379
|
this.adminMenuItems = [];
|
380
|
this.specialSideBarMenuItem = null;
|
381
|
this.adminMenuItems.push(new MenuItem("stakeholders", "Manage profiles", "", "/admin", false, [], [], {}, "<i uk-icon=\"cog\"></i>"));
|
382
|
// if(Session.isPortalAdministrator(this.user) ) {
|
383
|
// let adminOptions = new MenuItem("adminOptions", "Admin Options","", "/admin-tools/admin-pages", false, [], [], {});
|
384
|
// /* adminOptions.items.push(new MenuItem("pages", "Pages", "", "/admin-tools/pages", false, [], [], {}));
|
385
|
// adminOptions.items.push(new MenuItem("portals", "Portals", "", "/admin-tools/portals", false, [], [], {}));
|
386
|
// adminOptions.items.push(new MenuItem("entities", "Entities", "", "/admin-tools/entities", false, [], [], {}));
|
387
|
// // adminOptions.items.push(new MenuItem("classes", "Class help texts", "", "/admin-tools/classes", false, [], [], {}));*/
|
388
|
// this.adminMenuItems.push(adminOptions);
|
389
|
// let monitorOptions = new MenuItem("monitorOptions", "Monitor Options","", "/admin-tools/admin-pages", false, [], [], {communityId: 'monitor'});
|
390
|
// /* monitorOptions.items.push(new MenuItem("pages", "Pages", "", "/admin-tools/pages", false, [], [], {communityId: 'monitor'}));
|
391
|
// monitorOptions.items.push(new MenuItem("entities", "Entities", "", "/admin-tools/entities", false, [], [], {communityId: 'monitor'}));
|
392
|
// // monitorOptions.items.push(new MenuItem("classes", "Class help texts", "", "/admin-tools/classContents", false, [], [], {communityId: 'monitor'}));
|
393
|
// monitorOptions.items.push(new MenuItem("helptexts", "Help texts", "", "/admin-tools/helptexts", false, [], [], {communityId: 'monitor'}));*/
|
394
|
// this.adminMenuItems.push(monitorOptions);
|
395
|
// }
|
396
|
|
397
|
}
|
398
|
}
|
399
|
|
400
|
}
|
401
|
|
402
|
public isCurator() {
|
403
|
return this.user && (Session.isPortalAdministrator(this.user) || Session.isMonitorCurator(this.user) || Session.isKindOfMonitorManager(this.user));
|
404
|
}
|
405
|
|
406
|
public isManager(stakeholder: Stakeholder) {
|
407
|
return this.user && (Session.isPortalAdministrator(this.user) || Session.isCurator(stakeholder.type, this.user) || Session.isManager(stakeholder.type, stakeholder.alias, this.user));
|
408
|
}
|
409
|
|
410
|
private resolvePageInner() {
|
411
|
if (document !== undefined) {
|
412
|
let header = document.getElementById('pager_header_content');
|
413
|
let inner = document.getElementById('page_content_inner');
|
414
|
if (header) {
|
415
|
inner.setAttribute('style', '{margin-top:' + header.offsetHeight + '}');
|
416
|
} else {
|
417
|
inner.setAttribute('style', '{margin-top:' + 0 + '}');
|
418
|
}
|
419
|
}
|
420
|
}
|
421
|
|
422
|
public isPublicOrIsMember(visibility: Visibility): boolean {
|
423
|
if (visibility == "PRIVATE" || (this.isViewPublic && visibility != "PUBLIC")) {
|
424
|
return false;
|
425
|
}
|
426
|
return true;
|
427
|
}
|
428
|
setProperties(type, communityId){
|
429
|
this.properties.adminToolsCommunity = communityId;
|
430
|
this.properties.adminToolsPortalType = type;
|
431
|
this.configurationService.initCommunityInformation(this.properties, this.properties.adminToolsCommunity);
|
432
|
}
|
433
|
resetProperties(){
|
434
|
this.properties.adminToolsCommunity = "monitor";
|
435
|
this.properties.adminToolsPortalType = "monitor";
|
436
|
this.configurationService.initCommunityInformation(this.properties, this.properties.adminToolsCommunity);
|
437
|
}
|
438
|
|
439
|
/* createSearchParameters() {
|
440
|
if (!this.stakeholder) {
|
441
|
return {};
|
442
|
}
|
443
|
if (this.stakeholder.type == "funder") {
|
444
|
return {"relfunder": encodeURIComponent("\"" + this.stakeholder.index_id + "||" + this.stakeholder.index_name + "||" + this.stakeholder.index_shortName + "\"")};
|
445
|
} else if (this.stakeholder.type == "ri") {
|
446
|
return {"community": encodeURIComponent("\"" + this.stakeholder.index_id + "||" + this.stakeholder.index_name + "\"")};
|
447
|
} else if (this.stakeholder.type == "organization") {
|
448
|
return {"cf": true};
|
449
|
}
|
450
|
}*/
|
451
|
}
|