61 lines
2.2 KiB
TypeScript
61 lines
2.2 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 {StakeholderService} from "../services/stakeholder.service";
|
|
import {ConfigurationService} from "../../utils/configuration/configuration.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 properties = properties;
|
|
public pageContents;
|
|
|
|
constructor(private helper: HelperService,
|
|
private configurationService: ConfigurationService,
|
|
private router: Router,
|
|
private stakeholderService: StakeholderService,
|
|
private route: ActivatedRoute) {
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.subscriptions.push(this.route.params.subscribe(params => {
|
|
if(params['stakeholder']) {
|
|
this.subscriptions.push(this.stakeholderService.getStakeholderAsObservable().subscribe(stakeholder => {
|
|
this.getPageContents(stakeholder.type);
|
|
}));
|
|
} else if(params['type']){
|
|
this.getPageContents(params['type']);
|
|
}
|
|
}))
|
|
}
|
|
|
|
ngOnDestroy() {
|
|
this.subscriptions.forEach(subscription => {
|
|
if (subscription instanceof Subscriber) {
|
|
subscription.unsubscribe();
|
|
}
|
|
});
|
|
}
|
|
|
|
public getPageContents(type: string) {
|
|
this.subscriptions.push(this.configurationService.isPageEnabled('monitor', '/indicators/' + type, 'monitor').subscribe(isEnabled => {
|
|
if(isEnabled) {
|
|
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}});
|
|
}
|
|
}
|