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

    
26
@Component({
27
  selector: 'community',
28
  templateUrl: 'community.component.html',
29
})
30

    
31
export class CommunityComponent {
32
  public url: string = null;
33

    
34
  public sub: any;
35
  public piwiksub: any;
36
  public subfunders: any;
37

    
38
  public publicationTotal = null;
39
  public researchDataTotal = null;
40
  public softwareTotal = null;
41
  public orpTotal = null;
42
  public projectTotal = null;
43
  public contentProviderTotal = null;
44
  public organizationTotal = null;
45

    
46
  public projectsCalculated: boolean = false;
47
  public contentProvidersCalculated: boolean = false;
48

    
49
  params: any = {};
50
  properties: EnvProperties;
51

    
52
  public publicationResults = null;
53
  public researchDataResults = null;
54
  public softwareResults = null;
55
  public orpResults = null;
56

    
57
  @Input() communityId = null;
58
  public community = null;
59

    
60
  public communityInfo = null;
61

    
62
  public showLoading: boolean = true;
63
  masterZenodoCommunity = null;
64
  zenodoCommunityIdS = [];
65
  showAllSubjects = false;
66
  showAllDescription = false;
67
  public thresholdDescription: number = 550;
68

    
69
  subscribers: number = 0;
70

    
71
  // TODO Unsubscribe
72
  public subPublications;
73
  public subResearchData;
74
  public subSoftware;
75
  public subOrps;
76
  @ViewChild(StatisticsForDashboardComponent) statistics: StatisticsForDashboardComponent = null;
77
  public activeTab = "summary";
78
  public show: string = 'overview';
79

    
80
  searchLinkToResults: string = null;
81

    
82
  searchLinkToProjects: string = null;
83
  searchLinkToDataProviders: string = null;
84
  searchLinkToAdvancedResults: string = null;
85
  shareInZenodoPage: string = null;
86
  public routerHelper: RouterHelper = new RouterHelper();
87
  private user: User;
88

    
89
  @ViewChild(SubscribeComponent) subscribeComponent: SubscribeComponent = null;
90

    
91
  constructor(
92
    private element: ElementRef,
93
    private route: ActivatedRoute,
94
    private _router: Router,
95
    private location: Location,
96
    private _meta: Meta,
97
    private _title: Title,
98
    private _piwikService: PiwikService,
99
    private config: ConfigurationService,
100
    private _communityService: CommunityService,
101
    private _searchCommunityDataprovidersService: SearchCommunityDataprovidersService,
102
    private _searchCommunityProjectsService: SearchCommunityProjectsService,
103
    private _searchResearchResultsService: SearchResearchResultsService,
104
    private _searchZenodoCommunitiesService: SearchZenodoCommunitiesService,
105
    private _ΖenodoCommunitieService: ZenodoCommunitiesService,
106
    private seoService: SEOService,
107
    private userManagementService: UserManagementService) {
108

    
109
    var description = "OpenAIRE - Connect, Community Dashboard, research community";
110
    var title = "OpenAIRE - Connect";
111
    this._meta.updateTag({content: description}, "name='description'");
112
    this._meta.updateTag({content: description}, "property='og:description'");
113
    this._meta.updateTag({content: title}, "property='og:title'");
114
    this._title.setTitle(title);
115

    
116
  }
117

    
118
  public ngOnInit() {
119
    this.route.data
120
      .subscribe((data: { envSpecific: EnvProperties }) => {
121
        this.properties = data.envSpecific;
122
        this.searchLinkToResults = this.properties.searchLinkToResults;
123
        this.searchLinkToProjects = this.properties.searchLinkToProjects;
124
        this.searchLinkToDataProviders = this.properties.searchLinkToDataProviders;
125
        this.searchLinkToAdvancedResults = this.properties.searchLinkToAdvancedResults;
126
        this.shareInZenodoPage = this.properties.shareInZenodoPage;
127
        this.url = data.envSpecific.baseLink + this._router.url;
128
        this.seoService.createLinkForCanonicalURL(this.url, false);
129
        this._meta.updateTag({content: this.url}, "property='og:url'");
130
        this.userManagementService.getUserInfo().subscribe(user => {
131
          this.user = user;
132
        });
133
        if (this.communityId != null && this.communityId != '') {
134
          this._communityService.getCommunity(this.properties, this.properties.communityAPI + this.communityId).subscribe(
135
            community => {
136
              if (typeof document !== 'undefined') {
137
                HelperFunctions.scroll();
138
              }
139
              this.community = community;
140
              if (this.properties.environment == "development") {
141
                this.params = {communityId: community.communityId};
142
              }
143
              this._meta.updateTag({content: community.description}, "name='description'");
144
              this._meta.updateTag({content: community.description}, "property='og:description'");
145
              this._meta.updateTag({content: community.title}, "property='og:title'");
146
              this._title.setTitle(community.title);
147
              if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
148
                this.piwiksub = this._piwikService.trackView(this.properties, community.title, PiwikHelper.getSiteId(this.communityId, this.properties.environment)).subscribe();
149
              }
150
              if (this.community.zenodoCommunity) {
151
                this._ΖenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities + this.community.zenodoCommunity, null).subscribe(
152
                  result => {
153
                    this.masterZenodoCommunity = result;
154

    
155
                  },
156
                  error => {
157
                    // var emptyCommunity:ZenodoCommunityInfo = new ZenodoCommunityInfo();
158
                    // emptyCommunity.id = this.masterZenodoCommunityId;
159
                    // emptyCommunity.title = this.masterZenodoCommunityId;
160
                    // this.masterZenodoCommunity = emptyCommunity;
161
                    //console.log("Master Zenodo community'" + this.community.zenodoCommunity + "' couldn't be loaded");
162
                    this.handleError("Error getting Master Zenodo community with id: " + this.community.zenodoCommunityId, error);
163

    
164
                  }
165
                );
166
              }
167
              this._searchZenodoCommunitiesService.searchZCommunities(this.properties, this.communityId).subscribe(
168
                result => {
169
                  this.zenodoCommunityIdS = result;
170

    
171

    
172
                },
173
                error => {
174
                  //console.error("list of zenodo communities couldn't be loaded");
175
                  this.handleError("Error getting list of zenodo communities for community with openaire id: " + this.communityId, error);
176
                } //this.handleError('System error retrieving community profile', error)
177
              );
178

    
179
              //console.log(community);
180
            });
181

    
182
          this.countResearchResults("publication");
183
          this.countResearchResults("dataset");
184
          this.countResearchResults("software");
185
          this.countResearchResults("other");
186

    
187
          this._searchCommunityProjectsService.countTotalProjects(this.properties, this.communityId).subscribe(
188
            projectTotal => {
189
              this.projectTotal = projectTotal;
190
              //console.log(projectTotal);
191
            },
192
            error => {
193
              this.handleError("Error getting number of projects for community with id: " + this.communityId, error);
194
            },
195
            () => {
196
              this.projectsCalculated = true;
197
            }
198
          );
199

    
200
          this._searchCommunityDataprovidersService.countTotalDataproviders(this.properties, this.communityId).subscribe(
201
            contentProviderTotal => {
202
              this.contentProviderTotal = contentProviderTotal;
203
              //console.log(contentProviderTotal);
204
            },
205
            error => {
206
              this.handleError("Error getting number of content providers for community with id: " + this.communityId, error);
207
            },
208
            () => {
209
              this.contentProvidersCalculated = true;
210
            }
211
          );
212

    
213
          // this._searchEntriesService.countTotal(this.properties.communityAPI+this.communityId+'/organizations').subscribe(
214
          //   organizationTotal => {
215
          //             this.organizationTotal = organizationTotal;
216
          //             console.log(organizationTotal);
217
          //   });
218

    
219

    
220
          /**/
221
          this.config.getCommunityInformation(this.properties, this.communityId).subscribe(
222
            res => {
223
              this.communityInfo = res;
224
            },
225
            error => {
226
              //console.log(error)
227
              this.handleError("Error getting community with id: " + this.communityId, error);
228
            }
229
          );
230
        }
231
      });
