import {Component, Input} from '@angular/core'; import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties'; import {ActivatedRoute, Router} from "@angular/router"; import {CommunityService} from "../openaireLibrary/connect/community/community.service"; import {ConnectHelper} from "../openaireLibrary/connect/connectHelper"; import {HelperFunctions} from "../openaireLibrary/utils/HelperFunctions.class"; import {HelperService} from "../openaireLibrary/utils/helper/helper.service"; import {Meta, Title} from "@angular/platform-browser"; import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service"; import {PiwikService} from "../openaireLibrary/utils/piwik/piwik.service"; import {PiwikHelper} from "../utils/piwikHelper"; import {StringUtils} from "../openaireLibrary/utils/string-utils.class"; import {Breadcrumb} from "../openaireLibrary/utils/breadcrumbs/breadcrumbs.component"; @Component({ selector: 'subjects', template: `
Subjects
` }) export class SubjectsComponent { public subjects: string[]; @Input() communityId = null; public showLoading = true; public properties: EnvProperties; public pageContents = null; public divContents = null; public piwiksub: any; public url: string = null; public pageTitle: string = "Subjects"; public breadcrumbs: Breadcrumb[] = [{name: 'home', route: '/'}, {name: 'about - subjects'}]; constructor (private route: ActivatedRoute, private communityService: CommunityService, private _router: Router, private helper: HelperService, private _meta: Meta, private _title: Title, private seoService: SEOService, private _piwikService: PiwikService) {} ngOnInit() { this.route.data.subscribe((data: { envSpecific: EnvProperties }) => { this.showLoading = true; this.properties = data.envSpecific; if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) { this.piwiksub = this._piwikService.trackView(this.properties, this.pageTitle, PiwikHelper.getSiteId(this.communityId, this.properties.environment)).subscribe(); } this.url = this.properties.baseLink + this._router.url; this.seoService.createLinkForCanonicalURL(this.url); this.updateUrl(this.url); this.updateTitle(this.pageTitle); this.updateDescription("OpenAIRE - Connect, Community Gateway, research community"); this.route.queryParams.subscribe(data => { this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain); if(!this.communityId) { this.communityId = data['communityId']; } //this.getDivContents(); this.getPageContents(); this.communityService.getCommunity(this.properties, this.properties.communityAPI + this.communityId).subscribe(community => { this.subjects = community.subjects; this.showLoading = false; HelperFunctions.scroll(); }); }); }); } createParams(param) { return StringUtils.quote(StringUtils.URIEncode(param)); } ngOnDestroy() { if(this.piwiksub) { this.piwiksub.unsubscribe(); } } private getPageContents() { this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => { this.pageContents = contents; }) } private getDivContents() { this.helper.getDivHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => { this.divContents = contents; }) } private updateDescription(description: string) { this._meta.updateTag({content: description}, "name='description'"); this._meta.updateTag({content: description}, "property='og:description'"); } private updateTitle(title: string) { var _title = ((title.length > 50) ? title.substring(0, 50) : title); this._title.setTitle(_title); this._meta.updateTag({content: _title}, "property='og:title'"); } private updateUrl(url: string) { this._meta.updateTag({content: url}, "property='og:url'"); } }