Project

General

Profile

1
import { Component, Input } from '@angular/core';
2
import {ActivatedRoute} from '@angular/router';
3
import 'rxjs';
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 && !tooltip" [ngClass]=styleName>
13
    <div *ngFor="let text of texts " [innerHTML]="text.content | safeHtml">
14
    </div>
15
  </div>
16
  <span *ngIf=" texts  && texts.length > 0 && tooltip" >
17
  <span   uk-tooltip="pos:right; delay:10; "
18
          title="{{buildTooltip()}}">
19
     <span class="uk-icon">&nbsp;<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="info" ratio="1"><path d="M12.13,11.59 C11.97,12.84 10.35,14.12 9.1,14.16 C6.17,14.2 9.89,9.46 8.74,8.37 C9.3,8.16 10.62,7.83 10.62,8.81 C10.62,9.63 10.12,10.55 9.88,11.32 C8.66,15.16 12.13,11.15 12.14,11.18 C12.16,11.21 12.16,11.35 12.13,11.59 C12.08,11.95 12.16,11.35 12.13,11.59 L12.13,11.59 Z M11.56,5.67 C11.56,6.67 9.36,7.15 9.36,6.03 C9.36,5 11.56,4.54 11.56,5.67 L11.56,5.67 Z"></path><circle fill="none" stroke="#000" stroke-width="1.1" cx="10" cy="10" r="9"></circle></svg></span>
20
    </span>
21
  </span>
22
`
23
})
24
export class HelperComponent {
25
  texts=[];
26
  @Input() style:boolean = false;
27
  @Input() position:string = 'right';
28
  @Input() before: boolean;
29
  @Input() div: string;
30
  @Input() styleName:string = '';
31
  @Input() tooltip:boolean = false;
32
  sub:any;
33
  properties:EnvProperties;
34
  communityId = null;
35
  constructor (private _service: HelperService, private route: ActivatedRoute,) {}
36

    
37
  ngOnInit() {
38
    this.route.data
39
      .subscribe((data: { envSpecific: EnvProperties }) => {
40
         this.properties = data.envSpecific;
41
         this.route.queryParams.subscribe(
42
           params => {
43
                 this.communityId = params['communityId'];
44
                 if(!this.communityId){
45
                   this.communityId  = ConnectHelper.getCommunityFromDomain(this.properties.domain);
46
                 }
47
                  if(!this.communityId){
48
                  this.communityId = this.properties.adminToolsCommunity;
49
                  }
50
                  if(this.properties.enableHelper && typeof document != 'undefined'){
51
                    //this.sub = this._service.getHelper(location.pathname, this.properties).subscribe(
52
                    this.sub = this._service.getHelper(location.pathname, this.position, this.before, this.div, this.properties, this.communityId).subscribe(
53
                      data => {
54
                        //this.texts =(data && data.content && data.content[this.position] )? data.content[this.position]:[];
55
                        this.texts = data;
56
                      },
57
                      err => {
58
                        //console.log(err);
59
                        if(this.div) {
60
                          this.handleError("Error getting helper for route: "+location.pathname+" and div: "+this.div+" in community with id: "+this.communityId, err);
61
                        } else {
62
                          this.handleError("Error getting helper for route: "+location.pathname+", position: "+this.position+", before parameter:"+this.before+" in community with id: "+this.communityId, err);
63
                        }
64
                      }
65
                    );
66
                  }
67
               });
68
      });
69
  }
70

    
71
  ngOnDestroy() {
72
    if(this.sub){
73
      this.sub.unsubscribe();
74
    }
75
  }
76

    
77
buildTooltip():string{
78
  var text:string="<div class='uk-padding-small uk-width-xxlarge'>";
79
  for(var i=0; i< this.texts.length; i++){
80
    text+=this.texts[i].content;
81
  }
82
  text+="</div>";
83
  return text;
84
}
85

    
86
  private handleError(message: string, error) {
87
    console.error("Helper (component): "+message, error);
88
  }
89
}
(1-1/4)