232
  }
233

    
234
  public countResearchResults(resultType: string) {
235
    this._searchResearchResultsService.countTotalResults(resultType, this.properties, "&fq=communityid=" + this.communityId).subscribe(
236
      researchResultsTotal => {
237
        this.setTotal(resultType, researchResultsTotal);
238
        if (resultType == "publication") {
239
          //this.searchResearchResults(resultType, this.publicationTotal, this.publicationResults);
240
        }
241
      },
242
      error => {
243
        this.handleError("Error getting number of " + this.getEntityName(resultType, true, true) + " for community with id: " + this.communityId, error);
244
      }
245
    );
246
  }
247

    
248
  public searchResearchResults(resultType: string, resultsTotal: number, results: Array<any>) {
249
    this.setActiveTab(resultType);
250

    
251
    if (resultsTotal > 0 && results == null) {
252
      this.showLoading = true;
253

    
254
      this._searchResearchResultsService.search(resultType, "", "&fq=communityid=" + this.communityId, 1, 5, "resultdateofacceptance,descending", [], this.properties).subscribe(
255
        researchResults => {
256
          this.setResults(resultType, researchResults[1]);
257
          this.showLoading = false;
258
        },
259
        error => {
260
          this.handleError("Error getting " + this.getEntityName(resultType, true, true) + " for community with id: " + this.communityId, error);
261
        }
262
      );
263
    }
264
  }
265

    
266
  public ngOnDestroy() {
267
    if (this.piwiksub) {
268
      this.piwiksub.unsubscribe();
269
    }
270
  }
271

    
272
  isEntityEnabled(entity: string) {
273
    return this.communityInfo.entities.some(x => x['pid'] == entity && x['isEnabled'] === true);
274
  }
275

    
276
  isRouteEnabled(route: string) {
277
    return this.communityInfo.pages.some(x => x['route'] == route && x['isEnabled'] === true);
278
  }
279

    
280
  showInvite() {
281
    return this.isManager();
282
  }
