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 55417 k.triantaf
  params: any = {};
46
  properties: EnvProperties;
47 50428 argiro.kok
48 50822 sofia.balt
  public publicationResults = null;
49
  public researchDataResults = null;
50
  public softwareResults = null;
51 52831 sofia.balt
  public orpResults = null;
52 50568 sofia.balt
53 51407 argiro.kok
  @Input() communityId = null;
54 50974 sofia.balt
  public community = null;
55 50949 sofia.balt
56 51847 myrto.kouk
  public communityInfo = null;
57
58 53479 sofia.balt
  public showLoading: boolean = true;
59 53968 argiro.kok
  masterZenodoCommunity = null;
60
  zenodoCommunityIdS = [];
61 56518 argiro.kok
  showAllSubjects = false;
62
  showAllDescription = false;
63 53477 sofia.balt
  // TODO Unsubscribe
64
  public subPublications;
65
  public subResearchData;
66
  public subSoftware;
67
  public subOrps;
68 55417 k.triantaf
  @ViewChild(StatisticsForDashboardComponent) statistics: StatisticsForDashboardComponent = null;
69
  public activeTab = "publication";
70 56138 argiro.kok
  public show: string = 'overview';
71 55417 k.triantaf
72 56817 konstantin
  searchLinkToPublications: string = null;
73
  searchLinkToDatasets: string = null;
74
  searchLinkToSoftware: string = null;
75
  searchLinkToOrps: string = null;
76
  searchLinkToProjects: string = null;
77
  searchLinkToDataProviders: string = null;
78
  searchLinkToAdvancedPublications: string = null;
79
  shareInZenodoPage: string = null;
80 57548 k.triantaf
  public routerHelper: RouterHelper = new RouterHelper();
81 57061 k.triantaf
  private user: User;
82
  private loginCheck: boolean = false;
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 56817 konstantin
        this.searchLinkToPublications = this.properties.searchLinkToPublications;
116
        this.searchLinkToDatasets = this.properties.searchLinkToDatasets;
117
        this.searchLinkToSoftware = this.properties.searchLinkToSoftware;
118
        this.searchLinkToOrps = this.properties.searchLinkToOrps;
119
        this.searchLinkToProjects = this.properties.searchLinkToProjects;
120
        this.searchLinkToDataProviders = this.properties.searchLinkToDataProviders;
121
        this.searchLinkToAdvancedPublications = this.properties.searchLinkToAdvancedPublications;
122
        this.shareInZenodoPage = this.properties.shareInZenodoPage;
123 56841 konstantin
        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 57548 k.triantaf
        this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
127
          this.user = user;
128 57061 k.triantaf
          this.loginCheck = true;
129 57548 k.triantaf
        });
130 55417 k.triantaf
        if (this.communityId != null && this.communityId != '') {
131
          this._communityService.getCommunity(this.properties, this.properties.communityAPI + this.communityId).subscribe(
132
            community => {
133
              if (typeof document !== 'undefined') {
134
                HelperFunctions.scroll();
135
              }
136
              this.community = community;
137
              if (this.properties.environment == "development") {
138
                this.params = {communityId: community.communityId};
139
              }
140
              this._meta.updateTag({content: community.description}, "name='description'");
141
              this._meta.updateTag({content: community.description}, "property='og:description'");
142
              this._meta.updateTag({content: community.title}, "property='og:title'");
143
              this._title.setTitle(community.title);
144
              if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
145 57548 k.triantaf
                this.piwiksub = this._piwikService.trackView(this.properties, community.title, PiwikHelper.getSiteId(this.communityId, this.properties.environment)).subscribe();
146 55417 k.triantaf
              }
147
              if (this.community.zenodoCommunity) {
148
                this._ΖenodoCommunitieService.getZenodoCommunityById(this.properties, this.properties.zenodoCommunities + this.community.zenodoCommunity, null).subscribe(
149
                  result => {
150
                    this.masterZenodoCommunity = result;
151 51621 argiro.kok
152 55417 k.triantaf
                  },
153
                  error => {
154
                    // var emptyCommunity:ZenodoCommunityInfo = new ZenodoCommunityInfo();
155
                    // emptyCommunity.id = this.masterZenodoCommunityId;
156
                    // emptyCommunity.title = this.masterZenodoCommunityId;
157
                    // this.masterZenodoCommunity = emptyCommunity;
158
                    //console.log("Master Zenodo community'" + this.community.zenodoCommunity + "' couldn't be loaded");
159
                    this.handleError("Error getting Master Zenodo community with id: " + this.community.zenodoCommunityId, error);
160 53968 argiro.kok
161 55417 k.triantaf
                  }
162
                );
163
              }
164
              this._searchZenodoCommunitiesService.searchZCommunities(this.properties, this.communityId).subscribe(
165
                result => {
166
                  this.zenodoCommunityIdS = result;
167 53968 argiro.kok
168
169 55417 k.triantaf
                },
170
                error => {
171
                  //console.error("list of zenodo communities couldn't be loaded");
172
                  this.handleError("Error getting list of zenodo communities for community with openaire id: " + this.communityId, error);
173
                } //this.handleError('System error retrieving community profile', error)
174
              );
175 53968 argiro.kok
176 55417 k.triantaf
              //console.log(community);
177
            });
