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
import {FetchResearchResults} from "../openaireLibrary/utils/fetchEntitiesClasses/fetchResearchResults.class";
27
import {ErrorCodes} from "../openaireLibrary/utils/properties/errorCodes";
28
import {Subscription} from "rxjs";
29
import {properties} from "../../environments/environment";
30

    
31
@Component({
32
  selector: 'community',
33
  templateUrl: 'community.component.html',
34
})
35

    
36
export class CommunityComponent {
37
  public url: string = null;
38
  
39
  public projectTotal = null;
40
  public contentProviderTotal = null;
41
  
42
  public projectsCalculated: boolean = false;
43
  public contentProvidersCalculated: boolean = false;
44
  
45
  params: any = {};
46
  properties: EnvProperties = properties;
47
  
48
  public errorCodes: ErrorCodes = new ErrorCodes();
49
  // Request results of each tab only the one time (first time tab is clicked)
50
  private reloadPublications: boolean = true;
51
  private reloadDatasets: boolean = true;
52
  private reloadSoftware: boolean = true;
53
  private reloadOrps: boolean = true;
54
  private reloadFeaturedDatasets: boolean = true;
55
  
56
  // Variables for publications, research data, projects, content providers, related content providers tabs
57
  public fetchPublications: FetchResearchResults;
58
  public fetchDatasets: FetchResearchResults;
59
  public fetchSoftware: FetchResearchResults;
60
  public fetchOrps: FetchResearchResults;
61
  public fetchFeaturedDatasets: FetchResearchResults;
62
  public searchNumber: number = 5;
63
  
64
  @Input() communityId = null;
65
  public community = null;
66
  
67
  public communityInfo = null;
68
  
69
  public showLoading: boolean = true;
70
  masterZenodoCommunity = null;
71
  zenodoCommunityIdS = [];
72
  showAllDescription = false;
73
  public thresholdDescription: number = 500;
74
  public descriptionDiff: number = 100;
75
  
76
  subscribers: number = 0;
77
  
78
  subs: Subscription[] = [];
79
  
80
  @ViewChild(StatisticsForDashboardComponent) statistics: StatisticsForDashboardComponent = null;
81
  public activeTab = "summary";
82
  public show: string = 'overview';
83
  public analyticsActiveTab: string = "";
84
  public analyticsChecked: boolean = false;
85
  
86
  searchLinkToResults: string = null;
87
  
88
  searchLinkToProjects: string = null;
89
  searchLinkToDataProviders: string = null;
90
  searchLinkToAdvancedResults: string = null;
91
  shareInZenodoPage: string = null;
92
  public routerHelper: RouterHelper = new RouterHelper();
93
  private user: User;
94
  
95
  @ViewChild(SubscribeComponent) subscribeComponent: SubscribeComponent = null;
96
//Search Form
97
  selectedEntity;
98
  selectedEntitySimpleUrl;
99
  selectedEntityAdvancedUrl;
100
  keyword: string = "";
101
  customFilter;
102
  placeholderText = "Search by title, author, abstract, DOI, orcid... ";
103
  
104
  constructor(
105
    private element: ElementRef,
106
    private route: ActivatedRoute,
107
    private _router: Router,
108
    private location: Location,
109
    private _meta: Meta,
110
    private _title: Title,
111
    private _piwikService: PiwikService,
112
    private config: ConfigurationService,
113
    private _communityService: CommunityService,
114
    private _searchCommunityDataprovidersService: SearchCommunityDataprovidersService,
115
    private _searchCommunityProjectsService: SearchCommunityProjectsService,
116
    private _searchResearchResultsService: SearchResearchResultsService,
117
    private _searchZenodoCommunitiesService: SearchZenodoCommunitiesService,
118
    private _zenodoCommunitieService: ZenodoCommunitiesService,
119
    private seoService: SEOService,
120
    private userManagementService: UserManagementService) {
121
    
122
    var description = "OpenAIRE - Connect, Community Dashboard, research community";
123
    var title = "OpenAIRE - Connect";
124
    this._meta.updateTag({content: description}, "name='description'");
125
    this._meta.updateTag({content: description}, "property='og:description'");
126
    this._meta.updateTag({content: title}, "property='og:title'");
127
    this._title.setTitle(title);
128
    
129
    this.fetchPublications = new FetchResearchResults(this._searchResearchResultsService);
130
    this.fetchDatasets = new FetchResearchResults(this._searchResearchResultsService);
131
    this.fetchSoftware = new FetchResearchResults(this._searchResearchResultsService);
132
    this.fetchOrps = new FetchResearchResults(this._searchResearchResultsService);
133
    this.fetchFeaturedDatasets = new FetchResearchResults(this._searchResearchResultsService);
134

    
135
  }
136
  
137
  public ngOnInit() {
138
    this.searchLinkToResults = this.properties.searchLinkToResults;
139
    this.searchLinkToProjects = this.properties.searchLinkToProjects;
140
    this.searchLinkToDataProviders = this.properties.searchLinkToDataProviders;
141
    this.searchLinkToAdvancedResults = this.properties.searchLinkToAdvancedResults;
142
    this.shareInZenodoPage = this.properties.shareInZenodoPage;
143
    this.url = properties.domain + properties.baseLink + this._router.url;
144
    this.seoService.createLinkForCanonicalURL(this.url, false);
145
    this._meta.updateTag({content: this.url}, "property='og:url'");
146
    this.subs.push(this.userManagementService.getUserInfo().subscribe(user => {
147
      this.user = user;
148
    }));
149
    this.customFilter = new SearchCustomFilter("Community", "communityId", this.communityId, "");
150
    this.subs.push(this._communityService.getCommunityAsObservable().subscribe(
151
      community => {
152
        if(community) {
153
          if (typeof document !== 'undefined') {
154
            HelperFunctions.scroll();
155
          }
156
          this.community = community;
157
          if (community.description != null && (community.description.length - this.thresholdDescription <= this.descriptionDiff)) {
158
            this.thresholdDescription = community.description.length;
159
          }
160
  
161
          if (this.properties.environment == "development") {
162
            this.params = {communityId: community.communityId};
163
          }
164
          this._meta.updateTag({content: community.description}, "name='description'");
165
          this._meta.updateTag({content: community.description}, "property='og:description'");
166
          this._meta.updateTag({content: community.title}, "property='og:title'");
167
          this._title.setTitle(community.title);
168
          if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
169
            this.subs.push(this._piwikService.trackView(this.properties, community.title, PiwikHelper.getSiteId(this.communityId, this.properties.environment)).subscribe());
170
          }
171
          if (this.community.zenodoCommunity) {
172
            this.subs.push(this._zenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities + this.community.zenodoCommunity, null).subscribe(
173
              result => {
174
                this.masterZenodoCommunity = result;
175
              },
176
              error => {
177
                this.handleError("Error getting Master Zenodo community with id: " + this.community.zenodoCommunity, error);
178
              }
179
            ));
180
          }
181
          this.subs.push(this._searchZenodoCommunitiesService.searchZCommunities(this.properties, this.communityId).subscribe(
182
            result => {
183
              this.zenodoCommunityIdS = result;
184
            },
185
            error => {
186
              this.handleError("Error getting list of zenodo communities for community with openaire id: " + this.communityId, error);
187
            }
188
          ));
189
        }
190
      }));
