Project

General

Profile

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

    
9
@Component({
10
  selector: 'helper',
11
  template: `
12
  <div *ngIf=" texts  && texts.length > 0" [ngClass]=styleName>
13
    <div *ngFor="let text of texts " [innerHTML]="text.content | safeHtml">
14
    </div>
15
  </div>
16
`
17
})
18
export class HelperComponent {
19
  texts=[];
20
  @Input() style:boolean = false;
21
  @Input() position:string = 'right';
22
  @Input() before: boolean;
23
  @Input() div: string;
24
  @Input() styleName:string = '';
25
  sub:any;
26
  properties:EnvProperties;
27
  communityId = null;
28
  constructor (private _service: HelperService, private route: ActivatedRoute,) {}
29

    
30
  ngOnInit() {
31
    this.route.data
32
      .subscribe((data: { envSpecific: EnvProperties }) => {
33
         this.properties = data.envSpecific;
34
         this.route.queryParams.subscribe(
35
           params => {
36
                 this.communityId = params['communityId'];
37
                  if(!this.communityId){
38
                   this.communityId  = ConnectHelper.getCommunityFromDomain(document.location.hostname);
39
                  }
40
                  if(!this.communityId){
41
                  this.communityId = this.properties.adminToolsCommunity;
42
                  }
43
                  if(this.properties.enableHelper && location){
44
                    //this.sub = this._service.getHelper(location.pathname, this.properties).subscribe(
45
                    this.sub = this._service.getHelper(location.pathname, this.position, this.before, this.div, this.properties, this.communityId).subscribe(
46
                      data => {
47
                        //this.texts =(data && data.content && data.content[this.position] )? data.content[this.position]:[];
48
                        this.texts = data;
49
                      },
50
                      err => {
51
                        console.log(err);
52

    
53
                      }
54
                    );
55
                  }
56
               });
57
      });
58
  }
59

    
60
  ngOnDestroy() {
61
    if(this.sub){
62
      this.sub.unsubscribe();
63
    }
64
  }
65

    
66

    
67
}
(1-1/4)