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: `
` }) 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 = ConnectHelper.getCommunityFromDomain(this.properties.domain); if(!this.communityId) { this.communityId = params['communityId']; } 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); this.handleError("Error getting html content with route: "+location.pathname+" for community with id: "+this.communityId, err); } ); } }); }); } ngOnDestroy() { if(this.sub){ this.sub.unsubscribe(); } } private handleError(message: string, error) { console.error("Html Page: "+message, error); } }