191
    
192
    this.countResearchResults("publication");
193
    this.countResearchResults("dataset");
194
    this.countResearchResults("software");
195
    this.countResearchResults("other");
196
    if(this.communityId == "enermaps"){
197
      this.countResearchResults("dataset", "enermaps::selection" );
198
    }
199
    
200
    this.subs.push(this._searchCommunityProjectsService.countTotalProjects(this.properties, this.communityId).subscribe(
201
      projectTotal => {
202
        this.projectTotal = projectTotal;
203
      },
204
      error => {
205
        this.handleError("Error getting number of projects for community with id: " + this.communityId, error);
206
      },
207
      () => {
208
        this.projectsCalculated = true;
209
      }
210
    ));
211
    
212
    this.subs.push(this._searchCommunityDataprovidersService.countTotalDataproviders(this.properties, this.communityId).subscribe(
213
      contentProviderTotal => {
214
        this.contentProviderTotal = contentProviderTotal;
215
        //console.log(contentProviderTotal);
216
      },
217
      error => {
218
        this.handleError("Error getting number of content providers for community with id: " + this.communityId, error);
219
      },
220
      () => {
221
        this.contentProvidersCalculated = true;
222
      }
223
    ));
224
    this.subs.push(this.config.communityInformationState.subscribe(
225
      res => {
226
        this.communityInfo = res;
227
      },
228
      error => {
229
        //console.log(error)
230
        this.handleError("Error getting community with id: " + this.communityId, error);
231
      }
232
    ));
