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';
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'helper',
|
|
|
|
template: `
|
|
|
|
<div *ngIf=" texts && texts.length > 0" [ngClass]=styleName>
|
|
|
|
<div *ngFor="let text of texts " [innerHTML]="text.content">
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`
|
|
|
|
})
|
|
|
|
export class HelperComponent {
|
|
|
|
texts=[];
|
|
|
|
@Input() style:boolean = false;
|
|
|
|
@Input() position:string = 'right';
|
|
|
|
@Input() styleName:string = '';
|
|
|
|
sub:any;
|
2018-02-05 14:14:59 +01:00
|
|
|
properties:EnvProperties;
|
2017-12-19 13:53:46 +01:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
if(this.properties.enableHelper && location){
|
|
|
|
this.sub = this._service.getHelper(location.pathname, this.properties).subscribe(
|
|
|
|
data => {
|
2017-12-19 13:53:46 +01:00
|
|
|
this.texts =(data && data.content && data.content[this.position] )? data.content[this.position]:[];
|
2018-02-05 14:14:59 +01:00
|
|
|
},
|
|
|
|
err => {
|
|
|
|
console.log(err);
|
2017-12-19 13:53:46 +01: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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|