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 = params['communityId'];
29
                 if(!this.communityId){
30
                    this.communityId  = ConnectHelper.getCommunityFromDomain(this.properties.domain);
31
                  }
32
                  if(!this.communityId){
33
                  this.communityId = this.properties.adminToolsCommunity;
34
                  }
35
                  if(location){
36
                    this.sub = this._service.getHtmlContent(location.pathname, this.properties, this.communityId).subscribe(
37
                      data => {
38
                        if(data.length > 0) {
39
                          this.content = data[0].content;
40
                        }
41
                      },
42
                      err => {
43
                        //console.log(err);
44
                        this.handleError("Error getting html content with route: "+location.pathname+" for community with id: "+this.communityId, err);
45
                      }
46
                    );
47
                  }
48
               });
49
      });
50
  }
51

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

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