233
  }
234
  
235
  private searchPublications(page: number, size: number) {
236
    this.setActiveTab("publication");
237
    
238
    if (this.reloadPublications &&
239
      (this.fetchPublications.searchUtils.status == this.errorCodes.LOADING ||
240
        (this.fetchPublications.searchUtils.status == this.errorCodes.DONE && this.fetchPublications.searchUtils.totalResults > 0)
241
      )
242
    ) {
243
      this.fetchPublications.getResultsForCommunity("publication", this.communityId, page, size, this.properties);
244
    }
245
    this.reloadPublications = false;
246
  }
247
  
248
  private searchDatasets(page: number, size: number) {
249
    this.setActiveTab("dataset");
250
    
251
    if (this.reloadDatasets &&
252
      (this.fetchDatasets.searchUtils.status == this.errorCodes.LOADING ||
253
        (this.fetchDatasets.searchUtils.status == this.errorCodes.DONE && this.fetchDatasets.searchUtils.totalResults > 0)
254
      )
255
    ) {
256
      this.fetchDatasets.getResultsForCommunity("dataset", this.communityId, page, size, this.properties);
257
    }
258
    this.reloadDatasets = false;
259
  }
260
  
261
  private searchSoftware(page: number, size: number) {
262
    this.setActiveTab("software");
263
    
264
    if (this.reloadSoftware &&
265
      (this.fetchSoftware.searchUtils.status == this.errorCodes.LOADING ||
266
        (this.fetchSoftware.searchUtils.status == this.errorCodes.DONE && this.fetchSoftware.searchUtils.totalResults > 0)
267
      )
268
    ) {
269
      this.fetchSoftware.getResultsForCommunity("software", this.communityId, page, size, this.properties);
270
    }
271
    this.reloadSoftware = false;
272
  }
273
  
274
  private searchOrps(page: number, size: number) {
275
    this.setActiveTab("other");
276
    
277
    if (this.reloadOrps &&
278
      (this.fetchOrps.searchUtils.status == this.errorCodes.LOADING ||
279
        (this.fetchOrps.searchUtils.status == this.errorCodes.DONE && this.fetchOrps.searchUtils.totalResults > 0)
280
      )
281
    ) {
282
      this.fetchOrps.getResultsForCommunity("other", this.communityId, page, size, this.properties);
283
    }
284
    this.reloadOrps = false;
285
  }
286
  private searchFeaturedDatasets(page: number, size: number) {
287
    this.setActiveTab("enermaps");
288
    if (this.reloadFeaturedDatasets &&
289
      (this.fetchFeaturedDatasets.searchUtils.status == this.errorCodes.LOADING ||
290
        (this.fetchFeaturedDatasets.searchUtils.status == this.errorCodes.DONE && this.fetchFeaturedDatasets.searchUtils.totalResults > 0)
291
      )
292
    ) {
293
      this.fetchFeaturedDatasets.getAllResultsForCommunity("dataset", this.communityId, page, size, this.properties, "enermaps::selection");
294
    }
295
    this.reloadFeaturedDatasets = false;
296
  }
297
  
298
  private countResearchResults(resultType: string, contextId = null) {
299
    let fetch: FetchResearchResults;
300
    
301
    if (resultType == "publication") {
302
      fetch = this.fetchPublications;
303
    } else if (resultType == "dataset" && !contextId) {
304
      fetch = this.fetchDatasets;
305
    } else if (resultType == "software") {
306
      fetch = this.fetchSoftware;
307
    } else if (resultType == "other") {
308
      fetch = this.fetchOrps;
309
    } else if (resultType == "dataset" && contextId) {
310
      fetch = this.fetchFeaturedDatasets;
311
      this.fetchFeaturedDatasets.getAllResultsForCommunity("dataset", this.communityId, 0, 0, this.properties, contextId);
312
      return;
313
    }
314
    fetch.getNumForCommunity(resultType, this.communityId, this.properties, contextId);
315
  }
316
  
317
  public ngOnDestroy() {
318
    for (let sub of this.subs) {
319
      sub.unsubscribe();
320
    }
321
    this.fetchPublications.clearSubscriptions();
322
    this.fetchDatasets.clearSubscriptions();
323
    this.fetchOrps.clearSubscriptions();
324
    this.fetchSoftware.clearSubscriptions();
325
    this.fetchFeaturedDatasets.clearSubscriptions();
326
  }
