diff --git a/src/controllers/budgets.controller.ts b/src/controllers/budgets.controller.ts index e1c0d69..0752edb 100644 --- a/src/controllers/budgets.controller.ts +++ b/src/controllers/budgets.controller.ts @@ -11,6 +11,7 @@ import BudgetsTableFieldsMapping from '../config/mapping/budgets/table.json'; import BudgetsTreemapFieldsMapping from '../config/mapping/budgets/treemap.json'; import urls from '../config/urls/index.json'; import {BudgetSankeyChartData} from '../interfaces/budgetSankey'; +import CycleMapping from '../static-assets/cycle-mapping.json'; import {handleDataApiError} from '../utils/dataApiError'; import {filterFinancialIndicators} from '../utils/filtering/financialIndicators'; @@ -483,7 +484,7 @@ export class BudgetsController { item => _.get(item, BudgetsCyclesMapping.cycleFrom, null) !== null, ), - (item, index) => { + item => { const from = _.get(item, BudgetsCyclesMapping.cycleFrom, ''); const to = _.get(item, BudgetsCyclesMapping.cycleTo, ''); @@ -493,9 +494,11 @@ export class BudgetsController { value = `${from} - ${to}`; } + const name = _.find(CycleMapping, {value})?.name ?? value; + return { - name: `Cycle ${index + 1}`, - value, + name, + value: name, }; }, ), @@ -530,13 +533,14 @@ export class BudgetsController { 'implementationPeriod/grant/geography_BoardConstituencyView/code', ]; } - const years = cycle.split('-'); + // const years = cycle.split('-'); const filterString1 = filterFinancialIndicators( { ...this.req.query, - years: years[0], - yearsTo: years[1], + cycleNames: cycle, + // years: years[0], + // yearsTo: years[1], }, BudgetsBreakdownFieldsMapping.urlParams1.replace( '', @@ -562,8 +566,9 @@ export class BudgetsController { filterString2 = filterFinancialIndicators( { ...this.req.query, - years: years[0], - yearsTo: years[1], + cycleNames: cycle, + // years: years[0], + // yearsTo: years[1], }, BudgetsBreakdownFieldsMapping.urlParams2.replace( '', @@ -1324,9 +1329,11 @@ export class BudgetsController { value = `${from} - ${to}`; } + const name = _.find(CycleMapping, {value})?.name ?? value; + return { - name: `Cycle ${index + 1}`, - value, + name, + value: name, }; }, ), diff --git a/src/controllers/disbursements.controller.ts b/src/controllers/disbursements.controller.ts index 2adb815..8a1164e 100644 --- a/src/controllers/disbursements.controller.ts +++ b/src/controllers/disbursements.controller.ts @@ -8,6 +8,7 @@ import LineChartFieldsMapping from '../config/mapping/disbursements/lineChart.js import TableFieldsMapping from '../config/mapping/disbursements/table.json'; import FinancialInsightsStatsMapping from '../config/mapping/financialInsightsStats.json'; import urls from '../config/urls/index.json'; +import CycleMapping from '../static-assets/cycle-mapping.json'; import {handleDataApiError} from '../utils/dataApiError'; import {filterFinancialIndicators} from '../utils/filtering/financialIndicators'; @@ -566,7 +567,7 @@ export class DisbursementsController { item => _.get(item, DisbursementsCyclesMapping.cycleFrom, null) !== null, ), - (item, index) => { + item => { const from = _.get(item, DisbursementsCyclesMapping.cycleFrom, ''); const to = _.get(item, DisbursementsCyclesMapping.cycleTo, ''); @@ -576,9 +577,11 @@ export class DisbursementsController { value = `${from} - ${to}`; } + const name = _.find(CycleMapping, {value})?.name ?? value; + return { - name: `Cycle ${index + 1}`, - value, + name, + value: name, }; }, ); diff --git a/src/controllers/expenditures.controller.ts b/src/controllers/expenditures.controller.ts index a3026d2..ebe0d80 100644 --- a/src/controllers/expenditures.controller.ts +++ b/src/controllers/expenditures.controller.ts @@ -8,6 +8,7 @@ import ExpendituresCyclesMapping from '../config/mapping/expenditures/cycles.jso import ExpendituresHeatmapMapping from '../config/mapping/expenditures/heatmap.json'; import ExpendituresTableMapping from '../config/mapping/expenditures/table.json'; import urls from '../config/urls/index.json'; +import CycleMapping from '../static-assets/cycle-mapping.json'; import {handleDataApiError} from '../utils/dataApiError'; import {filterFinancialIndicators} from '../utils/filtering/financialIndicators'; @@ -472,9 +473,11 @@ export class ExpendituresController { value = `${from} - ${to}`; } + const name = _.find(CycleMapping, {value})?.name ?? value; + return { - name: `Cycle ${index + 1}`, - value, + name, + value: name, }; }); diff --git a/src/static-assets/cycle-mapping.json b/src/static-assets/cycle-mapping.json new file mode 100644 index 0000000..81a32ed --- /dev/null +++ b/src/static-assets/cycle-mapping.json @@ -0,0 +1,22 @@ +[ + { + "name": "Previous Cycles", + "value": "2002 - 2013" + }, + { + "name": "Grant Cycle 4", + "value": "2014 - 2016" + }, + { + "name": "Grant Cycle 5", + "value": "2017 - 2019" + }, + { + "name": "Grant Cycle 6", + "value": "2020 - 2022" + }, + { + "name": "Grant Cycle 7", + "value": "2023 - 2025" + } +] diff --git a/src/utils/filtering/financialIndicators.ts b/src/utils/filtering/financialIndicators.ts index 11c8e96..d618283 100644 --- a/src/utils/filtering/financialIndicators.ts +++ b/src/utils/filtering/financialIndicators.ts @@ -1,5 +1,6 @@ import _ from 'lodash'; import filtering from '../../config/filtering/index.json'; +import CycleMapping from '../../static-assets/cycle-mapping.json'; import {getGeographyValues} from './geographies'; const MAPPING = { @@ -39,6 +40,24 @@ export function filterFinancialIndicators( ): string { let str = ''; + if (_.get(params, 'cycleNames', '')) { + const cycles = _.get(params, 'cycleNames', '').split(','); + const cycleValues = _.filter( + cycles.map( + (cycle: string) => _.find(CycleMapping, {name: cycle})?.value ?? '', + ), + (c: string) => c.length > 0, + ); + cycleValues.forEach((cycle: string) => { + const splits = cycle.split(' - '); + params = { + ...params, + years: splits[0], + yearsTo: splits[1], + }; + }); + } + const geos = _.filter( _.get(params, 'geographies', '').split(','), (o: string) => o.length > 0,