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;
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.properties = properties;
136
    this.searchLinkToResults = this.properties.searchLinkToResults;
137
    this.searchLinkToProjects = this.properties.searchLinkToProjects;
138
    this.searchLinkToDataProviders = this.properties.searchLinkToDataProviders;
139
    this.searchLinkToAdvancedResults = this.properties.searchLinkToAdvancedResults;
140
    this.shareInZenodoPage = this.properties.shareInZenodoPage;
141
    this.url =properties.domain + properties.baseLink + this._router.url;
142
    this.seoService.createLinkForCanonicalURL(this.url, false);
143
    this._meta.updateTag({content: this.url}, "property='og:url'");
144
    this.subs.push(this.userManagementService.getUserInfo().subscribe(user => {
145
      this.user = user;
146
    }));
147
    if (this.communityId != null && this.communityId != '') {
148
      this.customFilter = new SearchCustomFilter("Community", "communityId", this.communityId, "");
149
      this.subs.push(this._communityService.getCommunityByState(this.properties, this.properties.communityAPI + this.communityId).subscribe(
150
        community => {
151
          if (typeof document !== 'undefined') {
152
            HelperFunctions.scroll();
153
          }
154
          this.community = community;
155
          if(community.description != null && (community.description.length - this.thresholdDescription <= this.descriptionDiff)) {
156
            this.thresholdDescription = community.description.length;
157
          }
158

    
159
          if (this.properties.environment == "development") {
160
            this.params = {communityId: community.communityId};
161
          }
162
          this._meta.updateTag({content: community.description}, "name='description'");
163
          this._meta.updateTag({content: community.description}, "property='og:description'");
164
          this._meta.updateTag({content: community.title}, "property='og:title'");
165
          this._title.setTitle(community.title);
166
          if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
167
            this.subs.push(this._piwikService.trackView(this.properties, community.title, PiwikHelper.getSiteId(this.communityId, this.properties.environment)).subscribe());
168
          }
169
          if (this.community.zenodoCommunity) {
170
            this.subs.push(this._zenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities + this.community.zenodoCommunity, null).subscribe(
171
              result => {
172
                this.masterZenodoCommunity = result;
173
              },
174
              error => {
175
                this.handleError("Error getting Master Zenodo community with id: " + this.community.zenodoCommunity, error);
176
              }
177
            ));
178
          }
179
          this.subs.push(this._searchZenodoCommunitiesService.searchZCommunities(this.properties, this.communityId).subscribe(
180
            result => {
181
              this.zenodoCommunityIdS = result;
182
            },
183
            error => {
184
              this.handleError("Error getting list of zenodo communities for community with openaire id: " + this.communityId, error);
185
            }
186
          ));
187

    
188
          //console.log(community);
189
        }));
190

    
191
      this.countResearchResults("publication");
192
      this.countResearchResults("dataset");
193
      this.countResearchResults("software");
194
      this.countResearchResults("other");
195

    
196
      this.subs.push(this._searchCommunityProjectsService.countTotalProjects(this.properties, this.communityId).subscribe(
197
        projectTotal => {
198
          this.projectTotal = projectTotal;
199
        },
200
        error => {
201
          this.handleError("Error getting number of projects for community with id: " + this.communityId, error);
202
        },
203
        () => {
204
          this.projectsCalculated = true;
205
        }
206
      ));
207

    
208
      this.subs.push(this._searchCommunityDataprovidersService.countTotalDataproviders(this.properties, this.communityId).subscribe(
209
        contentProviderTotal => {
210
          this.contentProviderTotal = contentProviderTotal;
211
          //console.log(contentProviderTotal);
212
        },
213
        error => {
214
          this.handleError("Error getting number of content providers for community with id: " + this.communityId, error);
215
        },
216
        () => {
217
          this.contentProvidersCalculated = true;
218
        }
219
      ));
220
      this.subs.push(this.config.communityInformationState.subscribe(
221
        res => {
222
          this.communityInfo = res;
223
        },
224
        error => {
225
          //console.log(error)
226
          this.handleError("Error getting community with id: " + this.communityId, error);
227
        }
228
      ));
229
    }
230
  }
