1
|
import {Component, HostListener, OnDestroy, OnInit} from '@angular/core';
|
2
|
import {Meta, Title} from '@angular/platform-browser';
|
3
|
import {ActivatedRoute, Router} from '@angular/router';
|
4
|
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
|
5
|
import {properties} from '../../environments/environment';
|
6
|
import {Subscriber, Subscription} from 'rxjs';
|
7
|
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
|
8
|
import {SEOService} from '../openaireLibrary/sharedComponents/SEO/SEO.service';
|
9
|
|
10
|
@Component({
|
11
|
selector: 'resources',
|
12
|
templateUrl: 'resources.component.html',
|
13
|
styleUrls: ['resources.component.css'],
|
14
|
})
|
15
|
export class ResourcesComponent implements OnInit, OnDestroy {
|
16
|
properties: EnvProperties = properties;
|
17
|
description = "OpenAIRE Provide. The resources of the OpenAIRE UsageCounts Service are available through the OpenAIRE PROVIDE product, which is serving the content providers. APIs and Reports.";
|
18
|
title = "OpenAIRE - UsageCounts | Resources";
|
19
|
subs: Subscription[] = [];
|
20
|
large: boolean = false;
|
21
|
|
22
|
constructor(private router: Router,
|
23
|
private _title: Title, private _piwikService: PiwikService,
|
24
|
private _meta: Meta, private seoService: SEOService,
|
25
|
private route: ActivatedRoute) {
|
26
|
}
|
27
|
|
28
|
@HostListener('window:resize', ['$event'])
|
29
|
onResize(event) {
|
30
|
if(event.target.innerWidth > 959 && this.large === false) {
|
31
|
this.large = true;
|
32
|
} else if(event.target.innerWidth < 960 && this.large === true){
|
33
|
this.large = false;
|
34
|
}
|
35
|
}
|
36
|
|
37
|
ngOnInit() {
|
38
|
if(typeof window !== 'undefined') {
|
39
|
this.large = window.innerWidth > 959;
|
40
|
}
|
41
|
this._title.setTitle(this.title);
|
42
|
this._meta.updateTag({content: this.description}, "name='description'");
|
43
|
this._meta.updateTag({content: this.description}, "property='og:description'");
|
44
|
this._meta.updateTag({content: this.title}, "property='og:title'");
|
45
|
this._title.setTitle(this.title);
|
46
|
let url = this.properties.domain + this.properties.baseLink + this.router.url;
|
47
|
this.seoService.createLinkForCanonicalURL(url, false);
|
48
|
this._meta.updateTag({content: url}, "property='og:url'");
|
49
|
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
|
50
|
this.subs.push(this._piwikService.trackView(this.properties, this.title).subscribe());
|
51
|
}
|
52
|
this.subs.push(this.route.fragment.subscribe(fragment => {
|
53
|
setTimeout(() => {
|
54
|
this.goTo(fragment);
|
55
|
}, 100);
|
56
|
}));
|
57
|
}
|
58
|
|
59
|
public ngOnDestroy() {
|
60
|
this.subs.forEach(subscription => {
|
61
|
if (subscription instanceof Subscriber) {
|
62
|
subscription.unsubscribe();
|
63
|
}
|
64
|
});
|
65
|
}
|
66
|
|
67
|
goTo(id: string) {
|
68
|
const yOffset = -100;
|
69
|
const element = document.getElementById(id);
|
70
|
if(element) {
|
71
|
const y = element.getBoundingClientRect().top + window.pageYOffset + yOffset;
|
72
|
window.scrollTo({top: y, behavior: 'smooth'});
|
73
|
}
|
74
|
}
|
75
|
}
|