connect/src/app/htmlPages/htmlPage.component.ts

60 lines
1.9 KiB
TypeScript
Raw Normal View History

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'];
if(!this.communityId && typeof document !== 'undefined'){
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();
}
}
}