openaire-library/monitor/indicators/indicators.component.ts

77 lines
2.8 KiB
TypeScript

import {Component, OnDestroy, OnInit} from "@angular/core";
import {Subscriber} from "rxjs";
import {properties} from "../../../../environments/environment";
import {ActivatedRoute, Router} from "@angular/router";
import {HelperService} from "../../utils/helper/helper.service";
import {Meta, Title} from "@angular/platform-browser";
import {SEOService} from "../../sharedComponents/SEO/SEO.service";
import {ResourcesService} from "../services/resources.service";
@Component({
selector: 'indicators-page',
template: `<helper *ngIf="pageContents && pageContents['top'] && pageContents['top'].length > 0" [texts]="pageContents['top']"></helper>`
})
export class IndicatorsComponent implements OnInit, OnDestroy {
private subscriptions: any[] = [];
public types = ResourcesService.types;
public properties = properties;
public pageContents;
constructor(private helper: HelperService,
private resourcesService: ResourcesService,
private router: Router,
private meta: Meta,
private title: Title,
private seoService: SEOService,
private route: ActivatedRoute) {
}
ngOnInit() {
this.subscriptions.push(this.route.params.subscribe(params => {
if(params['type']){
let type = this.types.find(type => type.value === params['type']);
if(type) {
this.getPageContents(type.value);
const description = "Monitor | Indicators " + type.label;
const title = "Monitor | Indicators " + type.label;
this.metaTags(title, description);
}
}
}))
}
metaTags(title, description) {
const url = properties.domain + properties.baseLink + this.router.url;
this.seoService.createLinkForCanonicalURL(url, false);
this.meta.updateTag({content: url}, "property='og:url'");
this.meta.updateTag({content: description}, "name='description'");
this.meta.updateTag({content: description}, "property='og:description'");
this.meta.updateTag({content: title}, "property='og:title'");
this.title.setTitle(title);
}
ngOnDestroy() {
this.subscriptions.forEach(subscription => {
if (subscription instanceof Subscriber) {
subscription.unsubscribe();
}
});
}
public getPageContents(type: string) {
this.subscriptions.push(this.resourcesService.isPagesEnabled().subscribe(status => {
if(status[0]) {
this.subscriptions.push(this.helper.getPageHelpContents(this.properties, 'monitor', '/indicators/' + type, 'monitor').subscribe(contents => {
this.pageContents = contents;
}));
} else {
this.navigateToError();
}
}));
}
private navigateToError() {
this.router.navigate([this.properties.errorLink], {queryParams: {'page': this.properties.baseLink + this.router.url}});
}
}