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