Project

General

Profile

1
import {Component, Input}       from '@angular/core';
2
import {ActivatedRoute, Router} from '@angular/router';
3
import {Title, Meta}            from '@angular/platform-browser';
4
import {EnvProperties}          from '../openaireLibrary/utils/properties/env-properties';
5
import {AffiliationService}     from "../openaireLibrary/connect/affiliations/affiliation.service";
6
import {Affiliation}            from "../openaireLibrary/utils/entities/CuratorInfo";
7
import {ConnectHelper}          from "../openaireLibrary/connect/connectHelper";
8
import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service";
9
import {PiwikService} from "../openaireLibrary/utils/piwik/piwik.service";
10
import {PiwikHelper} from "../utils/piwikHelper";
11

    
12
@Component({
13
  selector: 'affiliations',
14
  templateUrl: './affiliations.component.html'
15
})
16
export class AffiliationsComponent {
17
  @Input() getAffiliationsFromAPI: boolean = false;
18
  @Input() longView: boolean = false;
19
  @Input() communityFirstPage: boolean = false;
20
  @Input() affiliationsInSlider: number = 5;
21
  @Input() affiliations: Affiliation[] = [];
22
  @Input() sliderOptions = '';
23
  @Input() arrows = true;
24

    
25
  public showLoading: boolean = false;
26

    
27
  communityId: string;
28
  properties:EnvProperties;
29

    
30
  public piwiksub: any;
31
  public url: string = null;
32
  public pageTitle: string = "Related Organizations";
33

    
34
  constructor ( private  route: ActivatedRoute, private _router: Router,
35
                private _meta: Meta,
36
                private _title: Title,
37
                private seoService: SEOService,
38
                private _piwikService: PiwikService,
39
                private affiliationService: AffiliationService) {}
40

    
41
  public ngOnInit() {
42
    this.route.data
43
      .subscribe((data: { envSpecific: EnvProperties }) => {
44
        this.route.queryParams.subscribe(
45
          communityId => {
46
            this.communityId  = ConnectHelper.getCommunityFromDomain(data.envSpecific.domain);
47
            if(!this.communityId) {
48
              this.communityId = communityId['communityId'];
49
            }
50

    
51
            this.properties = data.envSpecific;
52
            if(this.longView) {
53
              if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
54
                this.piwiksub = this._piwikService.trackView(this.properties, this.pageTitle, PiwikHelper.getSiteId(this.communityId, this.properties.environment)).subscribe();
55
              }
56
              this.url = this.properties.baseLink + this._router.url;
57
              this.seoService.createLinkForCanonicalURL(this.url);
58
              this.updateUrl(this.url);
59
              this.updateTitle(this.pageTitle);
60
              this.updateDescription("OpenAIRE - Connect, Community Gateway, research community, organizations");
61
            }
62
            if(this.getAffiliationsFromAPI) {
63
              this.showLoading = true;
64
              this.affiliationService.initAffiliations(this.properties, this.properties.communityAPI + this.communityId + "/organizations");
65
              this.affiliationService.affiliations.subscribe(
66
                affiliations => {
67
                  this.affiliations = affiliations;
68
                  this.showLoading = false;
69
                },
70
                error => {
71
                  console.error("Affiliations Component: Error getting affiliations for community with id: "+this.communityId, error);
72
                  this.showLoading = false;
73
                }
74
              );
75
            }
76
          });
77
      });
78
  }
79

    
80
  public ngOnDestroy() {
81
    if (this.piwiksub) {
82
      this.piwiksub.unsubscribe();
83
    }
84
  }
85

    
86
  private updateDescription(description: string) {
87
    this._meta.updateTag({content: description}, "name='description'");
88
    this._meta.updateTag({content: description}, "property='og:description'");
89
  }
90

    
91
  private updateTitle(title: string) {
92
    var _title = ((title.length > 50) ? title.substring(0, 50) : title);
93
    this._title.setTitle(_title);
94
    this._meta.updateTag({content: _title}, "property='og:title'");
95
  }
96

    
97
  private updateUrl(url: string) {
98
    this._meta.updateTag({content: url}, "property='og:url'");
99
  }
100
}
(2-2/3)