283

    
284
  isManager() {
285
    if (!this.user) {
286
      return false;
287
    }
288
    var email = this.user.email;
289
    var index = -1;
290
    if (email && this.community != null && this.community.managers != null) {
291
      index = this.community.managers.indexOf(email);
292
    }
293
    return Session.isPortalAdministrator(this.user) || Session.isCommunityCurator(this.user) || index != -1;
294
  }
295

    
296
  private handleError(message: string, error) {
297
    console.error("Community (component): " + message, error);
298
  }
299

    
300
  getSearchPlaceHolder() {
301
    var entities = [];
302
    if (this.isEntityEnabled("publication")) {
303
      entities.push("publications");
304
    }
305
    if (this.isEntityEnabled("dataset")) {
306
      entities.push("research data");
307
    }
308
    if (this.isEntityEnabled("software")) {
309
      entities.push("software");
310
    }
311
    if (this.isEntityEnabled("orp")) {
312
      entities.push("other research products");
313
    }
314
    return "Search" + ((entities.length > 0) ? (" for " + entities.join(', ') + "...") : "");
315
  }
316

    
317
  countOtherGraphs() {
318
    var count = 0;
319
    if (this.statistics && this.statistics.allowedEntities) {
320
      for (var entity of this.statistics.allowedEntities) {
321
        if (this.statistics.statisticsSum[entity].total > 0 && this.statistics.allowedCharts[entity].length > 0 && this.activeTab != entity) {
322
          count += this.statistics.allowedCharts[entity].length;
323
        }
324
      }
325
    }
326
    return count;
327
  }
328

    
329
  createParams(param) {
330
    return StringUtils.quote(StringUtils.URIEncode(param));
331
  }
332

    
333
  private setActiveTab(entityType: string) {
334
    if (entityType == "other") {
335
      this.activeTab = "orp";
336
    } else {
337
      this.activeTab = entityType;
338
    }
339
  }
340

    
341
  private setResults(entityType: string, results: Array<any>) {
342
    if (entityType == "publication") {
343
      this.publicationResults = results;
344
    } else if (entityType == "dataset") {
345
      this.researchDataResults = results;
346
    } else if (entityType == "software") {
347
      this.softwareResults = results;
348
    } else if (entityType == "other") {
349
      this.orpResults = results;
350
    }
351
  }
352

    
353
  private setTotal(entityType: string, total: number) {
354
    if (entityType == "publication") {
355
      this.publicationTotal = total;
356
    } else if (entityType == "dataset") {
357
      this.researchDataTotal = total;
358
    } else if (entityType == "software") {
359
      this.softwareTotal = total;
360
    } else if (entityType == "other") {
361
      this.orpTotal = total;
362
    }
363
  }
364

    
365
  private getEntityName(entityType: string, plural: boolean, full: boolean): string {
366
    if (entityType == "publication") {
367
      return "publication" + (plural ? "s" : "");
368
    } else if (entityType == "dataset") {
369
      return (full ? "research data" : ("dataset" + (plural ? "s" : "")));
370
    } else if (entityType == "software") {
371
      return "software";
372
    } else if (entityType == "other") {
373
      return (full ? ("other research product" + (plural ? "s" : "")) : "other");
374
    }
375
  }
376

    
377
  public buildProjectsAndContentProvidesTooltip(): string {
378
    let tooltipContent: string = "<div class='uk-margin'>";
379

    
380
    if(this.projectTotal != null  && this.projectTotal > 0 && this.isEntityEnabled('project') && this.isRouteEnabled(this.searchLinkToProjects)) {
381
      tooltipContent += "<span class='uk-text-bold'>Projects</span>";
382
    }
383
    if(this.projectTotal != null  && this.projectTotal > 0 && this.isEntityEnabled('project') && this.isRouteEnabled(this.searchLinkToProjects)
384
      && (this.contentProviderTotal != null  && this.contentProviderTotal > 0 && this.isEntityEnabled('datasource') && this.isRouteEnabled(this.searchLinkToDataProviders))) {
385
      tooltipContent += " and ";
386
    }
387
    if(this.contentProviderTotal != null  && this.contentProviderTotal > 0 && this.isEntityEnabled('datasource') && this.isRouteEnabled(this.searchLinkToDataProviders)) {
388
      tooltipContent += "<span class='uk-text-bold'>Content Providers</span>";
389
    }
390

    
391
    tooltipContent += " have been selected as relevant for your community by the gateway curators.";
392
    tooltipContent += "</div>";
393

    
394
    return tooltipContent;
395
  }
396

    
397
  public buildZenodoCommunitiesTooltip(): string {
398
    let tooltipContent: string = "<div class='uk-margin'>";
399

    
400
    tooltipContent += "<span class='uk-text-bold'>Zenodo</span> is a catch-all repository for OpenAIRE.";
401
    tooltipContent += "<div class='uk-margin-small-top'>A <span class='uk-text-bold'>Zenodo Community</span> is created and curated by Zenodo users.</div>";
402
    tooltipContent += "</div>";
403
    return tooltipContent;
404
  }
405

    
406
  public countSubscribersEvent($event){
407
    this.subscribers = $event.value;
408
  }
409
}
(3-3/4)