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
  // TODO Unsubscribe
79
  subs: Subscription[] = [];
80
  
81
  @ViewChild(StatisticsForDashboardComponent) statistics: StatisticsForDashboardComponent = null;
82
  public activeTab = "summary";
83
  public show: string = 'overview';
84
  public analyticsActiveTab: string = "";
85
  public analyticsChecked: boolean = false;
86
  
87
  searchLinkToResults: string = null;
88
  
89
  searchLinkToProjects: string = null;
90
  searchLinkToDataProviders: string = null;
91
  searchLinkToAdvancedResults: string = null;
92
  shareInZenodoPage: string = null;
93
  public routerHelper: RouterHelper = new RouterHelper();
94
  private user: User;
95
  
96
  @ViewChild(SubscribeComponent) subscribeComponent: SubscribeComponent = null;
97
//Search Form
98
  selectedEntity;
99
  selectedEntitySimpleUrl;
100
  selectedEntityAdvancedUrl;
101
  keyword: string = "";
102
  customFilter;
103
  placeholderText = "Search by title, author, abstract, DOI, orcid... ";
104
  
105
  constructor(
106
    private element: ElementRef,
107
    private route: ActivatedRoute,
108
    private _router: Router,
109
    private location: Location,
110
    private _meta: Meta,
111
    private _title: Title,
112
    private _piwikService: PiwikService,
113
    private config: ConfigurationService,
114
    private _communityService: CommunityService,
115
    private _searchCommunityDataprovidersService: SearchCommunityDataprovidersService,
116
    private _searchCommunityProjectsService: SearchCommunityProjectsService,
117
    private _searchResearchResultsService: SearchResearchResultsService,
118
    private _searchZenodoCommunitiesService: SearchZenodoCommunitiesService,
119
    private _zenodoCommunitieService: ZenodoCommunitiesService,
120
    private seoService: SEOService,
121
    private userManagementService: UserManagementService) {
122
    
123
    var description = "OpenAIRE - Connect, Community Dashboard, research community";
124
    var title = "OpenAIRE - Connect";
125
    this._meta.updateTag({content: description}, "name='description'");
126
    this._meta.updateTag({content: description}, "property='og:description'");
127
    this._meta.updateTag({content: title}, "property='og:title'");
128
    this._title.setTitle(title);
129
    
130
    this.fetchPublications = new FetchResearchResults(this._searchResearchResultsService);
131
    this.fetchDatasets = new FetchResearchResults(this._searchResearchResultsService);
132
    this.fetchSoftware = new FetchResearchResults(this._searchResearchResultsService);
133
    this.fetchOrps = new FetchResearchResults(this._searchResearchResultsService);
134
    this.fetchFeaturedDatasets = new FetchResearchResults(this._searchResearchResultsService);
135

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