327
  
328
  isEntityEnabled(entity: string) {
329
    return this.communityInfo.entities.some(x => x['pid'] == entity && x['isEnabled'] === true);
330
  }
331
  
332
  isRouteEnabled(route: string) {
333
    return this.communityInfo.pages.some(x => x['route'] == route && x['isEnabled'] === true);
334
  }
335
  
336
  showInvite() {
337
    return this.isManager();
338
  }
339
  
340
  isManager() {
341
    if (!this.user) {
342
      return false;
343
    }
344
    var email = this.user.email;
345
    var index = -1;
346
    if (email && this.community != null && this.community.managers != null) {
347
      index = this.community.managers.indexOf(email);
348
    }
349
    return Session.isPortalAdministrator(this.user) || Session.isCommunityCurator(this.user) || index != -1;
350
  }
351
  
352
  private handleError(message: string, error) {
353
    console.error("Community (component): " + message, error);
354
  }
355
  
356
  getSearchPlaceHolder() {
357
    var entities = [];
358
    if (this.isEntityEnabled("publication")) {
359
      entities.push("publications");
360
    }
361
    if (this.isEntityEnabled("dataset")) {
362
      entities.push("research data");
363
    }
364
    if (this.isEntityEnabled("software")) {
365
      entities.push("software");
366
    }
367
    if (this.isEntityEnabled("orp")) {
368
      entities.push("other research products");
369
    }
370
    return "Search" + ((entities.length > 0) ? (" for " + entities.join(', ') + "...") : "");
371
  }
372
  
373
  countOtherGraphs() {
374
    var count = 0;
375
    if (this.statistics && this.statistics.allowedEntities) {
376
      for (var entity of this.statistics.allowedEntities) {
377
        if (this.statistics.statisticsSum[entity].total > 0 && this.statistics.allowedCharts[entity].length > 0 && this.activeTab != entity) {
378
          count += this.statistics.allowedCharts[entity].length;
379
        }
380
      }
381
    }
382
    return count;
383
  }
384
  
385
  createParams(param) {
386
    return StringUtils.quote(StringUtils.URIEncode(param));
387
  }
388
  
389
  private setActiveTab(entityType: string) {
390
    if (entityType == "other") {
391
      this.activeTab = "orp";
392
    } else {
393
      this.activeTab = entityType;
394
    }
395
  }
396
  
397
  public getParamsForSearchLink(type: string = "") {
398
    if (type) {
399
      return this.routerHelper.createQueryParams(['type', 'qf', 'sortBy'], [type, 'false', 'resultdateofacceptance,descending']);
400
    } else {
401
      return {};
402
    }
403
  }
404
  
405
  private getEntityName(entityType: string, plural: boolean, full: boolean): string {
406
    if (entityType == "publication") {
407
      return "publication" + (plural ? "s" : "");
408
    } else if (entityType == "dataset") {
409
      return (full ? "research data" : ("dataset" + (plural ? "s" : "")));
410
    } else if (entityType == "software") {
411
      return "software";
412
    } else if (entityType == "other") {
413
      return (full ? ("other research product" + (plural ? "s" : "")) : "other");
414
    }
415
  }
416
  
417
  public buildProjectsAndContentProvidesTooltip(): string {
418
    let tooltipContent: string = "<div class='uk-margin'>";
419
    
420
    if (this.projectTotal != null && this.projectTotal > 0 && this.isEntityEnabled('project') && this.isRouteEnabled(this.searchLinkToProjects)) {
421
      tooltipContent += "<span class='uk-text-bold'>Projects</span>";
422
    }
423
    if (this.projectTotal != null && this.projectTotal > 0 && this.isEntityEnabled('project') && this.isRouteEnabled(this.searchLinkToProjects)
424
      && (this.contentProviderTotal != null && this.contentProviderTotal > 0 && this.isEntityEnabled('datasource') && this.isRouteEnabled(this.searchLinkToDataProviders))) {
425
      tooltipContent += " and ";
426
    }
427
    if (this.contentProviderTotal != null && this.contentProviderTotal > 0 && this.isEntityEnabled('datasource') && this.isRouteEnabled(this.searchLinkToDataProviders)) {
428
      tooltipContent += "<span class='uk-text-bold'>Content Providers</span>";
429
    }
430
    
431
    tooltipContent += " have been selected as relevant for your community by the gateway curators.";
432
    tooltipContent += "</div>";
433
    
434
    return tooltipContent;
435
  }
