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 {HelperService} from "../openaireLibrary/utils/helper/helper.service";
5
import {EnvProperties} from "../openaireLibrary/utils/properties/env-properties";
6
import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service";
7
import {PiwikService} from "../openaireLibrary/utils/piwik/piwik.service";
8

    
9
@Component({
10
  selector: 'content',
11
  templateUrl: './contentPage.component.html'
12
})
13
export class ContentPageComponent {
14

    
15
  properties: EnvProperties;
16
  public pageContents = null;
17
  public divContents = null;
18

    
19
  public url: string = null;
20
  public pageTitle: string = "OpenAIRE - Connect | Content Policy";
21
  piwiksub: any;
22

    
23
  constructor(private  route: ActivatedRoute, private _router: Router,
24
              private _meta: Meta,
25
              private _title: Title,
26
              private seoService: SEOService,
27
              private _piwikService: PiwikService,
28
              private helper: HelperService) {}
29

    
30
  public ngOnInit() {
31
    this.route.data
32
      .subscribe((data: { envSpecific: EnvProperties }) => {
33
        this.properties = data.envSpecific;
34

    
35
        if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
36
          this.piwiksub = this._piwikService.trackView(this.properties, this.pageTitle, this.properties.piwikSiteId).subscribe();
37
        }
38
        this.url = this.properties.baseLink + this._router.url;
39
        this.seoService.createLinkForCanonicalURL(this.url);
40
        this.updateUrl(this.url);
41
        this.updateTitle(this.pageTitle);
42
        this.updateDescription("content, open access");
43

    
44
        //this.getDivContents();
45
        this.getPageContents();
46
      });
47
  }
48

    
49
  ngOnDestroy() {
50
    if(this.piwiksub) {
51
      this.piwiksub.unsubscribe();
52
    }
53
  }
54

    
55
  private updateDescription(description: string) {
56
    this._meta.updateTag({content: description}, "name='description'");
57
    this._meta.updateTag({content: description}, "property='og:description'");
58
  }
59

    
60
  private updateTitle(title: string) {
61
    var _title = ((title.length > 50) ? title.substring(0, 50) : title);
62
    this._title.setTitle(_title);
63
    this._meta.updateTag({content: _title}, "property='og:title'");
64
  }
65

    
66
  private updateUrl(url: string) {
67
    this._meta.updateTag({content: url}, "property='og:url'");
68
  }
69

    
70
  private getPageContents() {
71
    this.helper.getPageHelpContents(this._router.url, this.properties, 'connect').subscribe(contents => {
72
      this.pageContents = contents;
73
    })
74
  }
75

    
76
  private getDivContents() {
77
    this.helper.getDivHelpContents(this._router.url, this.properties, 'connect').subscribe(contents => {
78
      this.divContents = contents;
79
    })
80
  }
81
}
(3-3/4)