Project

General

Profile

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
  public analyticsActiveTab = "";
82

    
83
  searchLinkToResults: string = null;
84

    
85
  searchLinkToProjects: string = null;
86
  searchLinkToDataProviders: string = null;
87
  searchLinkToAdvancedResults: string = null;
88
  shareInZenodoPage: string = null;
89
  public routerHelper: RouterHelper = new RouterHelper();
90
  private user: User;
91

    
92
  @ViewChild(SubscribeComponent) subscribeComponent: SubscribeComponent = null;
93
//Search Form
94
  selectedEntity;
95
  selectedEntitySimpleUrl;
96
  selectedEntityAdvancedUrl;
97
  keyword:string ="";
98
  customFilter;
99
  placeholderText="Search by title, author, abstract, DOI, orcid... ";
100

    
101
  constructor(
102
    private element: ElementRef,
103
    private route: ActivatedRoute,
104
    private _router: Router,
105
    private location: Location,
106
    private _meta: Meta,
107
    private _title: Title,
108
    private _piwikService: PiwikService,
109
    private config: ConfigurationService,
110
    private _communityService: CommunityService,
111
    private _searchCommunityDataprovidersService: SearchCommunityDataprovidersService,
112
    private _searchCommunityProjectsService: SearchCommunityProjectsService,
113
    private _searchResearchResultsService: SearchResearchResultsService,
114
    private _searchZenodoCommunitiesService: SearchZenodoCommunitiesService,
115
    private _ΖenodoCommunitieService: ZenodoCommunitiesService,
116
    private seoService: SEOService,
117
    private userManagementService: UserManagementService) {
118

    
119
    var description = "OpenAIRE - Connect, Community Dashboard, research community";
120
    var title = "OpenAIRE - Connect";
121
    this._meta.updateTag({content: description}, "name='description'");
122
    this._meta.updateTag({content: description}, "property='og:description'");
123
    this._meta.updateTag({content: title}, "property='og:title'");
124
    this._title.setTitle(title);
125

    
126
  }
