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
|
|
25
|
@Component({
|
26
|
selector: 'community',
|
27
|
templateUrl: 'community.component.html',
|
28
|
})
|
29
|
|
30
|
export class CommunityComponent {
|
31
|
public url: string = null;
|
32
|
|
33
|
public sub: any;
|
34
|
public piwiksub: any;
|
35
|
public subfunders: any;
|
36
|
|
37
|
public publicationTotal = null;
|
38
|
public researchDataTotal = null;
|
39
|
public softwareTotal = null;
|
40
|
public orpTotal = null;
|
41
|
public projectTotal = null;
|
42
|
public contentProviderTotal = null;
|
43
|
public organizationTotal = null;
|
44
|
|
45
|
params: any = {};
|
46
|
properties: EnvProperties;
|
47
|
|
48
|
public publicationResults = null;
|
49
|
public researchDataResults = null;
|
50
|
public softwareResults = null;
|
51
|
public orpResults = null;
|
52
|
|
53
|
@Input() communityId = null;
|
54
|
public community = null;
|
55
|
|
56
|
public communityInfo = null;
|
57
|
|
58
|
public showLoading: boolean = true;
|
59
|
masterZenodoCommunity = null;
|
60
|
zenodoCommunityIdS = [];
|
61
|
showAllSubjects = false;
|
62
|
showAllDescription = false;
|
63
|
// TODO Unsubscribe
|
64
|
public subPublications;
|
65
|
public subResearchData;
|
66
|
public subSoftware;
|
67
|
public subOrps;
|
68
|
@ViewChild(StatisticsForDashboardComponent) statistics: StatisticsForDashboardComponent = null;
|
69
|
public activeTab = "publication";
|
70
|
public show: string = 'overview';
|
71
|
|
72
|
searchLinkToPublications: string = null;
|
73
|
searchLinkToDatasets: string = null;
|
74
|
searchLinkToSoftware: string = null;
|
75
|
searchLinkToOrps: string = null;
|
76
|
searchLinkToProjects: string = null;
|
77
|
searchLinkToDataProviders: string = null;
|
78
|
searchLinkToAdvancedPublications: string = null;
|
79
|
shareInZenodoPage: string = null;
|
80
|
public routerHelper: RouterHelper = new RouterHelper();
|
81
|
private user: User;
|
82
|
private loginCheck: boolean = false;
|
83
|
|
84
|
constructor(
|
85
|
private element: ElementRef,
|
86
|
private route: ActivatedRoute,
|
87
|
private _router: Router,
|
88
|
private location: Location,
|
89
|
private _meta: Meta,
|
90
|
private _title: Title,
|
91
|
private _piwikService: PiwikService,
|
92
|
private config: ConfigurationService,
|
93
|
private _communityService: CommunityService,
|
94
|
private _searchCommunityDataprovidersService: SearchCommunityDataprovidersService,
|
95
|
private _searchCommunityProjectsService: SearchCommunityProjectsService,
|
96
|
private _searchResearchResultsService: SearchResearchResultsService,
|
97
|
private _searchZenodoCommunitiesService: SearchZenodoCommunitiesService,
|
98
|
private _ΖenodoCommunitieService: ZenodoCommunitiesService,
|
99
|
private seoService: SEOService,
|
100
|
private userManagementService: UserManagementService) {
|
101
|
|
102
|
var description = "OpenAIRE - Connect, Community Dashboard, research community";
|
103
|
var title = "OpenAIRE - Connect";
|
104
|
this._meta.updateTag({content: description}, "name='description'");
|
105
|
this._meta.updateTag({content: description}, "property='og:description'");
|
106
|
this._meta.updateTag({content: title}, "property='og:title'");
|
107
|
this._title.setTitle(title);
|
108
|
|
109
|
}
|
110
|
|
111
|
public ngOnInit() {
|
112
|
this.route.data
|
113
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
114
|
this.properties = data.envSpecific;
|
115
|
this.searchLinkToPublications = this.properties.searchLinkToPublications;
|
116
|
this.searchLinkToDatasets = this.properties.searchLinkToDatasets;
|
117
|
this.searchLinkToSoftware = this.properties.searchLinkToSoftware;
|
118
|
this.searchLinkToOrps = this.properties.searchLinkToOrps;
|
119
|
this.searchLinkToProjects = this.properties.searchLinkToProjects;
|
120
|
this.searchLinkToDataProviders = this.properties.searchLinkToDataProviders;
|
121
|
this.searchLinkToAdvancedPublications = this.properties.searchLinkToAdvancedPublications;
|
122
|
this.shareInZenodoPage = this.properties.shareInZenodoPage;
|
123
|
this.url = data.envSpecific.baseLink + this._router.url;
|
124
|
this.seoService.createLinkForCanonicalURL(this.url, false);
|
125
|
this._meta.updateTag({content: this.url}, "property='og:url'");
|
126
|
this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
|
127
|
this.user = user;
|
128
|
this.loginCheck = true;
|
129
|
});
|
130
|
if (this.communityId != null && this.communityId != '') {
|
131
|
this._communityService.getCommunity(this.properties, this.properties.communityAPI + this.communityId).subscribe(
|
132
|
community => {
|
133
|
if (typeof document !== 'undefined') {
|
134
|
HelperFunctions.scroll();
|
135
|
}
|
136
|
this.community = community;
|
137
|
if (this.properties.environment == "development") {
|
138
|
this.params = {communityId: community.communityId};
|
139
|
}
|
140
|
this._meta.updateTag({content: community.description}, "name='description'");
|
141
|
this._meta.updateTag({content: community.description}, "property='og:description'");
|
142
|
this._meta.updateTag({content: community.title}, "property='og:title'");
|
143
|
this._title.setTitle(community.title);
|
144
|
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
|
145
|
this.piwiksub = this._piwikService.trackView(this.properties, community.title, PiwikHelper.getSiteId(this.communityId, this.properties.environment)).subscribe();
|
146
|
}
|
147
|
if (this.community.zenodoCommunity) {
|
148
|
this._ΖenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities + this.community.zenodoCommunity, null).subscribe(
|
149
|
result => {
|
150
|
this.masterZenodoCommunity = result;
|
151
|
|
152
|
},
|
153
|
error => {
|
154
|
// var emptyCommunity:ZenodoCommunityInfo = new ZenodoCommunityInfo();
|
155
|
// emptyCommunity.id = this.masterZenodoCommunityId;
|
156
|
// emptyCommunity.title = this.masterZenodoCommunityId;
|
157
|
// this.masterZenodoCommunity = emptyCommunity;
|
158
|
//console.log("Master Zenodo community'" + this.community.zenodoCommunity + "' couldn't be loaded");
|
159
|
this.handleError("Error getting Master Zenodo community with id: " + this.community.zenodoCommunityId, error);
|
160
|
|
161
|
}
|
162
|
);
|
163
|
}
|
164
|
this._searchZenodoCommunitiesService.searchZCommunities(this.properties, this.communityId).subscribe(
|
165
|
result => {
|
166
|
this.zenodoCommunityIdS = result;
|
167
|
|
168
|
|
169
|
},
|
170
|
error => {
|
171
|
//console.error("list of zenodo communities couldn't be loaded");
|
172
|
this.handleError("Error getting list of zenodo communities for community with openaire id: " + this.communityId, error);
|
173
|
} //this.handleError('System error retrieving community profile', error)
|
174
|
);
|
175
|
|
176
|
//console.log(community);
|
177
|
});
|
178
|
|
179
|
this.countResearchResults("publication");
|
180
|
this.countResearchResults("dataset");
|
181
|
this.countResearchResults("software");
|
182
|
this.countResearchResults("other");
|
183
|
|
184
|
this._searchCommunityProjectsService.countTotalProjects(this.properties, this.communityId).subscribe(
|
185
|
projectTotal => {
|
186
|
this.projectTotal = projectTotal;
|
187
|
//console.log(projectTotal);
|
188
|
},
|
189
|
error => {
|
190
|
this.handleError("Error getting number of projects for community with id: " + this.communityId, error);
|
191
|
}
|
192
|
);
|
193
|
|
194
|
this._searchCommunityDataprovidersService.countTotalDataproviders(this.properties, this.communityId).subscribe(
|
195
|
contentProviderTotal => {
|
196
|
this.contentProviderTotal = contentProviderTotal;
|
197
|
//console.log(contentProviderTotal);
|
198
|
},
|
199
|
error => {
|
200
|
this.handleError("Error getting number of content providers for community with id: " + this.communityId, error);
|
201
|
}
|
202
|
);
|
203
|
|
204
|
// this._searchEntriesService.countTotal(this.properties.communityAPI+this.communityId+'/organizations').subscribe(
|
205
|
// organizationTotal => {
|
206
|
// this.organizationTotal = organizationTotal;
|
207
|
// console.log(organizationTotal);
|
208
|
// });
|
209
|
|
210
|
|
211
|
/**/
|
212
|
this.config.getCommunityInformation(this.properties, this.communityId).subscribe(
|
213
|
res => {
|
214
|
this.communityInfo = res;
|
215
|
},
|
216
|
error => {
|
217
|
//console.log(error)
|
218
|
this.handleError("Error getting community with id: " + this.communityId, error);
|
219
|
}
|
220
|
);
|
221
|
}
|
222
|
});
|
223
|
}
|
224
|
|
225
|
public countResearchResults(resultType: string) {
|
226
|
this._searchResearchResultsService.countTotalResults(resultType, this.properties, "&fq=communityid=" + this.communityId).subscribe(
|
227
|
researchResultsTotal => {
|
228
|
this.setTotal(resultType, researchResultsTotal);
|
229
|
if (resultType == "publication") {
|
230
|
this.searchResearchResults(resultType, this.publicationTotal, this.publicationResults);
|
231
|
}
|
232
|
},
|
233
|
error => {
|
234
|
this.handleError("Error getting number of " + this.getEntityName(resultType, true, true) + " for community with id: " + this.communityId, error);
|
235
|
}
|
236
|
);
|
237
|
}
|
238
|
|
239
|
public searchResearchResults(resultType: string, resultsTotal: number, results: Array<any>) {
|
240
|
this.setActiveTab(resultType);
|
241
|
|
242
|
if (resultsTotal > 0 && results == null) {
|
243
|
this.showLoading = true;
|
244
|
|
245
|
this._searchResearchResultsService.search(resultType, "", "&fq=communityid=" + this.communityId, 1, 5, "resultdateofacceptance,descending", [], this.properties).subscribe(
|
246
|
researchResults => {
|
247
|
this.setResults(resultType, researchResults[1]);
|
248
|
this.showLoading = false;
|
249
|
},
|
250
|
error => {
|
251
|
this.handleError("Error getting " + this.getEntityName(resultType, true, true) + " for community with id: " + this.communityId, error);
|
252
|
}
|
253
|
);
|
254
|
}
|
255
|
}
|
256
|
|
257
|
public ngOnDestroy() {
|
258
|
if (this.piwiksub) {
|
259
|
this.piwiksub.unsubscribe();
|
260
|
}
|
261
|
}
|
262
|
|
263
|
isEntityEnabled(entity: string) {
|
264
|
return this.communityInfo.entities.some(x => x['pid'] == entity && x['isEnabled'] === true);
|
265
|
}
|
266
|
|
267
|
isRouteEnabled(route: string) {
|
268
|
return this.communityInfo.pages.some(x => x['route'] == route && x['isEnabled'] === true);
|
269
|
}
|
270
|
|
271
|
showInvite() {
|
272
|
return this.loginCheck && this.isManager();
|
273
|
}
|
274
|
|
275
|
isManager() {
|
276
|
if (!this.user) {
|
277
|
return false;
|
278
|
}
|
279
|
var email = this.user.email;
|
280
|
var index = -1;
|
281
|
if (email && this.community != null && this.community.managers != null) {
|
282
|
index = this.community.managers.indexOf(email);
|
283
|
}
|
284
|
return Session.isPortalAdministrator(this.user) || Session.isCommunityCurator(this.user) || index != -1;
|
285
|
}
|
286
|
|
287
|
private handleError(message: string, error) {
|
288
|
console.error("Community (component): " + message, error);
|
289
|
}
|
290
|
|
291
|
getSearchPlaceHolder() {
|
292
|
var entities = [];
|
293
|
if (this.isEntityEnabled("publication")) {
|
294
|
entities.push("publications");
|
295
|
}
|
296
|
if (this.isEntityEnabled("dataset")) {
|
297
|
entities.push("research data");
|
298
|
}
|
299
|
if (this.isEntityEnabled("software")) {
|
300
|
entities.push("software");
|
301
|
}
|
302
|
if (this.isEntityEnabled("orp")) {
|
303
|
entities.push("other research products");
|
304
|
}
|
305
|
return "Search" + ((entities.length > 0) ? (" for " + entities.join(', ') + "...") : "");
|
306
|
}
|
307
|
|
308
|
countOtherGraphs() {
|
309
|
var count = 0;
|
310
|
if (this.statistics && this.statistics.allowedEntities) {
|
311
|
for (var entity of this.statistics.allowedEntities) {
|
312
|
if (this.statistics.statisticsSum[entity].total > 0 && this.statistics.allowedCharts[entity].length > 0 && this.activeTab != entity) {
|
313
|
count += this.statistics.allowedCharts[entity].length;
|
314
|
}
|
315
|
}
|
316
|
}
|
317
|
return count;
|
318
|
}
|
319
|
|
320
|
createParams(param) {
|
321
|
return StringUtils.quote(StringUtils.URIEncode(param));
|
322
|
}
|
323
|
|
324
|
private setActiveTab(entityType: string) {
|
325
|
if (entityType == "other") {
|
326
|
this.activeTab = "orp";
|
327
|
} else {
|
328
|
this.activeTab = entityType;
|
329
|
}
|
330
|
}
|
331
|
|
332
|
private setResults(entityType: string, results: Array<any>) {
|
333
|
if (entityType == "publication") {
|
334
|
this.publicationResults = results;
|
335
|
} else if (entityType == "dataset") {
|
336
|
this.researchDataResults = results;
|
337
|
} else if (entityType == "software") {
|
338
|
this.softwareResults = results;
|
339
|
} else if (entityType == "other") {
|
340
|
this.orpResults = results;
|
341
|
}
|
342
|
}
|
343
|
|
344
|
private setTotal(entityType: string, total: number) {
|
345
|
if (entityType == "publication") {
|
346
|
this.publicationTotal = total;
|
347
|
} else if (entityType == "dataset") {
|
348
|
this.researchDataTotal = total;
|
349
|
} else if (entityType == "software") {
|
350
|
this.softwareTotal = total;
|
351
|
} else if (entityType == "other") {
|
352
|
this.orpTotal = total;
|
353
|
}
|
354
|
}
|
355
|
|
356
|
private getEntityName(entityType: string, plural: boolean, full: boolean): string {
|
357
|
if (entityType == "publication") {
|
358
|
return "publication" + (plural ? "s" : "");
|
359
|
} else if (entityType == "dataset") {
|
360
|
return (full ? "research data" : ("dataset" + (plural ? "s" : "")));
|
361
|
} else if (entityType == "software") {
|
362
|
return "software";
|
363
|
} else if (entityType == "other") {
|
364
|
return (full ? ("other research product" + (plural ? "s" : "")) : "other");
|
365
|
}
|
366
|
}
|
367
|
}
|