diff --git a/monitor/entities/stakeholder.ts b/monitor/entities/stakeholder.ts index 9970b6b3..c1abb28b 100644 --- a/monitor/entities/stakeholder.ts +++ b/monitor/entities/stakeholder.ts @@ -12,6 +12,7 @@ export type IndicatorType = 'number' | 'chart'; export type IndicatorSize = 'small' | 'medium' | 'large'; export type IndicatorPathType = 'table' | 'bar' | 'column' | 'pie' | 'line' | 'other'; export type SourceType = 'statistics' | 'search' |'stats-tool' | 'old' | 'image'; +export type Format = 'NUMBER' | 'PERCENTAGE'; export type Visibility = 'PUBLIC' | 'PRIVATE' | 'RESTRICTED'; export class Stakeholder { @@ -193,8 +194,9 @@ export class IndicatorPath { parameters: any; filters: any; filtersApplied: number = 0; + format: Format; - constructor(type: IndicatorPathType, source: SourceType, url: string, chartObject: string, jsonPath: string[]) { + constructor(type: IndicatorPathType, source: SourceType, url: string, chartObject: string, jsonPath: string[], format: Format = 'NUMBER') { this.type = type; this.url = url; this.source = source; @@ -203,6 +205,7 @@ export class IndicatorPath { this.parameters = {}; this.filters = {}; this.filtersApplied = 0; + this.format = format; } static createParameters(funderName: string = null, title: string = null, chartType: string = null): any { diff --git a/utils/pipes/number-percentage.pipe.ts b/utils/pipes/number-percentage.pipe.ts new file mode 100644 index 00000000..4480d12c --- /dev/null +++ b/utils/pipes/number-percentage.pipe.ts @@ -0,0 +1,18 @@ +import {Pipe, PipeTransform} from "@angular/core"; +import {Level, NumberSize, NumberUtils} from "../number-utils.class"; +import {DecimalPipe} from "@angular/common"; + +@Pipe({name: 'numberPercentage'}) +export class NumberPercentagePipe implements PipeTransform { + decimalPipe: DecimalPipe = new DecimalPipe("en"); + + constructor() { + } + + /** + * */ + transform(value: number | string, ...args: any[]): any { + value = Number.parseFloat(value.toString()) * 100; + return this.decimalPipe.transform(value) + '%'; + } +} diff --git a/utils/pipes/number-round.module.ts b/utils/pipes/number-round.module.ts index 951da877..dfa54a0d 100644 --- a/utils/pipes/number-round.module.ts +++ b/utils/pipes/number-round.module.ts @@ -1,9 +1,10 @@ import {NgModule} from "@angular/core"; import {NumberRoundPipe} from "./number-round.pipe"; +import {NumberPercentagePipe} from "./number-percentage.pipe"; @NgModule({ - declarations: [NumberRoundPipe], - exports: [NumberRoundPipe] + declarations: [NumberRoundPipe, NumberPercentagePipe], + exports: [NumberRoundPipe, NumberPercentagePipe] }) export class NumberRoundModule {