127

    
128
  public ngOnInit() {
129
    this.route.data
130
      .subscribe((data: { envSpecific: EnvProperties }) => {
131
        this.properties = data.envSpecific;
132
        this.searchLinkToResults = this.properties.searchLinkToResults;
133
        this.searchLinkToProjects = this.properties.searchLinkToProjects;
134
        this.searchLinkToDataProviders = this.properties.searchLinkToDataProviders;
135
        this.searchLinkToAdvancedResults = this.properties.searchLinkToAdvancedResults;
136
        this.shareInZenodoPage = this.properties.shareInZenodoPage;
137
        this.url = data.envSpecific.baseLink + this._router.url;
138
        this.seoService.createLinkForCanonicalURL(this.url, false);
139
        this._meta.updateTag({content: this.url}, "property='og:url'");
140
        this.userManagementService.getUserInfo().subscribe(user => {
141
          this.user = user;
142
        });
143
        if (this.communityId != null && this.communityId != '') {
144
          this.customFilter = new SearchCustomFilter("Community", "communityId", this.communityId, "");
145
          this._communityService.getCommunity(this.properties, this.properties.communityAPI + this.communityId).subscribe(
146
            community => {
147
              if (typeof document !== 'undefined') {
148
                HelperFunctions.scroll();
149
              }
150
              this.community = community;
151
              if(community.description != null && (community.description.length - this.thresholdDescription <= this.descriptionDiff)) {
152
                this.thresholdDescription = community.description.length;
153
              }
154

    
155
              if (this.properties.environment == "development") {
156
                this.params = {communityId: community.communityId};
157
              }
158
              this._meta.updateTag({content: community.description}, "name='description'");
159
              this._meta.updateTag({content: community.description}, "property='og:description'");
160
              this._meta.updateTag({content: community.title}, "property='og:title'");
161
              this._title.setTitle(community.title);
162
              if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
163
                this.piwiksub = this._piwikService.trackView(this.properties, community.title, PiwikHelper.getSiteId(this.communityId, this.properties.environment)).subscribe();
164
              }
165
              if (this.community.zenodoCommunity) {
166
                this._ΖenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities + this.community.zenodoCommunity, null).subscribe(
167
                  result => {
168
                    this.masterZenodoCommunity = result;
169

    
170
                  },
171
                  error => {
172
                    // var emptyCommunity:ZenodoCommunityInfo = new ZenodoCommunityInfo();
173
                    // emptyCommunity.id = this.masterZenodoCommunityId;
174
                    // emptyCommunity.title = this.masterZenodoCommunityId;
175
                    // this.masterZenodoCommunity = emptyCommunity;
176
                    //console.log("Master Zenodo community'" + this.community.zenodoCommunity + "' couldn't be loaded");
177
                    this.handleError("Error getting Master Zenodo community with id: " + this.community.zenodoCommunityId, error);
178

    
179
                  }
180
                );
181
              }
182
              this._searchZenodoCommunitiesService.searchZCommunities(this.properties, this.communityId).subscribe(
183
                result => {
184
                  this.zenodoCommunityIdS = result;
185

    
186

    
187
                },
188
                error => {
189
                  //console.error("list of zenodo communities couldn't be loaded");
190
                  this.handleError("Error getting list of zenodo communities for community with openaire id: " + this.communityId, error);
191
                } //this.handleError('System error retrieving community profile', error)
192
              );
193

    
194
              //console.log(community);
195
            });
196

    
197
          this.countResearchResults("publication");
198
          this.countResearchResults("dataset");
199
          this.countResearchResults("software");
200
          this.countResearchResults("other");
201

    
202
          this._searchCommunityProjectsService.countTotalProjects(this.properties, this.communityId).subscribe(
203
            projectTotal => {
204
              this.projectTotal = projectTotal;
205
              //console.log(projectTotal);
206
            },
207
            error => {
208
              this.handleError("Error getting number of projects for community with id: " + this.communityId, error);
209
            },
210
            () => {
211
              this.projectsCalculated = true;
212
            }
213
          );
214

    
215
          this._searchCommunityDataprovidersService.countTotalDataproviders(this.properties, this.communityId).subscribe(
216
            contentProviderTotal => {
217
              this.contentProviderTotal = contentProviderTotal;
218
              //console.log(contentProviderTotal);
219
            },
220
            error => {
221
              this.handleError("Error getting number of content providers for community with id: " + this.communityId, error);
222
            },
223
            () => {
224
              this.contentProvidersCalculated = true;
225
            }
226
          );
227

    
228
          // this._searchEntriesService.countTotal(this.properties.communityAPI+this.communityId+'/organizations').subscribe(
229
          //   organizationTotal => {
230
          //             this.organizationTotal = organizationTotal;
231
          //             console.log(organizationTotal);
232
          //   });
233

    
234

    
235
          /**/
236
          this.config.getCommunityInformation(this.properties, this.communityId).subscribe(
237
            res => {
238
              this.communityInfo = res;
239
            },
240
            error => {
241
              //console.log(error)
242
              this.handleError("Error getting community with id: " + this.communityId, error);
243
            }
244
          );
245
        }
246
      });
247
  }
248

    
249
  public countResearchResults(resultType: string) {
250
    this._searchResearchResultsService.countTotalResults(resultType, this.properties, "&fq=communityid=" + this.communityId).subscribe(
251
      researchResultsTotal => {
252
        this.setTotal(resultType, researchResultsTotal);
253
        if (resultType == "publication") {
254
          //this.searchResearchResults(resultType, this.publicationTotal, this.publicationResults);
255
        }
256
      },
257
      error => {
258
        this.handleError("Error getting number of " + this.getEntityName(resultType, true, true) + " for community with id: " + this.communityId, error);
259
      }
260
    );
261
  }