231

    
232
  private searchPublications(page: number, size: number) {
233
    this.setActiveTab("publication");
234

    
235
    if (this.reloadPublications &&
236
      (this.fetchPublications.searchUtils.status == this.errorCodes.LOADING ||
237
        (this.fetchPublications.searchUtils.status == this.errorCodes.DONE && this.fetchPublications.searchUtils.totalResults > 0)
238
      )
239
    ) {
240
      this.fetchPublications.getResultsForCommunity("publication", this.communityId, page, size, this.properties);
241
    }
242
    this.reloadPublications = false;
243
  }
244

    
245
  private searchDatasets(page: number, size: number) {
246
    this.setActiveTab("dataset");
247

    
248
    if (this.reloadDatasets &&
249
      (this.fetchDatasets.searchUtils.status == this.errorCodes.LOADING ||
250
        (this.fetchDatasets.searchUtils.status == this.errorCodes.DONE && this.fetchDatasets.searchUtils.totalResults > 0)
251
      )
252
    ) {
253
      this.fetchDatasets.getResultsForCommunity("dataset", this.communityId, page, size, this.properties);
254
    }
255
    this.reloadDatasets = false;
256
  }
257

    
258
  private searchSoftware(page: number, size: number) {
259
    this.setActiveTab("software");
260

    
261
    if (this.reloadSoftware &&
262
      (this.fetchSoftware.searchUtils.status == this.errorCodes.LOADING ||
263
        (this.fetchSoftware.searchUtils.status == this.errorCodes.DONE && this.fetchSoftware.searchUtils.totalResults > 0)
264
      )
265
    ) {
266
      this.fetchSoftware.getResultsForCommunity("software", this.communityId, page, size, this.properties);
267
    }
268
    this.reloadSoftware = false;
269
  }
270

    
271
  private searchOrps(page: number, size: number) {
272
    this.setActiveTab("other");
273

    
274
    if (this.reloadOrps &&
275
      (this.fetchOrps.searchUtils.status == this.errorCodes.LOADING ||
276
        (this.fetchOrps.searchUtils.status == this.errorCodes.DONE && this.fetchOrps.searchUtils.totalResults > 0)
277
      )
278
    ) {
279
      this.fetchOrps.getResultsForCommunity("other", this.communityId, page, size, this.properties);
280
    }
281
    this.reloadOrps = false;
282
  }
283

    
284
  private countResearchResults(resultType: string) {
285
    let fetch: FetchResearchResults;
286

    
287
    if (resultType == "publication") {
288
      fetch = this.fetchPublications;
289
    } else if (resultType == "dataset") {
290
      fetch = this.fetchDatasets;
291
    } else if (resultType == "software") {
292
      fetch = this.fetchSoftware;
293
    } else if (resultType == "other") {
294
      fetch = this.fetchOrps;
295
    }
296

    
297
    fetch.getNumForCommunity(resultType, this.communityId, this.properties);
298
  }
299
  
300
  public ngOnDestroy() {
301
    for (let sub of this.subs) {
302
      sub.unsubscribe();
303
    }
304
    this.fetchPublications.clearSubscriptions();
305
    this.fetchDatasets.clearSubscriptions();
306
    this.fetchOrps.clearSubscriptions();
307
    this.fetchSoftware.clearSubscriptions();
308
  }
309

    
310
  isEntityEnabled(entity: string) {
311
    return this.communityInfo.entities.some(x => x['pid'] == entity && x['isEnabled'] === true);
312
  }
313

    
314
  isRouteEnabled(route: string) {
315
    return this.communityInfo.pages.some(x => x['route'] == route && x['isEnabled'] === true);
316
  }
317

    
318
  showInvite() {
319
    return this.isManager();
320
  }
321

    
322
  isManager() {
323
    if (!this.user) {
324
      return false;
325
    }
326
    var email = this.user.email;
327
    var index = -1;
328
    if (email && this.community != null && this.community.managers != null) {
329
      index = this.community.managers.indexOf(email);
330
    }
331
    return Session.isPortalAdministrator(this.user) || Session.isCommunityCurator(this.user) || index != -1;
332
  }
333

    
334
  private handleError(message: string, error) {
335
    console.error("Community (component): " + message, error);
336
  }
