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
  // TODO Unsubscribe
68
  public subPublications;
69
  public subResearchData;
70
  public subSoftware;
71
  public subOrps;
72
  @ViewChild(StatisticsForDashboardComponent) statistics: StatisticsForDashboardComponent = null;
73
  public activeTab = "summary";
74
  public show: string = 'overview';
75

    
76
  searchLinkToResults: string = null;
77

    
78
  searchLinkToProjects: string = null;
79
  searchLinkToDataProviders: string = null;
80
  searchLinkToAdvancedResults: string = null;
81
  shareInZenodoPage: string = null;
82
  public routerHelper: RouterHelper = new RouterHelper();
83
  private user: User;
84

    
85
  @ViewChild(SubscribeComponent) subscribeComponent: SubscribeComponent = null;
86

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

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

    
112
  }
113

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

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

    
160
                  }
161
                );
162
              }
163
              this._searchZenodoCommunitiesService.searchZCommunities(this.properties, this.communityId).subscribe(
164
                result => {
165
                  this.zenodoCommunityIdS = result;
166

    
167

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

    
175
              //console.log(community);
176
            });
177

    
178
          this.countResearchResults("publication");
179
          this.countResearchResults("dataset");
180
          this.countResearchResults("software");
181
          this.countResearchResults("other");
182

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

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

    
209
          // this._searchEntriesService.countTotal(this.properties.communityAPI+this.communityId+'/organizations').subscribe(
210
          //   organizationTotal => {
211
          //             this.organizationTotal = organizationTotal;
212
          //             console.log(organizationTotal);
213
          //   });
214

    
215

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

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

    
244
  public searchResearchResults(resultType: string, resultsTotal: number, results: Array<any>) {
245
    this.setActiveTab(resultType);
246

    
247
    if (resultsTotal > 0 && results == null) {
248
      this.showLoading = true;
249

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

    
262
  public ngOnDestroy() {
263
    if (this.piwiksub) {
264
      this.piwiksub.unsubscribe();
265
    }
266
  }
267

    
268
  isEntityEnabled(entity: string) {
269
    return this.communityInfo.entities.some(x => x['pid'] == entity && x['isEnabled'] === true);
270
  }
271

    
272
  isRouteEnabled(route: string) {
273
    return this.communityInfo.pages.some(x => x['route'] == route && x['isEnabled'] === true);
274
  }
275

    
276
  showInvite() {
277
    return this.isManager();
278
  }
279

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

    
292
  private handleError(message: string, error) {
293
    console.error("Community (component): " + message, error);
294
  }
295

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

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

    
325
  createParams(param) {
326
    return StringUtils.quote(StringUtils.URIEncode(param));
327
  }
328

    
329
  private setActiveTab(entityType: string) {
330
    if (entityType == "other") {
331
      this.activeTab = "orp";
332
    } else {
333
      this.activeTab = entityType;
334
    }
335
  }
336

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

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

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

    
373
  public buildProjectsAndContentProvidesTooltip(): string {
374
    let tooltipContent: string = "<div class='uk-margin'>";
375

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

    
387
    tooltipContent += " have been selected as relevant for your community by the gateway curators.";
388
    tooltipContent += "</div>";
389

    
390
    return tooltipContent;
391
  }
392

    
393
  public buildZenodoCommunitiesTooltip(): string {
394
    let tooltipContent: string = "<div class='uk-margin'>";
395

    
396
    tooltipContent += "<span class='uk-text-bold'>Zenodo</span> is a catch-all repository for OpenAIRE.";
397
    tooltipContent += "<div class='uk-margin-small-top'>A <span class='uk-text-bold'>Zenodo Community</span> is created and curated by Zenodo users.</div>";
398
    tooltipContent += "</div>";
399
    return tooltipContent;
400
  }
401
}
(3-3/4)