262

    
263
  public searchResearchResults(resultType: string, resultsTotal: number, results: Array<any>) {
264
    this.setActiveTab(resultType);
265

    
266
    if (resultsTotal > 0 && results == null) {
267
      this.showLoading = true;
268

    
269
      this._searchResearchResultsService.search(resultType, "", "&fq=communityid=" + this.communityId, 1, 5, "resultdateofacceptance,descending", [], this.properties).subscribe(
270
        researchResults => {
271
          this.setResults(resultType, researchResults[1]);
272
          this.showLoading = false;
273
        },
274
        error => {
275
          this.handleError("Error getting " + this.getEntityName(resultType, true, true) + " for community with id: " + this.communityId, error);
276
        }
277
      );
278
    }
279
  }
280

    
281
  public ngOnDestroy() {
282
    if (this.piwiksub) {
283
      this.piwiksub.unsubscribe();
284
    }
285
  }
286

    
287
  isEntityEnabled(entity: string) {
288
    return this.communityInfo.entities.some(x => x['pid'] == entity && x['isEnabled'] === true);
289
  }
290

    
291
  isRouteEnabled(route: string) {
292
    return this.communityInfo.pages.some(x => x['route'] == route && x['isEnabled'] === true);
293
  }
294

    
295
  showInvite() {
296
    return this.isManager();
297
  }
298

    
299
  isManager() {
300
    if (!this.user) {
301
      return false;
302
    }
303
    var email = this.user.email;
304
    var index = -1;
305
    if (email && this.community != null && this.community.managers != null) {
306
      index = this.community.managers.indexOf(email);
307
    }
308
    return Session.isPortalAdministrator(this.user) || Session.isCommunityCurator(this.user) || index != -1;
309
  }
310

    
311
  private handleError(message: string, error) {
312
    console.error("Community (component): " + message, error);
313
  }
314

    
315
  getSearchPlaceHolder() {
316
    var entities = [];
317
    if (this.isEntityEnabled("publication")) {
318
      entities.push("publications");
319
    }
320
    if (this.isEntityEnabled("dataset")) {
321
      entities.push("research data");
322
    }
323
    if (this.isEntityEnabled("software")) {
324
      entities.push("software");
325
    }
326
    if (this.isEntityEnabled("orp")) {
327
      entities.push("other research products");
328
    }
329
    return "Search" + ((entities.length > 0) ? (" for " + entities.join(', ') + "...") : "");
330
  }
331

    
332
  countOtherGraphs() {
333
    var count = 0;
334
    if (this.statistics && this.statistics.allowedEntities) {
335
      for (var entity of this.statistics.allowedEntities) {
336
        if (this.statistics.statisticsSum[entity].total > 0 && this.statistics.allowedCharts[entity].length > 0 && this.activeTab != entity) {
337
          count += this.statistics.allowedCharts[entity].length;
338
        }
339
      }
340
    }
341
    return count;
342
  }
343

    
344
  createParams(param) {
345
    return StringUtils.quote(StringUtils.URIEncode(param));
346
  }
347

    
348
  private setActiveTab(entityType: string) {
349
    if (entityType == "other") {
350
      this.activeTab = "orp";
351
    } else {
352
      this.activeTab = entityType;
353
    }
354
  }
355

    
356
  private setResults(entityType: string, results: Array<any>) {
357
    if (entityType == "publication") {
358
      this.publicationResults = results;
359
    } else if (entityType == "dataset") {
360
      this.researchDataResults = results;
361
    } else if (entityType == "software") {
362
      this.softwareResults = results;
363
    } else if (entityType == "other") {
364
      this.orpResults = results;
365
    }
366
  }
367

    
368
  private setTotal(entityType: string, total: number) {
369
    if (entityType == "publication") {
370
      this.publicationTotal = total;
371
    } else if (entityType == "dataset") {
372
      this.researchDataTotal = total;
373
    } else if (entityType == "software") {
374
      this.softwareTotal = total;
375
    } else if (entityType == "other") {
376
      this.orpTotal = total;
377
    }
378
  }
