Project

General

Profile

1 55417 k.triantaf
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 51750 sofia.balt
7 55417 k.triantaf
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 53968 argiro.kok
import {SearchZenodoCommunitiesService} from '../openaireLibrary/connect/zenodoCommunities/searchZenodoCommunities.service';
11
import {ZenodoCommunitiesService} from '../openaireLibrary/connect/zenodoCommunities/zenodo-communities.service';
12 57061 k.triantaf
import {Session, User} from '../openaireLibrary/login/utils/helper.class';
13 55271 argiro.kok
import {StatisticsForDashboardComponent} from '../statistics/statistics.component';
14 55417 k.triantaf
import {StringUtils} from '../openaireLibrary/utils/string-utils.class';
15 51750 sofia.balt
16 51749 argiro.kok
import {PiwikHelper} from '../utils/piwikHelper';
17 55417 k.triantaf
import {HelperFunctions} from "../openaireLibrary/utils/HelperFunctions.class";
18 55996 argiro.kok
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 56817 konstantin
import {RouterHelper} from "../openaireLibrary/utils/routerHelper.class";
22 56841 konstantin
import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service";
23 57061 k.triantaf
import {UserManagementService} from "../openaireLibrary/services/user-management.service";
24 55417 k.triantaf
25 50428 argiro.kok
@Component({
26 55417 k.triantaf
  selector: 'community',
27
  templateUrl: 'community.component.html',
28 50428 argiro.kok
})
29 51164 sofia.balt
30 50428 argiro.kok
export class CommunityComponent {
31 56841 konstantin
  public url: string = null;
32
33 53477 sofia.balt
  public sub: any;
34 50428 argiro.kok
  public piwiksub: any;
35
  public subfunders: any;
36
37 50822 sofia.balt
  public publicationTotal = null;
38
  public researchDataTotal = null;
39
  public softwareTotal = null;
40 52831 sofia.balt
  public orpTotal = null;
41 50980 sofia.balt
  public projectTotal = null;
42
  public contentProviderTotal = null;
43
  public organizationTotal = null;
44 50822 sofia.balt
45 58549 konstantin
  public projectsCalculated: boolean = false;
46
  public contentProvidersCalculated: boolean = false;
47
48 55417 k.triantaf
  params: any = {};
49
  properties: EnvProperties;
50 50428 argiro.kok
51 50822 sofia.balt
  public publicationResults = null;
52
  public researchDataResults = null;
53
  public softwareResults = null;
54 52831 sofia.balt
  public orpResults = null;
55 50568 sofia.balt
56 51407 argiro.kok
  @Input() communityId = null;
57 50974 sofia.balt
  public community = null;
58 50949 sofia.balt
59 51847 myrto.kouk
  public communityInfo = null;
60
61 53479 sofia.balt
  public showLoading: boolean = true;
62 53968 argiro.kok
  masterZenodoCommunity = null;
63
  zenodoCommunityIdS = [];
64 56518 argiro.kok
  showAllSubjects = false;
65
  showAllDescription = false;
66 53477 sofia.balt
  // TODO Unsubscribe
67
  public subPublications;
68
  public subResearchData;
69
  public subSoftware;
70
  public subOrps;
71 55417 k.triantaf
  @ViewChild(StatisticsForDashboardComponent) statistics: StatisticsForDashboardComponent = null;
72 58549 konstantin
  public activeTab = "summary";
73 56138 argiro.kok
  public show: string = 'overview';
74 55417 k.triantaf
75 58392 argiro.kok
  searchLinkToResults: string = null;
76
77 56817 konstantin
  searchLinkToProjects: string = null;
78
  searchLinkToDataProviders: string = null;
79 58392 argiro.kok
  searchLinkToAdvancedResults: string = null;
80 56817 konstantin
  shareInZenodoPage: string = null;
81 57548 k.triantaf
  public routerHelper: RouterHelper = new RouterHelper();
82 57061 k.triantaf
  private user: User;
83 56817 konstantin
84 55417 k.triantaf
  constructor(
85 54852 argiro.kok
    private element: ElementRef,
86 55417 k.triantaf
    private route: ActivatedRoute,
87
    private _router: Router,
88
    private location: Location,
89
    private _meta: Meta,
90
    private _title: Title,
91
    private _piwikService: PiwikService,
92
    private config: ConfigurationService,
93
    private _communityService: CommunityService,
94 57548 k.triantaf
    private _searchCommunityDataprovidersService: SearchCommunityDataprovidersService,
95 55996 argiro.kok
    private _searchCommunityProjectsService: SearchCommunityProjectsService,
96
    private _searchResearchResultsService: SearchResearchResultsService,
97 55417 k.triantaf
    private _searchZenodoCommunitiesService: SearchZenodoCommunitiesService,
98 56841 konstantin
    private _ΖenodoCommunitieService: ZenodoCommunitiesService,
99 57061 k.triantaf
    private seoService: SEOService,
100
    private userManagementService: UserManagementService) {
101 51164 sofia.balt
102 55417 k.triantaf
    var description = "OpenAIRE - Connect, Community Dashboard, research community";
103
    var title = "OpenAIRE - Connect";
104
    this._meta.updateTag({content: description}, "name='description'");
105
    this._meta.updateTag({content: description}, "property='og:description'");
106
    this._meta.updateTag({content: title}, "property='og:title'");
107
    this._title.setTitle(title);
108 50428 argiro.kok
109
  }
110
111
  public ngOnInit() {
112 50681 argiro.kok
    this.route.data
113 55417 k.triantaf
      .subscribe((data: { envSpecific: EnvProperties }) => {
114
        this.properties = data.envSpecific;
115 58392 argiro.kok
        this.searchLinkToResults = this.properties.searchLinkToResults;
116 56817 konstantin
        this.searchLinkToProjects = this.properties.searchLinkToProjects;
117
        this.searchLinkToDataProviders = this.properties.searchLinkToDataProviders;
118 58392 argiro.kok
        this.searchLinkToAdvancedResults = this.properties.searchLinkToAdvancedResults;
119 56817 konstantin
        this.shareInZenodoPage = this.properties.shareInZenodoPage;
120 56841 konstantin
        this.url = data.envSpecific.baseLink + this._router.url;
121
        this.seoService.createLinkForCanonicalURL(this.url, false);
122
        this._meta.updateTag({content: this.url}, "property='og:url'");
123 57944 k.triantaf
        this.userManagementService.getUserInfo().subscribe(user => {
124 57548 k.triantaf
          this.user = user;
125
        });
126 55417 k.triantaf
        if (this.communityId != null && this.communityId != '') {
127
          this._communityService.getCommunity(this.properties, this.properties.communityAPI + this.communityId).subscribe(
128
            community => {
129
              if (typeof document !== 'undefined') {
130
                HelperFunctions.scroll();
131
              }
132
              this.community = community;
133
              if (this.properties.environment == "development") {
134
                this.params = {communityId: community.communityId};
135
              }
136
              this._meta.updateTag({content: community.description}, "name='description'");
137
              this._meta.updateTag({content: community.description}, "property='og:description'");
138
              this._meta.updateTag({content: community.title}, "property='og:title'");
139
              this._title.setTitle(community.title);
140
              if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
141 57548 k.triantaf
                this.piwiksub = this._piwikService.trackView(this.properties, community.title, PiwikHelper.getSiteId(this.communityId, this.properties.environment)).subscribe();
142 55417 k.triantaf
              }
143
              if (this.community.zenodoCommunity) {
144
                this._ΖenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities + this.community.zenodoCommunity, null).subscribe(
145
                  result => {
146
                    this.masterZenodoCommunity = result;
147 51621 argiro.kok
148 55417 k.triantaf
                  },
149
                  error => {
150
                    // var emptyCommunity:ZenodoCommunityInfo = new ZenodoCommunityInfo();
151
                    // emptyCommunity.id = this.masterZenodoCommunityId;
152
                    // emptyCommunity.title = this.masterZenodoCommunityId;
153
                    // this.masterZenodoCommunity = emptyCommunity;
154
                    //console.log("Master Zenodo community'" + this.community.zenodoCommunity + "' couldn't be loaded");
155
                    this.handleError("Error getting Master Zenodo community with id: " + this.community.zenodoCommunityId, error);
156 53968 argiro.kok
157 55417 k.triantaf
                  }
158
                );
159
              }
160
              this._searchZenodoCommunitiesService.searchZCommunities(this.properties, this.communityId).subscribe(
161
                result => {
162
                  this.zenodoCommunityIdS = result;
163 53968 argiro.kok
164
165 55417 k.triantaf
                },
166
                error => {
167
                  //console.error("list of zenodo communities couldn't be loaded");
168
                  this.handleError("Error getting list of zenodo communities for community with openaire id: " + this.communityId, error);
169
                } //this.handleError('System error retrieving community profile', error)
170
              );
171 53968 argiro.kok
172 55417 k.triantaf
              //console.log(community);
173
            });
174 53968 argiro.kok
175 57548 k.triantaf
          this.countResearchResults("publication");
176
          this.countResearchResults("dataset");
177
          this.countResearchResults("software");
178
          this.countResearchResults("other");
179 50980 sofia.balt
180 57548 k.triantaf
          this._searchCommunityProjectsService.countTotalProjects(this.properties, this.communityId).subscribe(
181
            projectTotal => {
182
              this.projectTotal = projectTotal;
183
              //console.log(projectTotal);
184
            },
185
            error => {
186
              this.handleError("Error getting number of projects for community with id: " + this.communityId, error);
187 58549 konstantin
            },
188
            () => {
189
              this.projectsCalculated = true;
190 57548 k.triantaf
            }
191
          );
192 51238 sofia.balt
193 57548 k.triantaf
          this._searchCommunityDataprovidersService.countTotalDataproviders(this.properties, this.communityId).subscribe(
194
            contentProviderTotal => {
195
              this.contentProviderTotal = contentProviderTotal;
196
              //console.log(contentProviderTotal);
197
            },
198
            error => {
199
              this.handleError("Error getting number of content providers for community with id: " + this.communityId, error);
200 58549 konstantin
            },
201
            () => {
202
              this.contentProvidersCalculated = true;
203 57548 k.triantaf
            }
204 55417 k.triantaf
          );
205 53968 argiro.kok
206 55417 k.triantaf
          // this._searchEntriesService.countTotal(this.properties.communityAPI+this.communityId+'/organizations').subscribe(
207
          //   organizationTotal => {
208
          //             this.organizationTotal = organizationTotal;
209
          //             console.log(organizationTotal);
210
          //   });
211 50518 sofia.balt
212 50980 sofia.balt
213 55417 k.triantaf
          /**/
214 55996 argiro.kok
          this.config.getCommunityInformation(this.properties, this.communityId).subscribe(
215 55417 k.triantaf
            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 50428 argiro.kok
  }
226 50941 sofia.balt
227 57085 konstantin
  public countResearchResults(resultType: string) {
228 57548 k.triantaf
    this._searchResearchResultsService.countTotalResults(resultType, this.properties, "&fq=communityid=" + this.communityId).subscribe(
229 57085 konstantin
      researchResultsTotal => {
230
        this.setTotal(resultType, researchResultsTotal);
231 57548 k.triantaf
        if (resultType == "publication") {
232 58549 konstantin
          //this.searchResearchResults(resultType, this.publicationTotal, this.publicationResults);
233 54863 konstantin
        }
234 57085 konstantin
      },
235
      error => {
236 57548 k.triantaf
        this.handleError("Error getting number of " + this.getEntityName(resultType, true, true) + " for community with id: " + this.communityId, error);
237 57085 konstantin
      }
238
    );
239 53477 sofia.balt
  }
240
241 57085 konstantin
  public searchResearchResults(resultType: string, resultsTotal: number, results: Array<any>) {
242
    this.setActiveTab(resultType);
243 53477 sofia.balt
244 57085 konstantin
    if (resultsTotal > 0 && results == null) {
245
      this.showLoading = true;
246 53477 sofia.balt
247 57085 konstantin
      this._searchResearchResultsService.search(resultType, "", "&fq=communityid=" + this.communityId, 1, 5, "resultdateofacceptance,descending", [], this.properties).subscribe(
248
        researchResults => {
249
          this.setResults(resultType, researchResults[1]);
250 55417 k.triantaf
          this.showLoading = false;
251 54863 konstantin
        },
252
        error => {
253 57548 k.triantaf
          this.handleError("Error getting " + this.getEntityName(resultType, true, true) + " for community with id: " + this.communityId, error);
254 54863 konstantin
        }
255
      );
256 53477 sofia.balt
    }
257
  }
258
259 50428 argiro.kok
  public ngOnDestroy() {
260 55417 k.triantaf
    if (this.piwiksub) {
261 50428 argiro.kok
      this.piwiksub.unsubscribe();
262
    }
263
  }
264 51847 myrto.kouk
265 55271 argiro.kok
  isEntityEnabled(entity: string) {
266 55417 k.triantaf
    return this.communityInfo.entities.some(x => x['pid'] == entity && x['isEnabled'] === true);
267 51847 myrto.kouk
  }
268 55417 k.triantaf
269 55271 argiro.kok
  isRouteEnabled(route: string) {
270 55417 k.triantaf
    return this.communityInfo.pages.some(x => x['route'] == route && x['isEnabled'] === true);
271 53968 argiro.kok
  }
272 55302 argiro.kok
273 55417 k.triantaf
  showInvite() {
274 57944 k.triantaf
    return this.isManager();
275 55302 argiro.kok
  }
276
277 55417 k.triantaf
  isManager() {
278 57548 k.triantaf
    if (!this.user) {
279 57061 k.triantaf
      return false;
280
    }
281
    var email = this.user.email;
282 55417 k.triantaf
    var index = -1;
283
    if (email && this.community != null && this.community.managers != null) {
284
      index = this.community.managers.indexOf(email);
285 54047 argiro.kok
    }
286 57061 k.triantaf
    return Session.isPortalAdministrator(this.user) || Session.isCommunityCurator(this.user) || index != -1;
287 54047 argiro.kok
  }
288 54863 konstantin
289
  private handleError(message: string, error) {
290 55417 k.triantaf
    console.error("Community (component): " + message, error);
291 54863 konstantin
  }
292 55271 argiro.kok
293 55417 k.triantaf
  getSearchPlaceHolder() {
294 55271 argiro.kok
    var entities = [];
295 55417 k.triantaf
    if (this.isEntityEnabled("publication")) {
296 55271 argiro.kok
      entities.push("publications");
297
    }
298 55417 k.triantaf
    if (this.isEntityEnabled("dataset")) {
299 55271 argiro.kok
      entities.push("research data");
300
    }
301 55417 k.triantaf
    if (this.isEntityEnabled("software")) {
302 55271 argiro.kok
      entities.push("software");
303
    }
304 55417 k.triantaf
    if (this.isEntityEnabled("orp")) {
305 55271 argiro.kok
      entities.push("other research products");
306
    }
307 55417 k.triantaf
    return "Search" + ((entities.length > 0) ? (" for " + entities.join(', ') + "...") : "");
308 55283 argiro.kok
  }
309 55271 argiro.kok
310 55417 k.triantaf
  countOtherGraphs() {
311
    var count = 0;
312
    if (this.statistics && this.statistics.allowedEntities) {
313
      for (var entity of this.statistics.allowedEntities) {
314
        if (this.statistics.statisticsSum[entity].total > 0 && this.statistics.allowedCharts[entity].length > 0 && this.activeTab != entity) {
315
          count += this.statistics.allowedCharts[entity].length;
316
        }
317 55283 argiro.kok
      }
318
    }
319 55417 k.triantaf
    return count;
320 55271 argiro.kok
  }
321 55417 k.triantaf
322
  createParams(param) {
323 55366 argiro.kok
    return StringUtils.quote(StringUtils.URIEncode(param));
324 55417 k.triantaf
  }
325 55283 argiro.kok
326 57085 konstantin
  private setActiveTab(entityType: string) {
327 57548 k.triantaf
    if (entityType == "other") {
328 57085 konstantin
      this.activeTab = "orp";
329
    } else {
330
      this.activeTab = entityType;
331
    }
332
  }
333
334
  private setResults(entityType: string, results: Array<any>) {
335 57548 k.triantaf
    if (entityType == "publication") {
336 57085 konstantin
      this.publicationResults = results;
337 57548 k.triantaf
    } else if (entityType == "dataset") {
338 57085 konstantin
      this.researchDataResults = results;
339 57548 k.triantaf
    } else if (entityType == "software") {
340 57085 konstantin
      this.softwareResults = results;
341 57548 k.triantaf
    } else if (entityType == "other") {
342 57085 konstantin
      this.orpResults = results;
343
    }
344
  }
345
346
  private setTotal(entityType: string, total: number) {
347 57548 k.triantaf
    if (entityType == "publication") {
348 57085 konstantin
      this.publicationTotal = total;
349 57548 k.triantaf
    } else if (entityType == "dataset") {
350 57085 konstantin
      this.researchDataTotal = total;
351 57548 k.triantaf
    } else if (entityType == "software") {
352 57085 konstantin
      this.softwareTotal = total;
353 57548 k.triantaf
    } else if (entityType == "other") {
354 57085 konstantin
      this.orpTotal = total;
355
    }
356
  }
357
358 57548 k.triantaf
  private getEntityName(entityType: string, plural: boolean, full: boolean): string {
359
    if (entityType == "publication") {
360 57085 konstantin
      return "publication" + (plural ? "s" : "");
361 57548 k.triantaf
    } else if (entityType == "dataset") {
362 57085 konstantin
      return (full ? "research data" : ("dataset" + (plural ? "s" : "")));
363 57548 k.triantaf
    } else if (entityType == "software") {
364 57085 konstantin
      return "software";
365 57548 k.triantaf
    } else if (entityType == "other") {
366 57085 konstantin
      return (full ? ("other research product" + (plural ? "s" : "")) : "other");
367
    }
368
  }
369 58549 konstantin
370
  public buildProjectsAndContentProvidesTooltip(): string {
371
    let tooltipContent: string = "<div class='uk-margin'>";
372
373
    if(this.projectTotal != null  && this.projectTotal > 0 && this.isEntityEnabled('project') && this.isRouteEnabled(this.searchLinkToProjects)) {
374
      tooltipContent += "<span class='uk-text-bold'>Projects</span>";
375
    }
376
    if(this.projectTotal != null  && this.projectTotal > 0 && this.isEntityEnabled('project') && this.isRouteEnabled(this.searchLinkToProjects)
377
      && (this.contentProviderTotal != null  && this.contentProviderTotal > 0 && this.isEntityEnabled('datasource') && this.isRouteEnabled(this.searchLinkToDataProviders))) {
378
      tooltipContent += " and ";
379
    }
380
    if(this.contentProviderTotal != null  && this.contentProviderTotal > 0 && this.isEntityEnabled('datasource') && this.isRouteEnabled(this.searchLinkToDataProviders)) {
381
      tooltipContent += "<span class='uk-text-bold'>Content Providers</span>";
382
    }
383
384
    tooltipContent += " have been selected as relevant for your community by the gateway curators.";
385
    tooltipContent += "</div>";
386
387
    return tooltipContent;
388
  }
389
390
  public buildZenodoCommunitiesTooltip(): string {
391
    let tooltipContent: string = "<div class='uk-margin'>";
392
393
    tooltipContent += "<span class='uk-text-bold'>Zenodo</span> is a catch-all repository for OpenAIRE.";
394
    tooltipContent += "<div class='uk-margin-small-top'>A <span class='uk-text-bold'>Zenodo Community</span> is created and curated by Zenodo users.</div>";
395
    tooltipContent += "</div>";
396
    return tooltipContent;
397
  }
398 55283 argiro.kok
}