1
|
import {Component, ElementRef, Input, ViewChild} from '@angular/core';
|
2
|
import {ActivatedRoute, Router} from '@angular/router';
|
3
|
import {Location} from '@angular/common';
|
4
|
import {Meta, Title} from '@angular/platform-browser';
|
5
|
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
|
6
|
|
7
|
import {CommunityService} from "../openaireLibrary/connect/community/community.service";
|
8
|
import {ConfigurationService} from '../openaireLibrary/utils/configuration/configuration.service';
|
9
|
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
|
10
|
import {SearchZenodoCommunitiesService} from '../openaireLibrary/connect/zenodoCommunities/searchZenodoCommunities.service';
|
11
|
import {ZenodoCommunitiesService} from '../openaireLibrary/connect/zenodoCommunities/zenodo-communities.service';
|
12
|
import {Session, User} from '../openaireLibrary/login/utils/helper.class';
|
13
|
import {StatisticsForDashboardComponent} from '../statistics/statistics.component';
|
14
|
import {StringUtils} from '../openaireLibrary/utils/string-utils.class';
|
15
|
|
16
|
import {PiwikHelper} from '../utils/piwikHelper';
|
17
|
import {HelperFunctions} from "../openaireLibrary/utils/HelperFunctions.class";
|
18
|
import {SearchCommunityDataprovidersService} from "../openaireLibrary/connect/contentProviders/searchDataproviders.service";
|
19
|
import {SearchCommunityProjectsService} from "../openaireLibrary/connect/projects/searchProjects.service";
|
20
|
import {SearchResearchResultsService} from "../openaireLibrary/services/searchResearchResults.service";
|
21
|
import {RouterHelper} from "../openaireLibrary/utils/routerHelper.class";
|
22
|
import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service";
|
23
|
import {UserManagementService} from "../openaireLibrary/services/user-management.service";
|
24
|
import {SubscribeComponent} from "../utils/subscribe/subscribe.component";
|
25
|
import {SearchCustomFilter} from "../openaireLibrary/searchPages/searchUtils/searchUtils.class";
|
26
|
|
27
|
@Component({
|
28
|
selector: 'community',
|
29
|
templateUrl: 'community.component.html',
|
30
|
})
|
31
|
|
32
|
export class CommunityComponent {
|
33
|
public url: string = null;
|
34
|
|
35
|
public sub: any;
|
36
|
public piwiksub: any;
|
37
|
public subfunders: any;
|
38
|
|
39
|
public publicationTotal = null;
|
40
|
public researchDataTotal = null;
|
41
|
public softwareTotal = null;
|
42
|
public orpTotal = null;
|
43
|
public projectTotal = null;
|
44
|
public contentProviderTotal = null;
|
45
|
public organizationTotal = null;
|
46
|
|
47
|
public projectsCalculated: boolean = false;
|
48
|
public contentProvidersCalculated: boolean = false;
|
49
|
|
50
|
params: any = {};
|
51
|
properties: EnvProperties;
|
52
|
|
53
|
public publicationResults = null;
|
54
|
public researchDataResults = null;
|
55
|
public softwareResults = null;
|
56
|
public orpResults = null;
|
57
|
|
58
|
@Input() communityId = null;
|
59
|
public community = null;
|
60
|
|
61
|
public communityInfo = null;
|
62
|
|
63
|
public showLoading: boolean = true;
|
64
|
masterZenodoCommunity = null;
|
65
|
zenodoCommunityIdS = [];
|
66
|
showAllSubjects = false;
|
67
|
showAllDescription = false;
|
68
|
public thresholdDescription: number = 500;
|
69
|
public descriptionDiff: number = 100;
|
70
|
|
71
|
subscribers: number = 0;
|
72
|
|
73
|
// TODO Unsubscribe
|
74
|
public subPublications;
|
75
|
public subResearchData;
|
76
|
public subSoftware;
|
77
|
public subOrps;
|
78
|
@ViewChild(StatisticsForDashboardComponent) statistics: StatisticsForDashboardComponent = null;
|
79
|
public activeTab = "summary";
|
80
|
public show: string = 'overview';
|
81
|
|
82
|
searchLinkToResults: string = null;
|
83
|
|
84
|
searchLinkToProjects: string = null;
|
85
|
searchLinkToDataProviders: string = null;
|
86
|
searchLinkToAdvancedResults: string = null;
|
87
|
shareInZenodoPage: string = null;
|
88
|
public routerHelper: RouterHelper = new RouterHelper();
|
89
|
private user: User;
|
90
|
|
91
|
@ViewChild(SubscribeComponent) subscribeComponent: SubscribeComponent = null;
|
92
|
//Search Form
|
93
|
selectedEntity;
|
94
|
selectedEntitySimpleUrl;
|
95
|
selectedEntityAdvancedUrl;
|
96
|
keyword:string ="";
|
97
|
customFilter;
|
98
|
placeholderText="Search by title, author, abstract, DOI, orcid... ";
|
99
|
|
100
|
constructor(
|
101
|
private element: ElementRef,
|
102
|
private route: ActivatedRoute,
|
103
|
private _router: Router,
|
104
|
private location: Location,
|
105
|
private _meta: Meta,
|
106
|
private _title: Title,
|
107
|
private _piwikService: PiwikService,
|
108
|
private config: ConfigurationService,
|
109
|
private _communityService: CommunityService,
|
110
|
private _searchCommunityDataprovidersService: SearchCommunityDataprovidersService,
|
111
|
private _searchCommunityProjectsService: SearchCommunityProjectsService,
|
112
|
private _searchResearchResultsService: SearchResearchResultsService,
|
113
|
private _searchZenodoCommunitiesService: SearchZenodoCommunitiesService,
|
114
|
private _ΖenodoCommunitieService: ZenodoCommunitiesService,
|
115
|
private seoService: SEOService,
|
116
|
private userManagementService: UserManagementService) {
|
117
|
|
118
|
var description = "OpenAIRE - Connect, Community Dashboard, research community";
|
119
|
var title = "OpenAIRE - Connect";
|
120
|
this._meta.updateTag({content: description}, "name='description'");
|
121
|
this._meta.updateTag({content: description}, "property='og:description'");
|
122
|
this._meta.updateTag({content: title}, "property='og:title'");
|
123
|
this._title.setTitle(title);
|
124
|
|
125
|
}
|
126
|
|
127
|
public ngOnInit() {
|
128
|
this.route.data
|
129
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
130
|
this.properties = data.envSpecific;
|
131
|
this.searchLinkToResults = this.properties.searchLinkToResults;
|
132
|
this.searchLinkToProjects = this.properties.searchLinkToProjects;
|
133
|
this.searchLinkToDataProviders = this.properties.searchLinkToDataProviders;
|
134
|
this.searchLinkToAdvancedResults = this.properties.searchLinkToAdvancedResults;
|
135
|
this.shareInZenodoPage = this.properties.shareInZenodoPage;
|
136
|
this.url = data.envSpecific.baseLink + this._router.url;
|
137
|
this.seoService.createLinkForCanonicalURL(this.url, false);
|
138
|
this._meta.updateTag({content: this.url}, "property='og:url'");
|
139
|
this.userManagementService.getUserInfo().subscribe(user => {
|
140
|
this.user = user;
|
141
|
});
|
142
|
if (this.communityId != null && this.communityId != '') {
|
143
|
this.customFilter = new SearchCustomFilter("Community", "communityId", this.communityId, "");
|
144
|
this._communityService.getCommunity(this.properties, this.properties.communityAPI + this.communityId).subscribe(
|
145
|
community => {
|
146
|
if (typeof document !== 'undefined') {
|
147
|
HelperFunctions.scroll();
|
148
|
}
|
149
|
this.community = community;
|
150
|
if(community.description != null && (community.description.length - this.thresholdDescription <= this.descriptionDiff)) {
|
151
|
this.thresholdDescription = community.description.length;
|
152
|
}
|
153
|
|
154
|
if (this.properties.environment == "development") {
|
155
|
this.params = {communityId: community.communityId};
|
156
|
}
|
157
|
this._meta.updateTag({content: community.description}, "name='description'");
|
158
|
this._meta.updateTag({content: community.description}, "property='og:description'");
|
159
|
this._meta.updateTag({content: community.title}, "property='og:title'");
|
160
|
this._title.setTitle(community.title);
|
161
|
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
|
162
|
this.piwiksub = this._piwikService.trackView(this.properties, community.title, PiwikHelper.getSiteId(this.communityId, this.properties.environment)).subscribe();
|
163
|
}
|
164
|
if (this.community.zenodoCommunity) {
|
165
|
this._ΖenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities + this.community.zenodoCommunity, null).subscribe(
|
166
|
result => {
|
167
|
this.masterZenodoCommunity = result;
|
168
|
|
169
|
},
|
170
|
error => {
|
171
|
// var emptyCommunity:ZenodoCommunityInfo = new ZenodoCommunityInfo();
|
172
|
// emptyCommunity.id = this.masterZenodoCommunityId;
|
173
|
// emptyCommunity.title = this.masterZenodoCommunityId;
|
174
|
// this.masterZenodoCommunity = emptyCommunity;
|
175
|
//console.log("Master Zenodo community'" + this.community.zenodoCommunity + "' couldn't be loaded");
|
176
|
this.handleError("Error getting Master Zenodo community with id: " + this.community.zenodoCommunityId, error);
|
177
|
|
178
|
}
|
179
|
);
|
180
|
}
|
181
|
this._searchZenodoCommunitiesService.searchZCommunities(this.properties, this.communityId).subscribe(
|
182
|
result => {
|
183
|
this.zenodoCommunityIdS = result;
|
184
|
|
185
|
|
186
|
},
|
187
|
error => {
|
188
|
//console.error("list of zenodo communities couldn't be loaded");
|
189
|
this.handleError("Error getting list of zenodo communities for community with openaire id: " + this.communityId, error);
|
190
|
} //this.handleError('System error retrieving community profile', error)
|
191
|
);
|
192
|
|
193
|
//console.log(community);
|
194
|
});
|
195
|
|
196
|
this.countResearchResults("publication");
|
197
|
this.countResearchResults("dataset");
|
198
|
this.countResearchResults("software");
|
199
|
this.countResearchResults("other");
|
200
|
|
201
|
this._searchCommunityProjectsService.countTotalProjects(this.properties, this.communityId).subscribe(
|
202
|
projectTotal => {
|
203
|
this.projectTotal = projectTotal;
|
204
|
//console.log(projectTotal);
|
205
|
},
|
206
|
error => {
|
207
|
this.handleError("Error getting number of projects for community with id: " + this.communityId, error);
|
208
|
},
|
209
|
() => {
|
210
|
this.projectsCalculated = true;
|
211
|
}
|
212
|
);
|
213
|
|
214
|
this._searchCommunityDataprovidersService.countTotalDataproviders(this.properties, this.communityId).subscribe(
|
215
|
contentProviderTotal => {
|
216
|
this.contentProviderTotal = contentProviderTotal;
|
217
|
//console.log(contentProviderTotal);
|
218
|
},
|
219
|
error => {
|
220
|
this.handleError("Error getting number of content providers for community with id: " + this.communityId, error);
|
221
|
},
|
222
|
() => {
|
223
|
this.contentProvidersCalculated = true;
|
224
|
}
|
225
|
);
|
226
|
|
227
|
// this._searchEntriesService.countTotal(this.properties.communityAPI+this.communityId+'/organizations').subscribe(
|
228
|
// organizationTotal => {
|
229
|
// this.organizationTotal = organizationTotal;
|
230
|
// console.log(organizationTotal);
|
231
|
// });
|
232
|
|
233
|
|
234
|
/**/
|
235
|
this.config.getCommunityInformation(this.properties, this.communityId).subscribe(
|
236
|
res => {
|
237
|
this.communityInfo = res;
|
238
|
},
|
239
|
error => {
|
240
|
//console.log(error)
|
241
|
this.handleError("Error getting community with id: " + this.communityId, error);
|
242
|
}
|
243
|
);
|
244
|
}
|
245
|
});
|
246
|
}
|
247
|
|
248
|
public countResearchResults(resultType: string) {
|
249
|
this._searchResearchResultsService.countTotalResults(resultType, this.properties, "&fq=communityid=" + this.communityId).subscribe(
|
250
|
researchResultsTotal => {
|
251
|
this.setTotal(resultType, researchResultsTotal);
|
252
|
if (resultType == "publication") {
|
253
|
//this.searchResearchResults(resultType, this.publicationTotal, this.publicationResults);
|
254
|
}
|
255
|
},
|
256
|
error => {
|
257
|
this.handleError("Error getting number of " + this.getEntityName(resultType, true, true) + " for community with id: " + this.communityId, error);
|
258
|
}
|
259
|
);
|
260
|
}
|
261
|
|
262
|
public searchResearchResults(resultType: string, resultsTotal: number, results: Array<any>) {
|
263
|
this.setActiveTab(resultType);
|
264
|
|
265
|
if (resultsTotal > 0 && results == null) {
|
266
|
this.showLoading = true;
|
267
|
|
268
|
this._searchResearchResultsService.search(resultType, "", "&fq=communityid=" + this.communityId, 1, 5, "resultdateofacceptance,descending", [], this.properties).subscribe(
|
269
|
researchResults => {
|
270
|
this.setResults(resultType, researchResults[1]);
|
271
|
this.showLoading = false;
|
272
|
},
|
273
|
error => {
|
274
|
this.handleError("Error getting " + this.getEntityName(resultType, true, true) + " for community with id: " + this.communityId, error);
|
275
|
}
|
276
|
);
|
277
|
}
|
278
|
}
|
279
|
|
280
|
public ngOnDestroy() {
|
281
|
if (this.piwiksub) {
|
282
|
this.piwiksub.unsubscribe();
|
283
|
}
|
284
|
}
|
285
|
|
286
|
isEntityEnabled(entity: string) {
|
287
|
return this.communityInfo.entities.some(x => x['pid'] == entity && x['isEnabled'] === true);
|
288
|
}
|
289
|
|
290
|
isRouteEnabled(route: string) {
|
291
|
return this.communityInfo.pages.some(x => x['route'] == route && x['isEnabled'] === true);
|
292
|
}
|
293
|
|
294
|
showInvite() {
|
295
|
return this.isManager();
|
296
|
}
|
297
|
|
298
|
isManager() {
|
299
|
if (!this.user) {
|
300
|
return false;
|
301
|
}
|
302
|
var email = this.user.email;
|
303
|
var index = -1;
|
304
|
if (email && this.community != null && this.community.managers != null) {
|
305
|
index = this.community.managers.indexOf(email);
|
306
|
}
|
307
|
return Session.isPortalAdministrator(this.user) || Session.isCommunityCurator(this.user) || index != -1;
|
308
|
}
|
309
|
|
310
|
private handleError(message: string, error) {
|
311
|
console.error("Community (component): " + message, error);
|
312
|
}
|
313
|
|
314
|
getSearchPlaceHolder() {
|
315
|
var entities = [];
|
316
|
if (this.isEntityEnabled("publication")) {
|
317
|
entities.push("publications");
|
318
|
}
|
319
|
if (this.isEntityEnabled("dataset")) {
|
320
|
entities.push("research data");
|
321
|
}
|
322
|
if (this.isEntityEnabled("software")) {
|
323
|
entities.push("software");
|
324
|
}
|
325
|
if (this.isEntityEnabled("orp")) {
|
326
|
entities.push("other research products");
|
327
|
}
|
328
|
return "Search" + ((entities.length > 0) ? (" for " + entities.join(', ') + "...") : "");
|
329
|
}
|
330
|
|
331
|
countOtherGraphs() {
|
332
|
var count = 0;
|
333
|
if (this.statistics && this.statistics.allowedEntities) {
|
334
|
for (var entity of this.statistics.allowedEntities) {
|
335
|
if (this.statistics.statisticsSum[entity].total > 0 && this.statistics.allowedCharts[entity].length > 0 && this.activeTab != entity) {
|
336
|
count += this.statistics.allowedCharts[entity].length;
|
337
|
}
|
338
|
}
|
339
|
}
|
340
|
return count;
|
341
|
}
|
342
|
|
343
|
createParams(param) {
|
344
|
return StringUtils.quote(StringUtils.URIEncode(param));
|
345
|
}
|
346
|
|
347
|
private setActiveTab(entityType: string) {
|
348
|
if (entityType == "other") {
|
349
|
this.activeTab = "orp";
|
350
|
} else {
|
351
|
this.activeTab = entityType;
|
352
|
}
|
353
|
}
|
354
|
|
355
|
private setResults(entityType: string, results: Array<any>) {
|
356
|
if (entityType == "publication") {
|
357
|
this.publicationResults = results;
|
358
|
} else if (entityType == "dataset") {
|
359
|
this.researchDataResults = results;
|
360
|
} else if (entityType == "software") {
|
361
|
this.softwareResults = results;
|
362
|
} else if (entityType == "other") {
|
363
|
this.orpResults = results;
|
364
|
}
|
365
|
}
|
366
|
|
367
|
private setTotal(entityType: string, total: number) {
|
368
|
if (entityType == "publication") {
|
369
|
this.publicationTotal = total;
|
370
|
} else if (entityType == "dataset") {
|
371
|
this.researchDataTotal = total;
|
372
|
} else if (entityType == "software") {
|
373
|
this.softwareTotal = total;
|
374
|
} else if (entityType == "other") {
|
375
|
this.orpTotal = total;
|
376
|
}
|
377
|
}
|
378
|
|
379
|
private getEntityName(entityType: string, plural: boolean, full: boolean): string {
|
380
|
if (entityType == "publication") {
|
381
|
return "publication" + (plural ? "s" : "");
|
382
|
} else if (entityType == "dataset") {
|
383
|
return (full ? "research data" : ("dataset" + (plural ? "s" : "")));
|
384
|
} else if (entityType == "software") {
|
385
|
return "software";
|
386
|
} else if (entityType == "other") {
|
387
|
return (full ? ("other research product" + (plural ? "s" : "")) : "other");
|
388
|
}
|
389
|
}
|
390
|
|
391
|
public buildProjectsAndContentProvidesTooltip(): string {
|
392
|
let tooltipContent: string = "<div class='uk-margin'>";
|
393
|
|
394
|
if(this.projectTotal != null && this.projectTotal > 0 && this.isEntityEnabled('project') && this.isRouteEnabled(this.searchLinkToProjects)) {
|
395
|
tooltipContent += "<span class='uk-text-bold'>Projects</span>";
|
396
|
}
|
397
|
if(this.projectTotal != null && this.projectTotal > 0 && this.isEntityEnabled('project') && this.isRouteEnabled(this.searchLinkToProjects)
|
398
|
&& (this.contentProviderTotal != null && this.contentProviderTotal > 0 && this.isEntityEnabled('datasource') && this.isRouteEnabled(this.searchLinkToDataProviders))) {
|
399
|
tooltipContent += " and ";
|
400
|
}
|
401
|
if(this.contentProviderTotal != null && this.contentProviderTotal > 0 && this.isEntityEnabled('datasource') && this.isRouteEnabled(this.searchLinkToDataProviders)) {
|
402
|
tooltipContent += "<span class='uk-text-bold'>Content Providers</span>";
|
403
|
}
|
404
|
|
405
|
tooltipContent += " have been selected as relevant for your community by the gateway curators.";
|
406
|
tooltipContent += "</div>";
|
407
|
|
408
|
return tooltipContent;
|
409
|
}
|
410
|
|
411
|
public buildZenodoCommunitiesTooltip(): string {
|
412
|
let tooltipContent: string = "<div class='uk-margin'>";
|
413
|
|
414
|
tooltipContent += "<span class='uk-text-bold'>Zenodo</span> is a catch-all repository for OpenAIRE.";
|
415
|
tooltipContent += "<div class='uk-margin-small-top'>A <span class='uk-text-bold'>Zenodo Community</span> is created and curated by Zenodo users.</div>";
|
416
|
tooltipContent += "</div>";
|
417
|
return tooltipContent;
|
418
|
}
|
419
|
|
420
|
entityChanged($event){
|
421
|
this.selectedEntity = $event.entity;
|
422
|
this.selectedEntitySimpleUrl = $event.simpleUrl;
|
423
|
this.selectedEntityAdvancedUrl = $event.advancedUrl;
|
424
|
if(this.selectedEntity == 'result'){
|
425
|
this.placeholderText ="Search by title, author, abstract, DOI, orcid... ";
|
426
|
}else if(this.selectedEntity == 'project') {
|
427
|
this.placeholderText = "Search by project title, grant id, funder...";
|
428
|
}else if(this.selectedEntity == 'dataprovider') {
|
429
|
this.placeholderText = "Search by name...";
|
430
|
}else{
|
431
|
this.placeholderText = "Search community content";
|
432
|
}
|
433
|
}
|
434
|
|
435
|
goTo(simple:boolean){
|
436
|
let url = (simple)?this.selectedEntitySimpleUrl:this.selectedEntityAdvancedUrl;
|
437
|
let parameterNames = [];
|
438
|
let parameterValues = [];
|
439
|
if (this.selectedEntity == "result") {
|
440
|
/* if (this.resultTypes) {
|
441
|
let values = [];
|
442
|
if (this.resultTypes.publication) {
|
443
|
values.push("publications");
|
444
|
}
|
445
|
if (this.resultTypes.dataset) {
|
446
|
values.push("datasets");
|
447
|
}
|
448
|
if (this.resultTypes.software) {
|
449
|
values.push("software");
|
450
|
}
|
451
|
if (this.resultTypes.other) {
|
452
|
values.push("other");
|
453
|
}
|
454
|
if (values.length > 0) {
|
455
|
parameterNames.push("type");
|
456
|
parameterValues.push(values.join(","));
|
457
|
}
|
458
|
if (this.resultsQuickFilter) {
|
459
|
parameterNames.push("qf");
|
460
|
parameterValues.push("" + this.resultsQuickFilter.selected);
|
461
|
}
|
462
|
}*/
|
463
|
}
|
464
|
if(this.keyword.length > 0) {
|
465
|
parameterNames.push("q");
|
466
|
parameterValues.push(this.keyword);
|
467
|
parameterNames.push("op");
|
468
|
parameterValues.push("and");
|
469
|
}
|
470
|
this._router.navigate([url], {queryParams: this.routerHelper.createQueryParams(parameterNames, parameterValues)});
|
471
|
}
|
472
|
|
473
|
public countSubscribersEvent($event){
|
474
|
this.subscribers = $event.value;
|
475
|
}
|
476
|
}
|