436
  
437
  public buildZenodoCommunitiesTooltip(): string {
438
    let tooltipContent: string = "<div class='uk-margin'>";
439
    
440
    tooltipContent += "<span class='uk-text-bold'>Zenodo</span> is a catch-all repository for OpenAIRE.";
441
    tooltipContent += "<div class='uk-margin-small-top'>A <span class='uk-text-bold'>Zenodo Community</span> is created and curated by Zenodo users.</div>";
442
    tooltipContent += "</div>";
443
    return tooltipContent;
444
  }
445
  
446
  entityChanged($event) {
447
    this.selectedEntity = $event.entity;
448
    this.selectedEntitySimpleUrl = $event.simpleUrl;
449
    this.selectedEntityAdvancedUrl = $event.advancedUrl;
450
    if (this.selectedEntity == 'result') {
451
      this.placeholderText = "Search by title, author, abstract, DOI, orcid... ";
452
    } else if (this.selectedEntity == 'project') {
453
      this.placeholderText = "Search by project title, grant id, funder...";
454
    } else if (this.selectedEntity == 'dataprovider') {
455
      this.placeholderText = "Search by name...";
456
    } else {
457
      this.placeholderText = "Search community content";
458
    }
459
  }
460
  
461
  goTo(simple: boolean) {
462
    let url = (simple) ? this.selectedEntitySimpleUrl : this.selectedEntityAdvancedUrl;
463
    let parameterNames = [];
464
    let parameterValues = [];
465
    if (this.keyword.length > 0) {
466
      parameterNames.push("fv0");
467
      parameterValues.push(this.keyword);
468
      parameterNames.push("f0");
469
      parameterValues.push("q");
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
    return !!(this.isEntityEnabled(type)
480
      && this.statistics && this.statistics.statisticsDisplay && this.statistics.statisticsDisplay.isActive
481
      && this.statistics.statisticsSum && this.statistics.statisticsSum[type] && 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']
490
          && this.statistics.allowedChartsMode['showInMonitor'][type]
491
          && this.statistics.allowedChartsMode['showInMonitor'][type].length > 0)));
492
  }
493
  
494
  public initializeAnalyticsActiveTab() {
495
    if (!this.analyticsChecked) {
496
      if (this.checkStatistics("publication")) {
497
        this.analyticsActiveTab = "publication";
498
      } else if (this.checkStatistics("dataset")) {
499
        this.analyticsActiveTab = "dataset";
500
      } else if (this.checkStatistics("software")) {
501
        this.analyticsActiveTab = "software";
502
      } else if (this.checkStatistics("orp")) {
503
        this.analyticsActiveTab = "orp";
504
      }
505
    }
506
  }
507
  
508
  public showAnalyticsTab() {
509
    this.initializeAnalyticsActiveTab();
510
    return this.analyticsActiveTab;
511
  }
512
  
513
  public onSelectActiveTab(activeTabId) {
514
    if (this.activeTab != "activaTabId") {   // tab really changed
515
      if (activeTabId == 'summary') {
516
        this.activeTab = 'summary';
517
      } else if (activeTabId == 'publications') {
518
        this.show = 'overview';
519
        this.searchPublications(1, this.searchNumber);
520
      } else if (activeTabId == 'datasets') {
521
        this.show = 'overview';
522
        this.searchDatasets(1, this.searchNumber);
523
      } else if (activeTabId == 'software') {
524
        this.show = 'overview';
525
        this.searchSoftware(1, this.searchNumber);
526
      } else if (activeTabId == 'other') {
527
        this.show = 'overview';
528
        this.searchOrps(1, this.searchNumber);
529
      } else if (activeTabId == 'analytics') {
530
        this.show = 'analysis';
531
        this.activeTab = 'analytics';
532
        this.analyticsChecked = true;
533
      } else if (activeTabId == 'mapping') {
534
        this.show = 'mapping';
535
        this.activeTab = 'mapping';
536
      } else if (activeTabId == 'enermaps') {
537
        this.show = 'enermaps';
538
        this.searchFeaturedDatasets(1, this.fetchFeaturedDatasets.searchUtils.totalResults < 20?this.fetchFeaturedDatasets.searchUtils.totalResults:20);
539
      }
540
    }
541
  }
542
}
(3-3/4)