379

    
380
  private getEntityName(entityType: string, plural: boolean, full: boolean): string {
381
    if (entityType == "publication") {
382
      return "publication" + (plural ? "s" : "");
383
    } else if (entityType == "dataset") {
384
      return (full ? "research data" : ("dataset" + (plural ? "s" : "")));
385
    } else if (entityType == "software") {
386
      return "software";
387
    } else if (entityType == "other") {
388
      return (full ? ("other research product" + (plural ? "s" : "")) : "other");
389
    }
390
  }
391

    
392
  public buildProjectsAndContentProvidesTooltip(): string {
393
    let tooltipContent: string = "<div class='uk-margin'>";
394

    
395
    if(this.projectTotal != null  && this.projectTotal > 0 && this.isEntityEnabled('project') && this.isRouteEnabled(this.searchLinkToProjects)) {
396
      tooltipContent += "<span class='uk-text-bold'>Projects</span>";
397
    }
398
    if(this.projectTotal != null  && this.projectTotal > 0 && this.isEntityEnabled('project') && this.isRouteEnabled(this.searchLinkToProjects)
399
      && (this.contentProviderTotal != null  && this.contentProviderTotal > 0 && this.isEntityEnabled('datasource') && this.isRouteEnabled(this.searchLinkToDataProviders))) {
400
      tooltipContent += " and ";
401
    }
402
    if(this.contentProviderTotal != null  && this.contentProviderTotal > 0 && this.isEntityEnabled('datasource') && this.isRouteEnabled(this.searchLinkToDataProviders)) {
403
      tooltipContent += "<span class='uk-text-bold'>Content Providers</span>";
404
    }
405

    
406
    tooltipContent += " have been selected as relevant for your community by the gateway curators.";
407
    tooltipContent += "</div>";
408

    
409
    return tooltipContent;
410
  }
411

    
412
  public buildZenodoCommunitiesTooltip(): string {
413
    let tooltipContent: string = "<div class='uk-margin'>";
414

    
415
    tooltipContent += "<span class='uk-text-bold'>Zenodo</span> is a catch-all repository for OpenAIRE.";
416
    tooltipContent += "<div class='uk-margin-small-top'>A <span class='uk-text-bold'>Zenodo Community</span> is created and curated by Zenodo users.</div>";
417
    tooltipContent += "</div>";
418
    return tooltipContent;
419
  }
420

    
421
  entityChanged($event){
422
    this.selectedEntity = $event.entity;
423
    this.selectedEntitySimpleUrl = $event.simpleUrl;
424
    this.selectedEntityAdvancedUrl = $event.advancedUrl;
425
    if(this.selectedEntity == 'result'){
426
      this.placeholderText ="Search by title, author, abstract, DOI, orcid... ";
427
    }else if(this.selectedEntity == 'project') {
428
      this.placeholderText = "Search by project title, grant id, funder...";
429
    }else if(this.selectedEntity == 'dataprovider') {
430
      this.placeholderText = "Search by name...";
431
    }else{
432
      this.placeholderText = "Search community content";
433
    }
434
  }
435

    
436
  goTo(simple:boolean){
437
    let url = (simple)?this.selectedEntitySimpleUrl:this.selectedEntityAdvancedUrl;
438
    let parameterNames = [];
439
    let parameterValues = [];
440
    if (this.selectedEntity == "result") {
441
     /* if (this.resultTypes) {
442
        let values = [];
443
        if (this.resultTypes.publication) {
444
          values.push("publications");
445
        }
446
        if (this.resultTypes.dataset) {
447
          values.push("datasets");
448
        }
449
        if (this.resultTypes.software) {
450
          values.push("software");
451
        }
452
        if (this.resultTypes.other) {
453
          values.push("other");
454
        }
455
        if (values.length > 0) {
456
          parameterNames.push("type");
457
          parameterValues.push(values.join(","));
458
        }
459
        if (this.resultsQuickFilter) {
460
          parameterNames.push("qf");
461
          parameterValues.push("" + this.resultsQuickFilter.selected);
462
        }
463
      }*/
464
    }
465
    if(this.keyword.length > 0) {
466
      parameterNames.push("q");
467
      parameterValues.push(this.keyword);
468
      parameterNames.push("op");
469
      parameterValues.push("and");
470
    }
471
    this._router.navigate([url], {queryParams: this.routerHelper.createQueryParams(parameterNames, parameterValues)});
472
  }
