Project

General

Profile

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

    
11
@Component({
12
  selector: 'learn-how',
13
  styleUrls: ['learn-how.component.css'],
14
  templateUrl: 'learn-how.component.html',
15
})
16
export class LearnHowComponent {
17
  public pageContents = null;
18
  public divContents = null;
19
  
20
  public url: string = null;
21
  public pageTitle: string = "OpenAIRE - Monitor | Learn How";
22
  public description: string = "Learn the process: Use the Monitor Dashboard to view your research results, open science. See how it works. Simplify research tracking & monitoring ";
23
  properties: EnvProperties;
24
  subscriptions = [];
25
  constructor(
26
    private route: ActivatedRoute,
27
    private _router: Router,
28
    private _meta: Meta,
29
    private _title: Title,
30
    private seoService: SEOService,
31
    private _piwikService: PiwikService,
32
    private helper: HelperService) {
33
  }
34
  
35
  public ngOnInit() {
36

    
37
    this.properties = properties;
38
    if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
39
      this.subscriptions.push(this._piwikService.trackView(this.properties, this.pageTitle, this.properties.piwikSiteId).subscribe());
40
    }
41
    this.url = this.properties.domain + this.properties.baseLink + this._router.url;
42
    this.seoService.createLinkForCanonicalURL(this.url);
43
    this.updateUrl(this.url);
44
    this.updateTitle(this.pageTitle);
45
    this.updateDescription("OpenAIRE - Monitor, Funders, Statistics, EC - Learn How");``
46
    //this.getDivContents();
47
    //this.getPageContents();
48

    
49
  }
50
  
51
  private getPageContents() {
52
    this.subscriptions.push(this.helper.getPageHelpContents(this.properties, 'monitor', this._router.url).subscribe(contents => {
53
      this.pageContents = contents;
54
    }));
55
  }
56
  
57
  private getDivContents() {
58
    this.subscriptions.push(this.helper.getDivHelpContents(this.properties, 'monitor', this._router.url).subscribe(contents => {
59
      this.divContents = contents;
60
    }));
61
  }
62

    
63
  ngOnDestroy() {
64
    this.subscriptions.forEach(subscription => {
65
      if (subscription instanceof Subscriber) {
66
        subscription.unsubscribe();
67
      }
68
    });
69
  }
70
  
71
  
72
  private updateDescription(description: string) {
73
    this._meta.updateTag({content: description}, "name='description'");
74
    this._meta.updateTag({content: description}, "property='og:description'");
75
  }
76
  
77
  private updateTitle(title: string) {
78
    var _title = ((title.length > 50) ? title.substring(0, 50) : title);
79
    this._title.setTitle(_title);
80
    this._meta.updateTag({content: _title}, "property='og:title'");
81
  }
82
  
83
  private updateUrl(url: string) {
84
    this._meta.updateTag({content: url}, "property='og:url'");
85
  }
86
}
(4-4/5)