178 53968 argiro.kok
179 57548 k.triantaf
          this.countResearchResults("publication");
180
          this.countResearchResults("dataset");
181
          this.countResearchResults("software");
182
          this.countResearchResults("other");
183 50980 sofia.balt
184 57548 k.triantaf
          this._searchCommunityProjectsService.countTotalProjects(this.properties, this.communityId).subscribe(
185
            projectTotal => {
186
              this.projectTotal = projectTotal;
187
              //console.log(projectTotal);
188
            },
189
            error => {
190
              this.handleError("Error getting number of projects for community with id: " + this.communityId, error);
191
            }
192
          );
193 51238 sofia.balt
194 57548 k.triantaf
          this._searchCommunityDataprovidersService.countTotalDataproviders(this.properties, this.communityId).subscribe(
195
            contentProviderTotal => {
196
              this.contentProviderTotal = contentProviderTotal;
197
              //console.log(contentProviderTotal);
198
            },
199
            error => {
200
              this.handleError("Error getting number of content providers for community with id: " + this.communityId, error);
201
            }
202 55417 k.triantaf
          );
203 53968 argiro.kok
204 55417 k.triantaf
          // this._searchEntriesService.countTotal(this.properties.communityAPI+this.communityId+'/organizations').subscribe(
205
          //   organizationTotal => {
206
          //             this.organizationTotal = organizationTotal;
207
          //             console.log(organizationTotal);
208
          //   });
209 50518 sofia.balt
210 50980 sofia.balt
211 55417 k.triantaf
          /**/
212 55996 argiro.kok
          this.config.getCommunityInformation(this.properties, this.communityId).subscribe(
213 55417 k.triantaf
            res => {
214
              this.communityInfo = res;
215
            },
216
            error => {
217
              //console.log(error)
218
              this.handleError("Error getting community with id: " + this.communityId, error);
219
            }
220
          );
221
        }
222
      });
223 50428 argiro.kok
  }
224 50941 sofia.balt
225 57085 konstantin
  public countResearchResults(resultType: string) {
226 57548 k.triantaf
    this._searchResearchResultsService.countTotalResults(resultType, this.properties, "&fq=communityid=" + this.communityId).subscribe(
227 57085 konstantin
      researchResultsTotal => {
228
        this.setTotal(resultType, researchResultsTotal);
229 57548 k.triantaf
        if (resultType == "publication") {
230 57085 konstantin
          this.searchResearchResults(resultType, this.publicationTotal, this.publicationResults);
231 54863 konstantin
        }
232 57085 konstantin
      },
233
      error => {
234 57548 k.triantaf
        this.handleError("Error getting number of " + this.getEntityName(resultType, true, true) + " for community with id: " + this.communityId, error);
235 57085 konstantin
      }
236
    );
237 53477 sofia.balt
  }
238
239 57085 konstantin
  public searchResearchResults(resultType: string, resultsTotal: number, results: Array<any>) {
240
    this.setActiveTab(resultType);
241 53477 sofia.balt
242 57085 konstantin
    if (resultsTotal > 0 && results == null) {
243
      this.showLoading = true;
244 53477 sofia.balt
245 57085 konstantin
      this._searchResearchResultsService.search(resultType, "", "&fq=communityid=" + this.communityId, 1, 5, "resultdateofacceptance,descending", [], this.properties).subscribe(
246
        researchResults => {
247
          this.setResults(resultType, researchResults[1]);
248 55417 k.triantaf
          this.showLoading = false;
249 54863 konstantin
        },
250
        error => {
251 57548 k.triantaf
          this.handleError("Error getting " + this.getEntityName(resultType, true, true) + " for community with id: " + this.communityId, error);
252 54863 konstantin
        }
253
      );
254 53477 sofia.balt
    }
255
  }
256
257 50428 argiro.kok
  public ngOnDestroy() {
258 55417 k.triantaf
    if (this.piwiksub) {
259 50428 argiro.kok
      this.piwiksub.unsubscribe();
260
    }
261
  }
262 51847 myrto.kouk
263 55271 argiro.kok
  isEntityEnabled(entity: string) {
264 55417 k.triantaf
    return this.communityInfo.entities.some(x => x['pid'] == entity && x['isEnabled'] === true);
265 51847 myrto.kouk
  }
266 55417 k.triantaf
267 55271 argiro.kok
  isRouteEnabled(route: string) {
268 55417 k.triantaf
    return this.communityInfo.pages.some(x => x['route'] == route && x['isEnabled'] === true);
269 53968 argiro.kok
  }
