2019-11-08 16:47:47 +01:00
|
|
|
import {Component, Input, OnChanges, OnInit, SimpleChanges} from "@angular/core";
|
|
|
|
import {SideBarService} from "../library/sharedComponents/sidebar/sideBar.service";
|
|
|
|
import {Indicator, Stakeholder} from "../utils/entities/stakeholder";
|
2019-11-11 14:28:36 +01:00
|
|
|
import {IndicatorUtils} from "../utils/indicator-utils";
|
2019-11-08 16:47:47 +01:00
|
|
|
|
|
|
|
@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();
|
2019-11-13 11:26:50 +01:00
|
|
|
/**
|
|
|
|
* All charts and numbers
|
|
|
|
*/
|
2019-11-08 16:47:47 +01:00
|
|
|
public charts: Indicator[] = [];
|
|
|
|
public numbers: Indicator[] = [];
|
2019-11-13 11:26:50 +01:00
|
|
|
/**
|
|
|
|
* Displayed chart and numbers base on Top filters
|
|
|
|
*/
|
2019-11-08 16:47:47 +01:00
|
|
|
public displayCharts: Indicator[] = [];
|
|
|
|
public displayNumbers: Indicator[] = [];
|
2019-11-13 11:26:50 +01:00
|
|
|
/**
|
|
|
|
* Top filters
|
|
|
|
*/
|
2019-11-08 16:47:47 +01:00
|
|
|
public chartType: string = 'all';
|
2019-11-13 11:26:50 +01:00
|
|
|
public privacy: string = 'all';
|
|
|
|
public status: string = 'all';
|
2019-11-08 16:47:47 +01:00
|
|
|
public keyword: string = null;
|
2019-11-13 11:26:50 +01:00
|
|
|
/**
|
|
|
|
* Grid or List View
|
|
|
|
*/
|
2019-11-08 16:47:47 +01:00
|
|
|
public grid: boolean = true;
|
|
|
|
|
|
|
|
constructor(private sideBarService: SideBarService) {}
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnChanges(changes: SimpleChanges): void {
|
2019-11-13 11:26:50 +01:00
|
|
|
if(this.canEdit) {
|
2019-11-08 16:47:47 +01:00
|
|
|
this.charts = this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].
|
|
|
|
subCategories[this.subcategoryIndex].charts;
|
2019-11-12 16:55:37 +01:00
|
|
|
this.displayCharts = this.filterChartType(this.filterPrivacy(
|
2019-11-13 11:26:50 +01:00
|
|
|
this.filterStatus(this.filterByKeyword(this.charts, this.keyword), this.status),
|
|
|
|
this.privacy),
|
2019-11-12 16:55:37 +01:00
|
|
|
this.chartType
|
|
|
|
);
|
2019-11-08 16:47:47 +01:00
|
|
|
this.numbers = this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].
|
|
|
|
subCategories[this.subcategoryIndex].numbers;
|
2019-11-12 16:55:37 +01:00
|
|
|
this.displayNumbers = this.filterPrivacy(this.filterStatus(
|
|
|
|
this.filterByKeyword(this.numbers, this.keyword),
|
2019-11-13 11:26:50 +01:00
|
|
|
this.status),
|
|
|
|
this.privacy);
|
2019-11-08 16:47:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-11-13 11:26:50 +01:00
|
|
|
get canEdit() {
|
|
|
|
return this.stakeholder &&
|
|
|
|
this.stakeholder.topics[this.topicIndex] &&
|
|
|
|
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex] &&
|
|
|
|
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex];
|
|
|
|
}
|
|
|
|
|
2019-11-08 16:47:47 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|