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} 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

    
22
@Component({
23
  selector: 'community',
24
  templateUrl: 'community.component.html',
25
})
26

    
27
export class CommunityComponent {
28
  public sub: any;
29
  public piwiksub: any;
30
  public subfunders: any;
31

    
32
  public publicationTotal = null;
33
  public researchDataTotal = null;
34
  public softwareTotal = null;
35
  public orpTotal = null;
36
  public projectTotal = null;
37
  public contentProviderTotal = null;
38
  public organizationTotal = null;
39

    
40
  params: any = {};
41
  properties: EnvProperties;
42

    
43
  public publicationResults = null;
44
  public researchDataResults = null;
45
  public softwareResults = null;
46
  public orpResults = null;
47

    
48
  @Input() communityId = null;
49
  public community = null;
50

    
51
  public communityInfo = null;
52

    
53
  public showLoading: boolean = true;
54
  masterZenodoCommunity = null;
55
  zenodoCommunityIdS = [];
56
  showAll = false;
57
  // TODO Unsubscribe
58
  public subPublications;
59
  public subResearchData;
60
  public subSoftware;
61
  public subOrps;
62
  @ViewChild(StatisticsForDashboardComponent) statistics: StatisticsForDashboardComponent = null;
63
  public activeTab = "publication";
64
  public show: string = 'overview';
65

    
66
  constructor(
67
    private element: ElementRef,
68
    private route: ActivatedRoute,
69
    private _router: Router,
70
    private location: Location,
71
    private _meta: Meta,
72
    private _title: Title,
73
    private _piwikService: PiwikService,
74
    private config: ConfigurationService,
75
    private _communityService: CommunityService,
76
    private _searchCommunityDataprovidersService:SearchCommunityDataprovidersService,
77
    private _searchCommunityProjectsService: SearchCommunityProjectsService,
78
    private _searchResearchResultsService: SearchResearchResultsService,
79
    private _searchZenodoCommunitiesService: SearchZenodoCommunitiesService,
80
    private _ΖenodoCommunitieService: ZenodoCommunitiesService) {
81

    
82
    var description = "OpenAIRE - Connect, Community Dashboard, research community";
83
    var title = "OpenAIRE - Connect";
84
    this._meta.updateTag({content: description}, "name='description'");
85
    this._meta.updateTag({content: description}, "property='og:description'");
86
    this._meta.updateTag({content: title}, "property='og:title'");
87
    this._title.setTitle(title);
88

    
89
  }
90

    
91
  public ngOnInit() {
92
    this.route.data
93
      .subscribe((data: { envSpecific: EnvProperties }) => {
94
        this.properties = data.envSpecific;
95
        var url = data.envSpecific.baseLink + this._router.url;
96
        this._meta.updateTag({content: url}, "property='og:url'");
97

    
98
        if (this.communityId != null && this.communityId != '') {
99
          this._communityService.getCommunity(this.properties, this.properties.communityAPI + this.communityId).subscribe(
100
            community => {
101
              if (typeof document !== 'undefined') {
102
                HelperFunctions.scroll();
103
              }
104
              this.community = community;
105
              if (this.properties.environment == "development") {
106
                this.params = {communityId: community.communityId};
107
              }
108
              this._meta.updateTag({content: community.description}, "name='description'");
109
              this._meta.updateTag({content: community.description}, "property='og:description'");
110
              this._meta.updateTag({content: community.title}, "property='og:title'");
111
              this._title.setTitle(community.title);
112
              if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
113
                this.piwiksub = this._piwikService.trackView(this.properties, community.title, PiwikHelper.siteIDs[this.communityId]).subscribe();
114
              }
115
              if (this.community.zenodoCommunity) {
116
                this._ΖenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities + this.community.zenodoCommunity, null).subscribe(
117
                  result => {
118
                    this.masterZenodoCommunity = result;
119

    
120
                  },
121
                  error => {
122
                    // var emptyCommunity:ZenodoCommunityInfo = new ZenodoCommunityInfo();
123
                    // emptyCommunity.id = this.masterZenodoCommunityId;
124
                    // emptyCommunity.title = this.masterZenodoCommunityId;
125
                    // this.masterZenodoCommunity = emptyCommunity;
126
                    //console.log("Master Zenodo community'" + this.community.zenodoCommunity + "' couldn't be loaded");
127
                    this.handleError("Error getting Master Zenodo community with id: " + this.community.zenodoCommunityId, error);
128

    
129
                  }
130
                );
131
              }
132
              this._searchZenodoCommunitiesService.searchZCommunities(this.properties, this.communityId).subscribe(
133
                result => {
134
                  this.zenodoCommunityIdS = result;
135

    
136

    
137
                },
138
                error => {
139
                  //console.error("list of zenodo communities couldn't be loaded");
140
                  this.handleError("Error getting list of zenodo communities for community with openaire id: " + this.communityId, error);
141
                } //this.handleError('System error retrieving community profile', error)
142
              );
143

    
144
              //console.log(community);
145
            });
146

    
147

    
148
          this._searchResearchResultsService.countTotalResults("publication", this.properties,"&fq=communityid=" + this.communityId).subscribe(
149
            publicationTotal => {
150
              this.publicationTotal = publicationTotal;
151
              this.showLoading = true;
152
              this.searchPublications();
153
            },
154
            error => {
155
              this.handleError("Error getting number of publications for community with id: " + this.communityId, error);
156
            }
157
          );
158

    
159
          this._searchResearchResultsService.countTotalResults("dataset", this.properties,"&fq=communityid=" + this.communityId).subscribe(
160
            researchDataTotal => {
161
              this.researchDataTotal = researchDataTotal;
162
            },
163
            error => {
164
              this.handleError("Error getting number of research data for community with id: " + this.communityId, error);
165
            }
166
          );
167

    
168
          this._searchResearchResultsService.countTotalResults("software", this.properties,"&fq=communityid=" + this.communityId).subscribe(
169
            softwareTotal => {
170
              this.softwareTotal = softwareTotal;
171
            },
172
            error => {
173
              this.handleError("Error getting number of software for community with id: " + this.communityId, error);
174
            }
175
          );
176

    
177
          this._searchResearchResultsService.countTotalResults("other", this.properties,"&fq=communityid=" + this.communityId).subscribe(
178
            orpTotal => {
179
              this.orpTotal = orpTotal;
180
            },
181
            error => {
182
              this.handleError("Error getting number of other research products for community with id: " + this.communityId, error);
183
            }
184
          );
185

    
186
          this._searchCommunityProjectsService.countTotalProjects(this.properties,  this.communityId ).subscribe(
187
            projectTotal => {
188
              this.projectTotal = projectTotal;
189
              //console.log(projectTotal);
190
            },
191
            error => {
192
              this.handleError("Error getting number of projects for community with id: " + this.communityId, error);
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

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

    
212

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

    
227
  public searchPublications() {
228
    this.activeTab = "publication";
229
    if (this.publicationTotal > 0 && this.publicationResults == null) {
230
      //this._searchEntriesService.getResults(this.properties.searchAPIURLLAst + 'publications?fq=communityid%20exact%20%22' + this.communityId + '%22&sortBy=resultdateofacceptance,descending&format=json&size=5')
231
      this._searchResearchResultsService.search("publication","","&fq=communityid=" + this.communityId,1,5,"resultdateofacceptance,descending",[],this.properties)
232
      .subscribe(
233
        publicationResults => {
234
         this.publicationResults = publicationResults[1];
235
          this.showLoading = false;
236
          //console.log(publicationResults);
237
       },
238
        error => {
239
          this.handleError("Error getting publications for community with id: " + this.communityId, error);
240
        }
241
      );
242
    }
243
  }
244

    
245
  public searchResearchData() {
246
    this.activeTab = "dataset";
247
    if (this.researchDataTotal > 0 && this.researchDataResults == null) {
248
      this._searchResearchResultsService.search("dataset","","&fq=communityid=" + this.communityId,1,5,"resultdateofacceptance,descending",[],this.properties).subscribe(
249
        researchDataResults => {
250
          this.researchDataResults = researchDataResults[1];
251
          this.showLoading = false;
252
        },
253
        error => {
254
          this.handleError("Error getting research data for community with id: " + this.communityId, error);
255
        }
256
      );
257
    }
258
  }
259

    
260
  public searchSoftware() {
261
    this.activeTab = "software";
262
    if (this.softwareTotal > 0 && this.softwareResults == null) {
263
      this._searchResearchResultsService.search("software","","&fq=communityid=" + this.communityId,1,5,"resultdateofacceptance,descending",[],this.properties).subscribe(
264
        softwareResults => {
265
          this.softwareResults = softwareResults[1];
266
          this.showLoading = false;
267
        },
268
        error => {
269
          this.handleError("Error getting software for community with id: " + this.communityId, error);
270
        }
271
      );
272
    }
273
  }
274

    
275
  public searchOrps() {
276
    this.activeTab = "orp";
277
    if (this.orpTotal > 0 && this.orpResults == null) {
278
      this._searchResearchResultsService.search("other","","&fq=communityid=" + this.communityId,1,5,"resultdateofacceptance,descending",[],this.properties).subscribe(
279
        orpResults => {
280
          this.orpResults = orpResults[1];
281
          this.showLoading = false;
282
        },
283
        error => {
284
          this.handleError("Error getting other research products for community with id: " + this.communityId, error);
285
        }
286
      );
287
    }
288
  }
289

    
290
  public ngOnDestroy() {
291
    if (this.piwiksub) {
292
      this.piwiksub.unsubscribe();
293
    }
294
  }
295

    
296
  isEntityEnabled(entity: string) {
297
    return this.communityInfo.entities.some(x => x['pid'] == entity && x['isEnabled'] === true);
298
  }
299

    
300
  isRouteEnabled(route: string) {
301
    return this.communityInfo.pages.some(x => x['route'] == route && x['isEnabled'] === true);
302
  }
303

    
304
  showInvite() {
305

    
306

    
307
    return this.isManager();
308
  }
309

    
310
  isManager() {
311
    var email = Session.getUserEmail();
312
    var index = -1;
313
    if (email && this.community != null && this.community.managers != null) {
314
      index = this.community.managers.indexOf(email);
315
    }
316

    
317
    return Session.isPortalAdministrator() || Session.isCommunityCurator() || index != -1;
318
  }
319

    
320
  private handleError(message: string, error) {
321
    console.error("Community (component): " + message, error);
322
  }
323

    
324
  getSearchPlaceHolder() {
325
    var entities = [];
326
    if (this.isEntityEnabled("publication")) {
327
      entities.push("publications");
328
    }
329
    if (this.isEntityEnabled("dataset")) {
330
      entities.push("research data");
331
    }
332
    if (this.isEntityEnabled("software")) {
333
      entities.push("software");
334
    }
335
    if (this.isEntityEnabled("orp")) {
336
      entities.push("other research products");
337
    }
338
    return "Search" + ((entities.length > 0) ? (" for " + entities.join(', ') + "...") : "");
339
  }
340

    
341
  countOtherGraphs() {
342
    var count = 0;
343
    if (this.statistics && this.statistics.allowedEntities) {
344
      for (var entity of this.statistics.allowedEntities) {
345
        if (this.statistics.statisticsSum[entity].total > 0 && this.statistics.allowedCharts[entity].length > 0 && this.activeTab != entity) {
346
          count += this.statistics.allowedCharts[entity].length;
347
        }
348
      }
349
    }
350
    return count;
351
  }
352

    
353
  createParams(param) {
354
    return StringUtils.quote(StringUtils.URIEncode(param));
355
  }
356

    
357
}
(3-3/4)