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
import {Subscriber} from "rxjs";
11
import {properties} from "../../environments/environment";
12

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

    
22
  properties: EnvProperties;
23
  public pageContents = null;
24
  public divContents = null;
25

    
26
  @Input() url: string = null;
27
  @Input() pageTitle: string;
28
  @Input() description: string;
29
  private   subscriptions = [];
30
  communityId;
31

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

    
39
  public ngOnInit() {
40

    
41
        this.properties = properties;
42

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

    
60
  }
61

    
62
  ngOnDestroy() {
63
    this.subscriptions.forEach(subscription => {
64
      if (subscription instanceof Subscriber) {
65
        subscription.unsubscribe();
66
      }
67
    });
68
  }
69

    
70

    
71
  private updateDescription(description: string) {
72
    this._meta.updateTag({content: description}, "name='description'");
73
    this._meta.updateTag({content: description}, "property='og:description'");
74
  }
75

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

    
82
  private updateUrl(url: string) {
83
    this._meta.updateTag({content: url}, "property='og:url'");
84
  }
85

    
86
  private getPageContents() {
87
    this.subscriptions.push(this.helper.getPageHelpContents(this.properties, this.communityId?this.communityId:"connect", this._router.url).subscribe(contents => {
88
      this.pageContents = contents;
89
    }));
90
  }
91
}
(1-1/2)