1
|
import {Component, Input, Output, ElementRef} from '@angular/core';
|
2
|
import {EventEmitter, ViewChild} from '@angular/core';
|
3
|
import {ChangeDetectionStrategy} from '@angular/core';
|
4
|
import {ViewEncapsulation} from '@angular/core';
|
5
|
import {ActivatedRoute, Router} from '@angular/router';
|
6
|
import {Location} from '@angular/common';
|
7
|
import {Title, Meta} from '@angular/platform-browser';
|
8
|
|
9
|
import {Observable} from 'rxjs/Observable';
|
10
|
|
11
|
import "rxjs/add/observable/zip";
|
12
|
|
13
|
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
|
14
|
import {ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes';
|
15
|
|
16
|
import {CommunityService} from "../openaireLibrary/connect/community/community.service";
|
17
|
import {ConfigurationService} from '../openaireLibrary/utils/configuration/configuration.service';
|
18
|
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
|
19
|
import {SearchEntriesService} from '../searchEntries/searchEntries.service';
|
20
|
import {SearchZenodoCommunitiesService} from '../openaireLibrary/connect/zenodoCommunities/searchZenodoCommunities.service';
|
21
|
import {ZenodoCommunitiesService} from '../openaireLibrary/connect/zenodoCommunities/zenodo-communities.service';
|
22
|
import {Session} from '../openaireLibrary/login/utils/helper.class';
|
23
|
import {StatisticsForDashboardComponent} from '../statistics/statistics.component';
|
24
|
|
25
|
import {PiwikHelper} from '../utils/piwikHelper';
|
26
|
@Component({
|
27
|
selector: 'community',
|
28
|
templateUrl: 'community.component.html',
|
29
|
})
|
30
|
|
31
|
export class CommunityComponent {
|
32
|
public sub: any;
|
33
|
public piwiksub: any;
|
34
|
public subfunders: any;
|
35
|
|
36
|
public publicationTotal = null;
|
37
|
public researchDataTotal = null;
|
38
|
public softwareTotal = null;
|
39
|
public orpTotal = null;
|
40
|
public projectTotal = null;
|
41
|
public contentProviderTotal = null;
|
42
|
public organizationTotal = null;
|
43
|
|
44
|
params: any ={};
|
45
|
properties:EnvProperties;
|
46
|
|
47
|
public publicationResults = null;
|
48
|
public researchDataResults = null;
|
49
|
public softwareResults = null;
|
50
|
public orpResults = null;
|
51
|
|
52
|
@Input() communityId = null;
|
53
|
public community = null;
|
54
|
|
55
|
public communityInfo = null;
|
56
|
|
57
|
public showLoading: boolean = true;
|
58
|
masterZenodoCommunity = null;
|
59
|
zenodoCommunityIdS = [];
|
60
|
|
61
|
// TODO Unsubscribe
|
62
|
public subPublications;
|
63
|
public subResearchData;
|
64
|
public subSoftware;
|
65
|
public subOrps;
|
66
|
@ViewChild (StatisticsForDashboardComponent) statistics : StatisticsForDashboardComponent =null;
|
67
|
public activeTab = "publication";
|
68
|
constructor (
|
69
|
private element: ElementRef,
|
70
|
private route: ActivatedRoute,
|
71
|
private _router: Router,
|
72
|
private location: Location,
|
73
|
private _meta: Meta,
|
74
|
private _title: Title,
|
75
|
private _piwikService:PiwikService,
|
76
|
private config: ConfigurationService,
|
77
|
private _communityService:CommunityService,
|
78
|
private _searchEntriesService:SearchEntriesService,
|
79
|
private _searchZenodoCommunitiesService: SearchZenodoCommunitiesService,
|
80
|
private _ΖenodoCommunitieService: ZenodoCommunitiesService) {
|
81
|
|
82
|
var description = "OpenAIRE - Connect, Community Dashboard, research community";
|
83
|
var title = "OpenAIRE - Connect";
|
84
|
this._meta.updateTag({content:description},"name='description'");
|
85
|
this._meta.updateTag({content:description},"property='og:description'");
|
86
|
this._meta.updateTag({content:title},"property='og:title'");
|
87
|
this._title.setTitle(title);
|
88
|
|
89
|
}
|
90
|
|
91
|
public ngOnInit() {
|
92
|
this.route.data
|
93
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
94
|
this.properties = data.envSpecific;
|
95
|
var url = data.envSpecific.baseLink+this._router.url;
|
96
|
this._meta.updateTag({content:url},"property='og:url'");
|
97
|
|
98
|
if (this.communityId != null && this.communityId != '') {
|
99
|
this._communityService.getCommunity(this.properties, this.properties.communityAPI+this.communityId).subscribe (
|
100
|
community => {
|
101
|
this.community = community;
|
102
|
if(this.properties.environment == "development"){
|
103
|
this.params = {communityId: community.communityId};
|
104
|
}
|
105
|
this._meta.updateTag({content:community.description},"name='description'");
|
106
|
this._meta.updateTag({content:community.description},"property='og:description'");
|
107
|
this._meta.updateTag({content:community.title},"property='og:title'");
|
108
|
this._title.setTitle(community.title);
|
109
|
if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
|
110
|
this.piwiksub = this._piwikService.trackView(this.properties, community.title,PiwikHelper.siteIDs[this.communityId]).subscribe();
|
111
|
}
|
112
|
if(this.community.zenodoCommunity){
|
113
|
this._ΖenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities+this.community.zenodoCommunity, null).subscribe(
|
114
|
result => {
|
115
|
this.masterZenodoCommunity = result;
|
116
|
|
117
|
},
|
118
|
error => {
|
119
|
// var emptyCommunity:ZenodoCommunityInfo = new ZenodoCommunityInfo();
|
120
|
// emptyCommunity.id = this.masterZenodoCommunityId;
|
121
|
// emptyCommunity.title = this.masterZenodoCommunityId;
|
122
|
// this.masterZenodoCommunity = emptyCommunity;
|
123
|
//console.log("Master Zenodo community'" + this.community.zenodoCommunity + "' couldn't be loaded");
|
124
|
this.handleError("Error getting Master Zenodo community with id: "+this.community.zenodoCommunityId, error);
|
125
|
|
126
|
}
|
127
|
);
|
128
|
}
|
129
|
this._searchZenodoCommunitiesService.searchZCommunities(this.properties,this.communityId).subscribe (
|
130
|
result => {
|
131
|
this.zenodoCommunityIdS = result;
|
132
|
|
133
|
|
134
|
|
135
|
},
|
136
|
error => {
|
137
|
//console.error("list of zenodo communities couldn't be loaded");
|
138
|
this.handleError("Error getting list of zenodo communities for community with openaire id: "+this.communityId, error);
|
139
|
} //this.handleError('System error retrieving community profile', error)
|
140
|
);
|
141
|
|
142
|
//console.log(community);
|
143
|
});
|
144
|
|
145
|
|
146
|
|
147
|
this._searchEntriesService.getTotal(this.properties.searchAPIURLLAst+'publications/count?format=json&fq=communityid='+this.communityId).subscribe(
|
148
|
publicationTotal => {
|
149
|
this.publicationTotal = publicationTotal;
|
150
|
this.showLoading = true;
|
151
|
this.searchPublications();
|
152
|
},
|
153
|
error => {
|
154
|
this.handleError("Error getting number of publications for community with id: "+this.communityId, error);
|
155
|
}
|
156
|
);
|
157
|
|
158
|
this._searchEntriesService.getTotal(this.properties.searchAPIURLLAst+'datasets/count?format=json&fq=communityid='+this.communityId).subscribe(
|
159
|
researchDataTotal => {
|
160
|
this.researchDataTotal = researchDataTotal;
|
161
|
},
|
162
|
error => {
|
163
|
this.handleError("Error getting number of research data for community with id: "+this.communityId, error);
|
164
|
}
|
165
|
);
|
166
|
|
167
|
this._searchEntriesService.getTotal(this.properties.searchAPIURLLAst+'software/count?format=json&fq=communityid='+this.communityId).subscribe(
|
168
|
softwareTotal => {
|
169
|
this.softwareTotal = softwareTotal;
|
170
|
},
|
171
|
error => {
|
172
|
this.handleError("Error getting number of software for community with id: "+this.communityId, error);
|
173
|
}
|
174
|
);
|
175
|
|
176
|
this._searchEntriesService.getTotal(this.properties.searchAPIURLLAst+'other/count?format=json&fq=communityid='+this.communityId).subscribe(
|
177
|
orpTotal => {
|
178
|
this.orpTotal = orpTotal;
|
179
|
},
|
180
|
error => {
|
181
|
this.handleError("Error getting number of other research products for community with id: "+this.communityId, error);
|
182
|
}
|
183
|
);
|
184
|
|
185
|
this._searchEntriesService.countTotal(this.properties.communityAPI+this.communityId+'/projects').subscribe(
|
186
|
projectTotal => {
|
187
|
this.projectTotal = projectTotal;
|
188
|
//console.log(projectTotal);
|
189
|
},
|
190
|
error => {
|
191
|
this.handleError("Error getting number of projects for community with id: "+this.communityId, error);
|
192
|
}
|
193
|
);
|
194
|
|
195
|
this._searchEntriesService.countTotal(this.properties.communityAPI+this.communityId+'/contentproviders').subscribe(
|
196
|
contentProviderTotal => {
|
197
|
this.contentProviderTotal = contentProviderTotal;
|
198
|
//console.log(contentProviderTotal);
|
199
|
},
|
200
|
error => {
|
201
|
this.handleError("Error getting number of content providers for community with id: "+this.communityId, error);
|
202
|
}
|
203
|
);
|
204
|
|
205
|
// this._searchEntriesService.countTotal(this.properties.communityAPI+this.communityId+'/organizations').subscribe(
|
206
|
// organizationTotal => {
|
207
|
// this.organizationTotal = organizationTotal;
|
208
|
// console.log(organizationTotal);
|
209
|
// });
|
210
|
|
211
|
|
212
|
/**/
|
213
|
this.config.getCommunityInformation(this.properties.adminToolsAPIURL, this.communityId).subscribe(
|
214
|
res => {
|
215
|
this.communityInfo = res;
|
216
|
},
|
217
|
error => {
|
218
|
//console.log(error)
|
219
|
this.handleError("Error getting community with id: "+this.communityId, error);
|
220
|
}
|
221
|
);
|
222
|
}
|
223
|
});
|
224
|
// if (typeof document !== 'undefined') {
|
225
|
// this.element.nativeElement.scrollIntoView();
|
226
|
// }
|
227
|
}
|
228
|
|
229
|
public searchPublications() {
|
230
|
this.activeTab = "publication";
|
231
|
if (this.publicationTotal > 0 && this.publicationResults == null) {
|
232
|
this._searchEntriesService.getResults(this.properties.searchAPIURLLAst+'publications?fq=communityid%20exact%20%22'+this.communityId+'%22&sortBy=resultdateofacceptance,descending&format=json&size=5').subscribe(
|
233
|
publicationResults => {
|
234
|
this.publicationResults = publicationResults;
|
235
|
this.showLoading = false;
|
236
|
//console.log(publicationResults);
|
237
|
},
|
238
|
error => {
|
239
|
this.handleError("Error getting publications for community with id: "+this.communityId, error);
|
240
|
}
|
241
|
);
|
242
|
}
|
243
|
}
|
244
|
|
245
|
public searchResearchData() {
|
246
|
this.activeTab = "dataset";
|
247
|
if (this.researchDataTotal > 0 && this.researchDataResults == null) {
|
248
|
this._searchEntriesService.getResults(this.properties.searchAPIURLLAst+'datasets?fq=communityid%20exact%20%22'+this.communityId+'%22&sortBy=resultdateofacceptance,descending&format=json&size=5').subscribe(
|
249
|
researchDataResults => {
|
250
|
this.researchDataResults = researchDataResults;
|
251
|
this.showLoading = false;
|
252
|
},
|
253
|
error => {
|
254
|
this.handleError("Error getting research data for community with id: "+this.communityId, error);
|
255
|
}
|
256
|
);
|
257
|
}
|
258
|
}
|
259
|
|
260
|
public searchSoftware() {
|
261
|
this.activeTab = "software";
|
262
|
if (this.softwareTotal > 0 && this.softwareResults == null) {
|
263
|
this._searchEntriesService.getResults(this.properties.searchAPIURLLAst+'software?fq=communityid%20exact%20%22'+this.communityId+'%22&sortBy=resultdateofacceptance,descending&format=json&size=5').subscribe(
|
264
|
softwareResults => {
|
265
|
this.softwareResults = softwareResults;
|
266
|
this.showLoading = false;
|
267
|
},
|
268
|
error => {
|
269
|
this.handleError("Error getting software for community with id: "+this.communityId, error);
|
270
|
}
|
271
|
);
|
272
|
}
|
273
|
}
|
274
|
|
275
|
public searchOrps() {
|
276
|
this.activeTab = "orp";
|
277
|
if (this.orpTotal > 0 && this.orpResults == null) {
|
278
|
this._searchEntriesService.getResults(this.properties.searchAPIURLLAst+'other?fq=communityid%20exact%20%22'+this.communityId+'%22&sortBy=resultdateofacceptance,descending&format=json&size=5').subscribe(
|
279
|
orpResults => {
|
280
|
this.orpResults = orpResults;
|
281
|
this.showLoading = false;
|
282
|
},
|
283
|
error => {
|
284
|
this.handleError("Error getting other research products for community with id: "+this.communityId, error);
|
285
|
}
|
286
|
);
|
287
|
}
|
288
|
}
|
289
|
|
290
|
public ngOnDestroy() {
|
291
|
if(this.piwiksub){
|
292
|
this.piwiksub.unsubscribe();
|
293
|
}
|
294
|
}
|
295
|
|
296
|
isEntityEnabled(entity: string) {
|
297
|
return this.communityInfo.entities.some(x => x['pid'] == entity && x['isEnabled']===true);
|
298
|
}
|
299
|
isRouteEnabled(route: string) {
|
300
|
return this.communityInfo.pages.some(x => x['route'] == route && x['isEnabled']===true);
|
301
|
}
|
302
|
showInvite(){
|
303
|
// console.log(Session.isPortalAdministrator() + Session.isCommunityCurator())
|
304
|
var email = Session.getUserEmail();
|
305
|
var index =-1;
|
306
|
if(email && this.community != null && this.community.managers != null){
|
307
|
index = this.community.managers.indexOf(email);
|
308
|
}
|
309
|
|
310
|
return Session.isPortalAdministrator() || Session.isCommunityCurator() || index != -1;
|
311
|
}
|
312
|
|
313
|
private handleError(message: string, error) {
|
314
|
console.error("Community (component): "+message, error);
|
315
|
}
|
316
|
|
317
|
getSearchPlaceHolder(){
|
318
|
var entities = [];
|
319
|
if(this.isEntityEnabled("publication")){
|
320
|
entities.push("publications");
|
321
|
}
|
322
|
if(this.isEntityEnabled("dataset")){
|
323
|
entities.push("research data");
|
324
|
}
|
325
|
if(this.isEntityEnabled("software")){
|
326
|
entities.push("software");
|
327
|
}
|
328
|
if(this.isEntityEnabled("orp")){
|
329
|
entities.push("other research products");
|
330
|
}
|
331
|
return "Search"+ ((entities.length > 0 )?(" for "+entities.join(', ')+"..."):"");
|
332
|
}
|
333
|
|
334
|
countOtherGraphs(){
|
335
|
var count = 0;
|
336
|
if(this.statistics && this.statistics.allowedEntities){
|
337
|
for(var entity of this.statistics.allowedEntities){
|
338
|
if(this.statistics.statisticsSum[entity].total>0 && this.statistics.allowedCharts[entity].length>0 && this.activeTab!=entity){
|
339
|
count+=this.statistics.allowedCharts[entity].length;
|
340
|
}
|
341
|
}
|
342
|
}
|
343
|
return count;
|
344
|
}
|
345
|
|
346
|
|
347
|
}
|