Project

General

Profile

1
import { Component, Input } from '@angular/core';
2
import {ActivatedRoute} from '@angular/router';
3
import 'rxjs/Rx';
4
import {HtmlPageService} from './htmlPage.service';
5
import{EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
6
import {ConnectHelper} from '../openaireLibrary/connect/connectHelper';
7
import {SafeHtmlPipe} from '../openaireLibrary/utils/pipes/safeHTML.pipe';
8

    
9
@Component({
10
  selector: 'html-page',
11
  template: `
12
    <div [innerHTML]="content | safeHtml"></div>
13
`
14
})
15
export class HtmlPageComponent {
16
  public content:string="";
17
  sub:any;
18
  properties:EnvProperties;
19
  private communityId: string = null;
20
  constructor (private _service: HtmlPageService, private route: ActivatedRoute,) {}
21

    
22
  ngOnInit() {
23
    this.route.data
24
      .subscribe((data: { envSpecific: EnvProperties }) => {
25
         this.properties = data.envSpecific;
26
         this.route.queryParams.subscribe(
27
           params => {
28
                 this.communityId  = ConnectHelper.getCommunityFromDomain(this.properties.domain);
29
                 if(!this.communityId) {
30
                   this.communityId = params['communityId'];
31
                 }
32

    
33
                  if(!this.communityId){
34
                    this.communityId = this.properties.adminToolsCommunity;
35
                  }
36
                  if(location){
37
                    this.sub = this._service.getHtmlContent(location.pathname, this.properties, this.communityId).subscribe(
38
                      data => {
39
                        if(data.length > 0) {
40
                          this.content = data[0].content;
41
                        }
42
                      },
43
                      err => {
44
                        //console.log(err);
45
                        this.handleError("Error getting html content with route: "+location.pathname+" for community with id: "+this.communityId, err);
46
                      }
47
                    );
48
                  }
49
               });
50
      });
51
  }
52

    
53
  ngOnDestroy() {
54
    if(this.sub){
55
      this.sub.unsubscribe();
56
    }
57
  }
58

    
59
  private handleError(message: string, error) {
60
    console.error("Html Page: "+message, error);
61
  }
62
}
(1-1/3)