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
|
import {StringUtils} from '../openaireLibrary/utils/string-utils.class';
|
12
|
|
13
|
@Component({
|
14
|
selector: 'affiliations',
|
15
|
templateUrl: './affiliations.component.html'
|
16
|
})
|
17
|
export class AffiliationsComponent {
|
18
|
@Input() getAffiliationsFromAPI: boolean = false;
|
19
|
@Input() longView: boolean = false;
|
20
|
@Input() communityFirstPage: boolean = false;
|
21
|
@Input() affiliationsInSlider: number = 5;
|
22
|
@Input() affiliations: Affiliation[] = [];
|
23
|
@Input() sliderOptions = '';
|
24
|
@Input() arrows = true;
|
25
|
|
26
|
public showLoading: boolean = false;
|
27
|
|
28
|
communityId: string;
|
29
|
properties:EnvProperties;
|
30
|
|
31
|
public piwiksub: any;
|
32
|
public url: string = null;
|
33
|
public pageTitle: string = "Related Organizations";
|
34
|
|
35
|
constructor ( private route: ActivatedRoute, private _router: Router,
|
36
|
private _meta: Meta,
|
37
|
private _title: Title,
|
38
|
private seoService: SEOService,
|
39
|
private _piwikService: PiwikService,
|
40
|
private affiliationService: AffiliationService) {}
|
41
|
|
42
|
public ngOnInit() {
|
43
|
this.route.data
|
44
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
45
|
this.route.queryParams.subscribe(
|
46
|
communityId => {
|
47
|
this.communityId = ConnectHelper.getCommunityFromDomain(data.envSpecific.domain);
|
48
|
if(!this.communityId) {
|
49
|
this.communityId = communityId['communityId'];
|
50
|
}
|
51
|
|
52
|
this.properties = data.envSpecific;
|
53
|
if(this.longView) {
|
54
|
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
|
55
|
this.piwiksub = this._piwikService.trackView(this.properties, this.pageTitle, PiwikHelper.getSiteId(this.communityId, this.properties.environment)).subscribe();
|
56
|
}
|
57
|
this.url = this.properties.baseLink + this._router.url;
|
58
|
this.seoService.createLinkForCanonicalURL(this.url);
|
59
|
this.updateUrl(this.url);
|
60
|
this.updateTitle(this.pageTitle);
|
61
|
this.updateDescription("OpenAIRE - Connect, Community Gateway, research community, organizations");
|
62
|
}
|
63
|
if(this.getAffiliationsFromAPI) {
|
64
|
this.showLoading = true;
|
65
|
this.affiliationService.initAffiliations(this.properties, this.properties.communityAPI + this.communityId + "/organizations");
|
66
|
this.affiliationService.affiliations.subscribe(
|
67
|
affiliations => {
|
68
|
this.affiliations = affiliations;
|
69
|
this.showLoading = false;
|
70
|
},
|
71
|
error => {
|
72
|
console.error("Affiliations Component: Error getting affiliations for community with id: "+this.communityId, error);
|
73
|
this.showLoading = false;
|
74
|
}
|
75
|
);
|
76
|
}
|
77
|
});
|
78
|
});
|
79
|
}
|
80
|
|
81
|
public ngOnDestroy() {
|
82
|
if (this.piwiksub) {
|
83
|
this.piwiksub.unsubscribe();
|
84
|
}
|
85
|
}
|
86
|
|
87
|
public urlPrefix(url: string): string {
|
88
|
return StringUtils.urlPrefix(url);
|
89
|
}
|
90
|
|
91
|
private updateDescription(description: string) {
|
92
|
this._meta.updateTag({content: description}, "name='description'");
|
93
|
this._meta.updateTag({content: description}, "property='og:description'");
|
94
|
}
|
95
|
|
96
|
private updateTitle(title: string) {
|
97
|
var _title = ((title.length > 50) ? title.substring(0, 50) : title);
|
98
|
this._title.setTitle(_title);
|
99
|
this._meta.updateTag({content: _title}, "property='og:title'");
|
100
|
}
|
101
|
|
102
|
private updateUrl(url: string) {
|
103
|
this._meta.updateTag({content: url}, "property='og:url'");
|
104
|
}
|
105
|
}
|