Project

General

Profile

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

    
11
@Component({
12
  selector: 'html-page',
13
  template: `
14
    <schema2jsonld *ngIf="url" [URL]="url" [name]="pageTitle" type="other"></schema2jsonld>
15
    <helper *ngIf="pageContents && pageContents['top'] && pageContents['top'].length > 0" [texts]="pageContents['top']"></helper>
16
`
17
})
18
export class HtmlPageComponent {
19

    
20
  properties: EnvProperties;
21
  public pageContents = null;
22
  public divContents = null;
23

    
24
  @Input() url: string = null;
25
  @Input() pageTitle: string;
26
  @Input() description: string;
27
  piwiksub: any;
28
  communityId;
29

    
30
  constructor(private  route: ActivatedRoute, private _router: Router,
31
              private _meta: Meta,
32
              private _title: Title,
33
              private seoService: SEOService,
34
              private _piwikService: PiwikService,
35
              private helper: HelperService) {}
36

    
37
  public ngOnInit() {
38
    this.route.data
39
      .subscribe((data: { envSpecific: EnvProperties }) => {
40
        this.properties = data.envSpecific;
41

    
42
        if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
43
          this.piwiksub = this._piwikService.trackView(this.properties, this.pageTitle, this.properties.piwikSiteId).subscribe();
44
        }
45
        this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
46
        if (this.properties.environment == "development") {
47
          this.route.queryParams.subscribe(params => {
48
            this.communityId = (params['communityId']) ? params['communityId'] :  ConnectHelper.getCommunityFromDomain(this.properties.domain);
49
           })
50
        }
51
        //TODO set the proper URL
52
        this.url = this.properties.baseLink + this._router.url;
53
        this.seoService.createLinkForCanonicalURL(this.url);
54
        this.updateUrl(this.url);
55
        this.updateTitle(this.pageTitle);
56
        this.updateDescription(this.description);
57
        this.getPageContents();
58
      });
59
  }
60

    
61
  ngOnDestroy() {
62
    if(this.piwiksub) {
63
      this.piwiksub.unsubscribe();
64
    }
65
  }
66

    
67
  private updateDescription(description: string) {
68
    this._meta.updateTag({content: description}, "name='description'");
69
    this._meta.updateTag({content: description}, "property='og:description'");
70
  }
71

    
72
  private updateTitle(title: string) {
73
    var _title = ((title.length > 50) ? title.substring(0, 50) : title);
74
    this._title.setTitle(_title);
75
    this._meta.updateTag({content: _title}, "property='og:title'");
76
  }
77

    
78
  private updateUrl(url: string) {
79
    this._meta.updateTag({content: url}, "property='og:url'");
80
  }
81

    
82
  private getPageContents() {
83
    this.helper.getPageHelpContents(this.properties, this.communityId?this.communityId:"connect", this._router.url).subscribe(contents => {
84
      this.pageContents = contents;
85
    })
86
  }
87
}
(1-1/2)