Add number percentage pipe. Add format field in indicatorPath

This commit is contained in:
Konstantinos Triantafyllou 2023-04-18 15:26:41 +03:00
parent e88bb206dc
commit a49970aca6
3 changed files with 25 additions and 3 deletions

View File

@ -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 {

View File

@ -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) + '<span class="number-size">%</span>';
}
}

View File

@ -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 {