337

    
338
  getSearchPlaceHolder() {
339
    var entities = [];
340
    if (this.isEntityEnabled("publication")) {
341
      entities.push("publications");
342
    }
343
    if (this.isEntityEnabled("dataset")) {
344
      entities.push("research data");
345
    }
346
    if (this.isEntityEnabled("software")) {
347
      entities.push("software");
348
    }
349
    if (this.isEntityEnabled("orp")) {
350
      entities.push("other research products");
351
    }
352
    return "Search" + ((entities.length > 0) ? (" for " + entities.join(', ') + "...") : "");
353
  }
354

    
355
  countOtherGraphs() {
356
    var count = 0;
357
    if (this.statistics && this.statistics.allowedEntities) {
358
      for (var entity of this.statistics.allowedEntities) {
359
        if (this.statistics.statisticsSum[entity].total > 0 && this.statistics.allowedCharts[entity].length > 0 && this.activeTab != entity) {
360
          count += this.statistics.allowedCharts[entity].length;
361
        }
362
      }
363
    }
364
    return count;
365
  }
366

    
367
  createParams(param) {
368
    return StringUtils.quote(StringUtils.URIEncode(param));
369
  }
370

    
371
  private setActiveTab(entityType: string) {
372
    if (entityType == "other") {
373
      this.activeTab = "orp";
374
    } else {
375
      this.activeTab = entityType;
376
    }
377
  }
378

    
379
  public getParamsForSearchLink(type: string = "") {
380
    if(type) {
381
      return this.routerHelper.createQueryParams(['type', 'qf', 'sortBy'], [type, 'false', 'resultdateofacceptance,descending']);
382
    } else {
383
      return {};
384
    }
385
  }
386

    
387
  private getEntityName(entityType: string, plural: boolean, full: boolean): string {
388
    if (entityType == "publication") {
389
      return "publication" + (plural ? "s" : "");
390
    } else if (entityType == "dataset") {
391
      return (full ? "research data" : ("dataset" + (plural ? "s" : "")));
392
    } else if (entityType == "software") {
393
      return "software";
394
    } else if (entityType == "other") {
395
      return (full ? ("other research product" + (plural ? "s" : "")) : "other");
396
    }
397
  }
398

    
399
  public buildProjectsAndContentProvidesTooltip(): string {
400
    let tooltipContent: string = "<div class='uk-margin'>";
401

    
402
    if(this.projectTotal != null  && this.projectTotal > 0 && this.isEntityEnabled('project') && this.isRouteEnabled(this.searchLinkToProjects)) {
403
      tooltipContent += "<span class='uk-text-bold'>Projects</span>";
404
    }
405
    if(this.projectTotal != null  && this.projectTotal > 0 && this.isEntityEnabled('project') && this.isRouteEnabled(this.searchLinkToProjects)
406
      && (this.contentProviderTotal != null  && this.contentProviderTotal > 0 && this.isEntityEnabled('datasource') && this.isRouteEnabled(this.searchLinkToDataProviders))) {
407
      tooltipContent += " and ";
408
    }
409
    if(this.contentProviderTotal != null  && this.contentProviderTotal > 0 && this.isEntityEnabled('datasource') && this.isRouteEnabled(this.searchLinkToDataProviders)) {
410
      tooltipContent += "<span class='uk-text-bold'>Content Providers</span>";
411
    }
412

    
413
    tooltipContent += " have been selected as relevant for your community by the gateway curators.";
414
    tooltipContent += "</div>";
415

    
416
    return tooltipContent;
417
  }
418

    
419
  public buildZenodoCommunitiesTooltip(): string {
420
    let tooltipContent: string = "<div class='uk-margin'>";
421

    
422
    tooltipContent += "<span class='uk-text-bold'>Zenodo</span> is a catch-all repository for OpenAIRE.";
423
    tooltipContent += "<div class='uk-margin-small-top'>A <span class='uk-text-bold'>Zenodo Community</span> is created and curated by Zenodo users.</div>";
424
    tooltipContent += "</div>";
425
    return tooltipContent;
426
  }
