Project

General

Profile

1
import {Component, HostListener, OnDestroy, OnInit} from '@angular/core';
2
import {faqs} from './faqs';
3
import {ActivatedRoute, Router} from '@angular/router';
4
import {Meta, Title} from '@angular/platform-browser';
5
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
6
import {properties} from '../../environments/environment';
7
import {Subscriber, Subscription} from 'rxjs';
8
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
9
import {SEOService} from '../openaireLibrary/sharedComponents/SEO/SEO.service';
10

    
11
@Component({
12
  selector: 'about',
13
  templateUrl: 'about.component.html',
14
  styleUrls: ['about.component.css'],
15
})
16
export class AboutComponent implements OnInit, OnDestroy {
17
  faqs: any[] = faqs;
18
  properties: EnvProperties = properties;
19
  description = "UsageCounts service is an OpenAIRE service built to cover the needs of content providers and consumers and offer added value to assist them in reaching their goals. UsageCounts forms metrics of usage activity of Open Access Repositories categorizing the data retrieved by country, number of downloads, number of views, number of repositories and all derivative quantitative open metrics, comprehensively. Architecture. ";
20
  title = "OpenAIRE - UsageCounts | About";
21
  subs: Subscription[] = [];
22
  large: boolean = false;
23
  
24
  constructor(private route: ActivatedRoute,
25
              private router: Router,
26
              private _title: Title, private _piwikService: PiwikService,
27
              private _meta: Meta, private seoService: SEOService) {
28
  }
29
  
30
  @HostListener('window:resize', ['$event'])
31
  onResize(event) {
32
    if(event.target.innerWidth > 959 && this.large === false) {
33
      this.large = true;
34
    } else if(event.target.innerWidth < 960 && this.large === true){
35
      this.large = false;
36
    }
37
  }
38
  
39
  ngOnInit() {
40
    if(typeof window !== 'undefined') {
41
      this.large = window.innerWidth > 959;
42
    }
43
    this._title.setTitle(this.title);
44
    this._meta.updateTag({content: this.description}, "name='description'");
45
    this._meta.updateTag({content: this.description}, "property='og:description'");
46
    this._meta.updateTag({content: this.title}, "property='og:title'");
47
    this._title.setTitle(this.title);
48
    let url = this.properties.domain + this.properties.baseLink + this.router.url;
49
    this.seoService.createLinkForCanonicalURL(url, false);
50
    this._meta.updateTag({content: url}, "property='og:url'");
51
    if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
52
      this.subs.push(this._piwikService.trackView(this.properties, this.title).subscribe());
53
    }
54
    this.subs.push(this.route.fragment.subscribe(fragment => {
55
      setTimeout(() => {
56
        this.goTo(fragment);
57
      }, 100);
58
    }));
59
  }
60
  
61
  public ngOnDestroy() {
62
    this.subs.forEach(subscription => {
63
      if (subscription instanceof Subscriber) {
64
        subscription.unsubscribe();
65
      }
66
    });
67
  }
68
  
69
  goTo(id: string) {
70
    const yOffset = -100;
71
    const element = document.getElementById(id);
72
    if(element) {
73
      const y = element.getBoundingClientRect().top + window.pageYOffset + yOffset;
74
      window.scrollTo({top: y, behavior: 'smooth'});
75
    }
76
  }
77
}
(3-3/5)