monitor-dashboard/src/app/topic/indicators.component.ts

115 lines
3.4 KiB
TypeScript

import {Component, Input, OnChanges, OnInit, SimpleChanges} from "@angular/core";
import {SideBarService} from "../library/sharedComponents/sidebar/sideBar.service";
import {Indicator, Stakeholder} from "../utils/entities/stakeholder";
import {IndicatorUtils} from "../utils/Tools";
@Component({
selector: 'indicators',
templateUrl: './indicators.component.html'
})
export class IndicatorsComponent implements OnInit, OnChanges {
@Input()
public topicIndex: number = 0;
@Input()
public categoryIndex: number = 0;
@Input()
public subcategoryIndex: number = 0;
@Input()
public stakeholder: Stakeholder = null;
public indicatorUtils: IndicatorUtils = new IndicatorUtils();
public charts: Indicator[] = [];
public numbers: Indicator[] = [];
public displayCharts: Indicator[] = [];
public displayNumbers: Indicator[] = [];
public chartType: string = 'all';
public isPublic: string = 'all';
public isActive: string = 'all';
public keyword: string = null;
public grid: boolean = true;
constructor(private sideBarService: SideBarService) {}
ngOnInit(): void {
}
ngOnChanges(changes: SimpleChanges): void {
if(this.stakeholder) {
this.charts = this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].
subCategories[this.subcategoryIndex].charts;
this.displayCharts = this.charts;
this.numbers = this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].
subCategories[this.subcategoryIndex].numbers;
this.displayNumbers = this.numbers;
}
}
onChartTypeChange(value) {
this.displayCharts = this.filterChartType(this.charts, value);
}
onPrivacyChange(value) {
this.displayCharts = this.filterPrivacy(this.charts, value);
this.displayNumbers = this.filterPrivacy(this.numbers, value);
}
onStatusChange(value) {
this.displayCharts = this.filterStatus(this.charts, value);
this.displayNumbers = this.filterStatus(this.numbers, value);
}
onKeywordChange(value) {
this.displayCharts = this.filterByKeyword(this.charts, value);
this.displayNumbers = this.filterByKeyword(this.numbers, value);
}
filterChartType(indicators: Indicator[], value): Indicator[] {
if (value === 'all') {
return indicators;
} else {
return indicators.filter(indicator =>
indicator.indicatorPaths.filter(indicatorPath => indicatorPath.type === value).length > 0);
}
}
filterPrivacy(indicators: Indicator[], value): Indicator[] {
if (value === 'all') {
return indicators;
} else {
return indicators.filter(indicator => indicator.isPublic === (value === 'public'));
}
}
filterStatus(indicators: Indicator[], value): Indicator[] {
if (value === 'all') {
return indicators;
} else {
return indicators.filter(indicator => indicator.isActive === (value === 'active'));
}
}
filterByKeyword(indicators: Indicator[], value): Indicator[] {
if (value === null || value === '') {
return indicators;
} else {
return indicators.filter(indicator => indicator.name.includes(value) || indicator.description.includes(value));
}
}
get open(): boolean {
return this.sideBarService.open;
}
public toggleOpen(event = null) {
if (!event) {
this.sideBarService.setOpen(!this.open);
} else if (event && event['value'] === true) {
this.sideBarService.setOpen(false);
}
}
public changeGrid(value) {
this.grid = value;
}
}