270 55302 argiro.kok
271 55417 k.triantaf
  showInvite() {
272 57061 k.triantaf
    return this.loginCheck && this.isManager();
273 55302 argiro.kok
  }
274
275 55417 k.triantaf
  isManager() {
276 57548 k.triantaf
    if (!this.user) {
277 57061 k.triantaf
      return false;
278
    }
279
    var email = this.user.email;
280 55417 k.triantaf
    var index = -1;
281
    if (email && this.community != null && this.community.managers != null) {
282
      index = this.community.managers.indexOf(email);
283 54047 argiro.kok
    }
284 57061 k.triantaf
    return Session.isPortalAdministrator(this.user) || Session.isCommunityCurator(this.user) || index != -1;
285 54047 argiro.kok
  }
286 54863 konstantin
287
  private handleError(message: string, error) {
288 55417 k.triantaf
    console.error("Community (component): " + message, error);
289 54863 konstantin
  }
290 55271 argiro.kok
291 55417 k.triantaf
  getSearchPlaceHolder() {
292 55271 argiro.kok
    var entities = [];
293 55417 k.triantaf
    if (this.isEntityEnabled("publication")) {
294 55271 argiro.kok
      entities.push("publications");
295
    }
296 55417 k.triantaf
    if (this.isEntityEnabled("dataset")) {
297 55271 argiro.kok
      entities.push("research data");
298
    }
299 55417 k.triantaf
    if (this.isEntityEnabled("software")) {
300 55271 argiro.kok
      entities.push("software");
301
    }
302 55417 k.triantaf
    if (this.isEntityEnabled("orp")) {
303 55271 argiro.kok
      entities.push("other research products");
304
    }
305 55417 k.triantaf
    return "Search" + ((entities.length > 0) ? (" for " + entities.join(', ') + "...") : "");
306 55283 argiro.kok
  }
307 55271 argiro.kok
308 55417 k.triantaf
  countOtherGraphs() {
309
    var count = 0;
310
    if (this.statistics && this.statistics.allowedEntities) {
311
      for (var entity of this.statistics.allowedEntities) {
312
        if (this.statistics.statisticsSum[entity].total > 0 && this.statistics.allowedCharts[entity].length > 0 && this.activeTab != entity) {
313
          count += this.statistics.allowedCharts[entity].length;
314
        }
315 55283 argiro.kok
      }
316
    }
317 55417 k.triantaf
    return count;
318 55271 argiro.kok
  }
319 55417 k.triantaf
320
  createParams(param) {
321 55366 argiro.kok
    return StringUtils.quote(StringUtils.URIEncode(param));
322 55417 k.triantaf
  }
323 55283 argiro.kok
324 57085 konstantin
  private setActiveTab(entityType: string) {
325 57548 k.triantaf
    if (entityType == "other") {
326 57085 konstantin
      this.activeTab = "orp";
327
    } else {
328
      this.activeTab = entityType;
329
    }
330
  }
331
332
  private setResults(entityType: string, results: Array<any>) {
333 57548 k.triantaf
    if (entityType == "publication") {
334 57085 konstantin
      this.publicationResults = results;
335 57548 k.triantaf
    } else if (entityType == "dataset") {
336 57085 konstantin
      this.researchDataResults = results;
337 57548 k.triantaf
    } else if (entityType == "software") {
338 57085 konstantin
      this.softwareResults = results;
339 57548 k.triantaf
    } else if (entityType == "other") {
340 57085 konstantin
      this.orpResults = results;
341
    }
342
  }
343
344
  private setTotal(entityType: string, total: number) {
345 57548 k.triantaf
    if (entityType == "publication") {
346 57085 konstantin
      this.publicationTotal = total;
347 57548 k.triantaf
    } else if (entityType == "dataset") {
348 57085 konstantin
      this.researchDataTotal = total;
349 57548 k.triantaf
    } else if (entityType == "software") {
350 57085 konstantin
      this.softwareTotal = total;
351 57548 k.triantaf
    } else if (entityType == "other") {
352 57085 konstantin
      this.orpTotal = total;
353
    }
354
  }
355
356 57548 k.triantaf
  private getEntityName(entityType: string, plural: boolean, full: boolean): string {
357
    if (entityType == "publication") {
358 57085 konstantin
      return "publication" + (plural ? "s" : "");
359 57548 k.triantaf
    } else if (entityType == "dataset") {
360 57085 konstantin
      return (full ? "research data" : ("dataset" + (plural ? "s" : "")));
361 57548 k.triantaf
    } else if (entityType == "software") {
362 57085 konstantin
      return "software";
363 57548 k.triantaf
    } else if (entityType == "other") {
364 57085 konstantin
      return (full ? ("other research product" + (plural ? "s" : "")) : "other");
365
    }
366
  }
367 55283 argiro.kok
}