473

    
474
  public countSubscribersEvent($event){
475
    this.subscribers = $event.value;
476
  }
477

    
478
  public checkStatistics(type: string) {
479
    // if(this.isEntityEnabled(type)
480
    // && this.statistics && this.statistics.statisticsDisplay && this.statistics.statisticsDisplay.isActive
481
    // && this.statistics.statisticsSum && this.statistics.statisticsSum[type].total>0
482
    // &&
483
    // (  this.statistics.statisticsDisplay.entities[type].numbers.map['total']['showInMonitor']
484
    //   || this.statistics.statisticsDisplay.entities[type].numbers.map['project']['showInMonitor']
485
    //   || this.statistics.statisticsDisplay.entities[type].numbers.map['open']['showInMonitor']
486
    //   || this.statistics.statisticsDisplay.entities[type].numbers.map['closed']['showInMonitor']
487
    //   || this.statistics.statisticsDisplay.entities[type].numbers.map['embargo']['showInMonitor']
488
    //   || this.statistics.statisticsDisplay.entities[type].numbers.map['restricted']['showInMonitor']
489
    //   || ( this.statistics.allowedEntitiesMode['showInMonitor'] && this.statistics.statisticsSum
490
    //     && this.statistics.allowedChartsMode['showInMonitor'] && this.statistics.statisticsSum[type]
491
    //     && this.statistics.allowedChartsMode['showInMonitor'][type] && this.statistics.statisticsSum[type].total > 0
492
    //     && this.statistics.allowedChartsMode['showInMonitor'][type].length > 0))) {
493
    //   return true;
494
    // } else {
495
    //   return false;
496
    // }
497
    if(this.isEntityEnabled(type)
498
      && this.statistics && this.statistics.statisticsDisplay && this.statistics.statisticsDisplay.isActive
499
      && this.statistics.statisticsSum && this.statistics.statisticsSum[type] && this.statistics.statisticsSum[type].total>0
500
      &&
501
      (  this.statistics.statisticsDisplay.entities[type].numbers.map['total']['showInMonitor']
502
        || this.statistics.statisticsDisplay.entities[type].numbers.map['project']['showInMonitor']
503
        || this.statistics.statisticsDisplay.entities[type].numbers.map['open']['showInMonitor']
504
        || this.statistics.statisticsDisplay.entities[type].numbers.map['closed']['showInMonitor']
505
        || this.statistics.statisticsDisplay.entities[type].numbers.map['embargo']['showInMonitor']
506
        || this.statistics.statisticsDisplay.entities[type].numbers.map['restricted']['showInMonitor']
507
        || ( this.statistics.allowedEntitiesMode['showInMonitor']
508
          && this.statistics.allowedChartsMode['showInMonitor'][type]
509
          && this.statistics.allowedChartsMode['showInMonitor'][type].length > 0))) {
510
      return true;
511
    } else {
512
      return false;
513
    }
514
  }
515

    
516
  public initializeAnalyticsActiveTab() {
517
    if(!this.analyticsActiveTab) {
518
      if(this.checkStatistics("publication")) {
519
        this.analyticsActiveTab = "publication";
520
      } else if(this.checkStatistics("dataset")) {
521
        this.analyticsActiveTab = "dataset";
522
      } else if(this.checkStatistics("software")) {
523
        this.analyticsActiveTab = "software";
524
      } else if(this.checkStatistics("orp")) {
525
        this.analyticsActiveTab = "orp";
526
      }
527
    }
528
  }
529

    
530
  public showAnalyticsTab() {
531
    this.initializeAnalyticsActiveTab();
532
    if(!this.analyticsActiveTab) {
533
      return false;
534
    } else {
535
      return true;
536
    }
537
  }
538
}
(3-3/4)