1
|
import { Component, Input } from '@angular/core';
|
2
|
import 'rxjs/Rx';
|
3
|
import {HelperService} from './helper.service';
|
4
|
import {OpenaireProperties} from '../properties/openaireProperties';
|
5
|
|
6
|
@Component({
|
7
|
selector: 'helper',
|
8
|
template: `
|
9
|
<div *ngIf=" texts && texts.length > 0" [ngClass]=styleName>
|
10
|
<div *ngFor="let text of texts " [innerHTML]="text.content">
|
11
|
</div>
|
12
|
</div>
|
13
|
`
|
14
|
})
|
15
|
export class HelperComponent {
|
16
|
texts=[];
|
17
|
@Input() style:boolean = false;
|
18
|
@Input() position:string = 'right';
|
19
|
@Input() styleName:string = '';
|
20
|
sub:any;
|
21
|
|
22
|
constructor (
|
23
|
private _service: HelperService
|
24
|
) {
|
25
|
}
|
26
|
|
27
|
ngOnInit() {
|
28
|
if(OpenaireProperties.isHelperEnabled() && location){
|
29
|
this.sub = this._service.getHelper(location.pathname).subscribe(
|
30
|
data => {
|
31
|
this.texts =(data && data.content && data.content[this.position] )? data.content[this.position]:[];
|
32
|
},
|
33
|
err => {
|
34
|
console.log(err);
|
35
|
|
36
|
}
|
37
|
);
|
38
|
}
|
39
|
}
|
40
|
ngOnDestroy() {
|
41
|
if(this.sub){
|
42
|
this.sub.unsubscribe();
|
43
|
}
|
44
|
}
|
45
|
|
46
|
|
47
|
}
|