427

    
428
  entityChanged($event){
429
    this.selectedEntity = $event.entity;
430
    this.selectedEntitySimpleUrl = $event.simpleUrl;
431
    this.selectedEntityAdvancedUrl = $event.advancedUrl;
432
    if(this.selectedEntity == 'result'){
433
      this.placeholderText ="Search by title, author, abstract, DOI, orcid... ";
434
    }else if(this.selectedEntity == 'project') {
435
      this.placeholderText = "Search by project title, grant id, funder...";
436
    }else if(this.selectedEntity == 'dataprovider') {
437
      this.placeholderText = "Search by name...";
438
    }else{
439
      this.placeholderText = "Search community content";
440
    }
441
  }
442

    
443
  goTo(simple:boolean){
444
    let url = (simple)?this.selectedEntitySimpleUrl:this.selectedEntityAdvancedUrl;
445
    let parameterNames = [];
446
    let parameterValues = [];
447
    if(this.keyword.length > 0) {
448
      parameterNames.push("fv0");
449
      parameterValues.push(this.keyword);
450
      parameterNames.push("f0");
451
      parameterValues.push("q");
452
    }
453
    this._router.navigate([url], {queryParams: this.routerHelper.createQueryParams(parameterNames, parameterValues)});
454
  }
455

    
456
  public countSubscribersEvent($event){
457
    this.subscribers = $event.value;
458
  }
459

    
460
  public checkStatistics(type: string) {
461
    return !!(this.isEntityEnabled(type)
462
      && this.statistics && this.statistics.statisticsDisplay && this.statistics.statisticsDisplay.isActive
463
      && this.statistics.statisticsSum && this.statistics.statisticsSum[type] && this.statistics.statisticsSum[type].total > 0
464
      &&
465
      (this.statistics.statisticsDisplay.entities[type].numbers.map['total']['showInMonitor']
466
        || this.statistics.statisticsDisplay.entities[type].numbers.map['project']['showInMonitor']
467
        || this.statistics.statisticsDisplay.entities[type].numbers.map['open']['showInMonitor']
468
        || this.statistics.statisticsDisplay.entities[type].numbers.map['closed']['showInMonitor']
469
        || this.statistics.statisticsDisplay.entities[type].numbers.map['embargo']['showInMonitor']
470
        || this.statistics.statisticsDisplay.entities[type].numbers.map['restricted']['showInMonitor']
471
        || (this.statistics.allowedEntitiesMode['showInMonitor']
472
          && this.statistics.allowedChartsMode['showInMonitor'][type]
473
          && this.statistics.allowedChartsMode['showInMonitor'][type].length > 0)));
474
  }
475

    
476
  public initializeAnalyticsActiveTab() {
477
    if(!this.analyticsChecked) {
478
      if(this.checkStatistics("publication")) {
479
        this.analyticsActiveTab = "publication";
480
      } else if(this.checkStatistics("dataset")) {
481
        this.analyticsActiveTab = "dataset";
482
      } else if(this.checkStatistics("software")) {
483
        this.analyticsActiveTab = "software";
484
      } else if(this.checkStatistics("orp")) {
485
        this.analyticsActiveTab = "orp";
486
      }
487
    }
488
  }
489

    
490
  public showAnalyticsTab() {
491
    this.initializeAnalyticsActiveTab();
492
    return this.analyticsActiveTab;
493
  }
494

    
495
  public onSelectActiveTab(activeTabId) {
496
    if(this.activeTab != "activaTabId") {   // tab really changed
497
      if (activeTabId == 'summary') {
498
        this.activeTab = 'summary';
499
      } else if (activeTabId == 'publications') {
500
        this.show = 'overview';
501
        this.searchPublications(1, this.searchNumber);
502
      } else if (activeTabId == 'datasets') {
503
        this.show = 'overview';
504
        this.searchDatasets(1, this.searchNumber);
505
      } else if (activeTabId == 'software') {
506
        this.show = 'overview';
507
        this.searchSoftware(1, this.searchNumber);
508
      } else if (activeTabId == 'other') {
509
        this.show='overview';
510
        this.searchOrps(1, this.searchNumber);
511
      } else if (activeTabId == 'analytics') {
512
        this.show = 'analysis';
513
        this.activeTab = 'analytics';
514
        this.analyticsChecked = true;
515
      }
516
    }
517
  }
518
}
(3-3/4)