2017-12-19 13:53:46 +01:00
import { Component , Input } from '@angular/core' ;
2018-02-05 14:14:59 +01:00
import { ActivatedRoute } from '@angular/router' ;
2017-12-19 13:53:46 +01:00
import 'rxjs/Rx' ;
import { HelperService } from './helper.service' ;
2018-02-05 14:14:59 +01:00
import { EnvProperties } from '../properties/env-properties' ;
2018-03-29 10:23:36 +02:00
import { ConnectHelper } from '../../connect/connectHelper' ;
2018-04-17 12:41:28 +02:00
import { SafeHtmlPipe } from '../pipes/safeHTML.pipe' ;
2017-12-19 13:53:46 +01:00
@Component ( {
selector : 'helper' ,
template : `
2018-07-25 15:56:02 +02:00
< div * ngIf = " texts && texts.length > 0 && !tooltip" [ ngClass ] = styleName >
2018-04-17 12:41:28 +02:00
< div * ngFor = "let text of texts " [ innerHTML ] = " text.content | safeHtml " >
2017-12-19 13:53:46 +01:00
< / div >
< / div >
2018-07-25 15:56:02 +02:00
< span * ngIf = " texts && texts.length > 0 && tooltip" >
< span uk - tooltip = "pos:right; delay:10; "
title = "{{buildTooltip()}}" >
< 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 >
< / span >
< / span >
2017-12-19 13:53:46 +01:00
`
} )
export class HelperComponent {
texts = [ ] ;
@Input ( ) style :boolean = false ;
@Input ( ) position :string = 'right' ;
2018-02-13 15:52:23 +01:00
@Input ( ) before : boolean ;
@Input ( ) div : string ;
2017-12-19 13:53:46 +01:00
@Input ( ) styleName :string = '' ;
2018-07-25 15:56:02 +02:00
@Input ( ) tooltip :boolean = false ;
2017-12-19 13:53:46 +01:00
sub :any ;
2018-02-05 14:14:59 +01:00
properties :EnvProperties ;
2018-03-29 10:23:36 +02:00
communityId = null ;
2018-02-05 14:14:59 +01:00
constructor ( private _service : HelperService , private route : ActivatedRoute , ) { }
2017-12-19 13:53:46 +01:00
ngOnInit() {
2018-02-05 14:14:59 +01:00
this . route . data
. subscribe ( ( data : { envSpecific : EnvProperties } ) = > {
this . properties = data . envSpecific ;
2018-03-29 10:23:36 +02:00
this . route . queryParams . subscribe (
params = > {
this . communityId = params [ 'communityId' ] ;
2019-03-01 12:29:52 +01:00
if ( ! this . communityId ) {
this . communityId = ConnectHelper . getCommunityFromDomain ( this . properties . domain ) ;
}
2018-03-29 10:23:36 +02:00
if ( ! this . communityId ) {
this . communityId = this . properties . adminToolsCommunity ;
}
2019-02-15 16:03:48 +01:00
if ( this . properties . enableHelper && typeof document != 'undefined' ) {
2018-03-29 10:23:36 +02:00
//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 = > {
2019-02-19 16:26:59 +01:00
//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 ) ;
}
2018-03-29 10:23:36 +02:00
}
) ;
}
} ) ;
2018-02-05 14:14:59 +01:00
} ) ;
2017-12-19 13:53:46 +01:00
}
2018-02-05 14:14:59 +01:00
2017-12-19 13:53:46 +01:00
ngOnDestroy() {
if ( this . sub ) {
this . sub . unsubscribe ( ) ;
}
}
2018-07-25 15:56:02 +02:00
buildTooltip ( ) : string {
var text :string = "<div class='uk-padding-small uk-width-xxlarge'>" ;
for ( var i = 0 ; i < this . texts . length ; i ++ ) {
text += this . texts [ i ] . content ;
}
text += "</div>" ;
return text ;
}
2019-02-19 16:26:59 +01:00
private handleError ( message : string , error ) {
console . error ( "Helper (component): " + message , error ) ;
}
2017-12-19 13:53:46 +01:00
}