2018-06-08 13:25:35 +02:00
|
|
|
import { Component, Input } from '@angular/core';
|
|
|
|
import {ActivatedRoute} from '@angular/router';
|
|
|
|
import 'rxjs/Rx';
|
|
|
|
import {HtmlPageService} from './htmlPage.service';
|
|
|
|
import{EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
|
|
|
|
import {ConnectHelper} from '../openaireLibrary/connect/connectHelper';
|
|
|
|
import {SafeHtmlPipe} from '../openaireLibrary/utils/pipes/safeHTML.pipe';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'html-page',
|
|
|
|
template: `
|
|
|
|
<div [innerHTML]="content | safeHtml"></div>
|
|
|
|
`
|
|
|
|
})
|
|
|
|
export class HtmlPageComponent {
|
|
|
|
public content:string="";
|
|
|
|
sub:any;
|
|
|
|
properties:EnvProperties;
|
|
|
|
private communityId: string = null;
|
|
|
|
constructor (private _service: HtmlPageService, private route: ActivatedRoute,) {}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.route.data
|
|
|
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
|
|
|
this.properties = data.envSpecific;
|
|
|
|
this.route.queryParams.subscribe(
|
|
|
|
params => {
|
|
|
|
this.communityId = params['communityId'];
|
2019-02-18 16:15:53 +01:00
|
|
|
if(!this.communityId && typeof document !== 'undefined'){
|
2018-06-08 13:25:35 +02:00
|
|
|
this.communityId = ConnectHelper.getCommunityFromDomain(document.location.hostname);
|
|
|
|
}
|
|
|
|
if(!this.communityId){
|
|
|
|
this.communityId = this.properties.adminToolsCommunity;
|
|
|
|
}
|
|
|
|
if(location){
|
|
|
|
this.sub = this._service.getHtmlContent(location.pathname, this.properties, this.communityId).subscribe(
|
|
|
|
data => {
|
|
|
|
if(data.length > 0) {
|
|
|
|
this.content = data[0].content;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
console.log(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
if(this.sub){
|
|
|
|
this.sub.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|