import { Component, Input } from '@angular/core'; import {ActivatedRoute} from '@angular/router'; import 'rxjs/Rx'; import {HelperService} from './helper.service'; import{EnvProperties} from '../properties/env-properties'; import {ConnectHelper} from '../../connect/connectHelper'; import {SafeHtmlPipe} from '../pipes/safeHTML.pipe'; @Component({ selector: 'helper', template: `
  ` }) export class HelperComponent { texts=[]; @Input() style:boolean = false; @Input() position:string = 'right'; @Input() before: boolean; @Input() div: string; @Input() styleName:string = ''; @Input() tooltip:boolean = false; sub:any; properties:EnvProperties; communityId = null; constructor (private _service: HelperService, private route: ActivatedRoute,) {} ngOnInit() { this.route.data .subscribe((data: { envSpecific: EnvProperties }) => { this.properties = data.envSpecific; this.route.queryParams.subscribe( params => { this.communityId = params['communityId']; if(!this.communityId){ this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain); } if(!this.communityId){ this.communityId = this.properties.adminToolsCommunity; } if(this.properties.enableHelper && typeof document != 'undefined'){ //this.sub = this._service.getHelper(location.pathname, this.properties).subscribe( this.sub = this._service.getHelper(location.pathname, this.position, this.before, this.div, this.properties, this.communityId).subscribe( data => { //this.texts =(data && data.content && data.content[this.position] )? data.content[this.position]:[]; this.texts = data; }, err => { //console.log(err); if(this.div) { this.handleError("Error getting helper for route: "+location.pathname+" and div: "+this.div+" in community with id: "+this.communityId, err); } else { this.handleError("Error getting helper for route: "+location.pathname+", position: "+this.position+", before parameter:"+this.before+" in community with id: "+this.communityId, err); } } ); } }); }); } ngOnDestroy() { if(this.sub){ this.sub.unsubscribe(); } } buildTooltip():string{ var text:string="
"; for(var i=0; i< this.texts.length; i++){ text+=this.texts[i].content; } text+="
"; return text; } private handleError(message: string, error) { console.error("Helper (component): "+message, error); } }