From: Galen Charlton Date: Tue, 1 Jun 2021 22:23:36 +0000 (-0400) Subject: LP#1904244: format: switch from CurrencyPipe to DecimalPipe X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=449e7994c43e7363c2cbe5dcc8f90a1b2caf62a3;p=evergreen%2Fmasslnc.git LP#1904244: format: switch from CurrencyPipe to DecimalPipe CurrencyPipe has no easy way of displaying the monetary amount without a currency symbol, which means that currency amounts display with a dollar sign -- which isn't a univeral assumption for Evergreen. Future work is indicated to (a) teach Evergreen a global flag or a library setting for the system's base currency and (b) let the format service be passed a currency code. Once both are in place, CurrencyPipe can be restored. Signed-off-by: Galen Charlton Signed-off-by: Ruth Frasur Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/eg2/src/app/core/core.module.ts b/Open-ILS/src/eg2/src/app/core/core.module.ts index 82052f591d..40cfe29dc4 100644 --- a/Open-ILS/src/eg2/src/app/core/core.module.ts +++ b/Open-ILS/src/eg2/src/app/core/core.module.ts @@ -5,7 +5,7 @@ * and do not require entry in our 'providers' array. */ import {NgModule} from '@angular/core'; -import {CommonModule, DatePipe, CurrencyPipe} from '@angular/common'; +import {CommonModule, DatePipe, DecimalPipe} from '@angular/common'; import {FormatService, FormatValuePipe} from './format.service'; @NgModule({ @@ -21,7 +21,7 @@ import {FormatService, FormatValuePipe} from './format.service'; ], providers: [ DatePipe, - CurrencyPipe + DecimalPipe ] }) diff --git a/Open-ILS/src/eg2/src/app/core/format.service.ts b/Open-ILS/src/eg2/src/app/core/format.service.ts index 3cd755ded1..9622bd0681 100644 --- a/Open-ILS/src/eg2/src/app/core/format.service.ts +++ b/Open-ILS/src/eg2/src/app/core/format.service.ts @@ -1,5 +1,5 @@ import {Injectable, Pipe, PipeTransform} from '@angular/core'; -import {DatePipe, CurrencyPipe, getLocaleDateFormat, getLocaleTimeFormat, getLocaleDateTimeFormat, FormatWidth} from '@angular/common'; +import {DatePipe, DecimalPipe, getLocaleDateFormat, getLocaleTimeFormat, getLocaleDateTimeFormat, FormatWidth} from '@angular/common'; import {IdlService, IdlObject} from '@eg/core/idl.service'; import {OrgService} from '@eg/core/org.service'; import {LocaleService} from '@eg/core/locale.service'; @@ -30,7 +30,7 @@ export class FormatService { constructor( private datePipe: DatePipe, - private currencyPipe: CurrencyPipe, + private decimalPipe: DecimalPipe, private idl: IdlService, private org: OrgService, private locale: LocaleService @@ -133,7 +133,12 @@ export class FormatService { return this.datePipe.transform(date.toISOString(true), fmt, date.format('ZZ')); case 'money': - return this.currencyPipe.transform(value); + // TODO: this used to use CurrencyPipe, but that injected + // an assumption that the default currency is always going to be + // USD. Since CurrencyPipe doesn't have an apparent way to specify + // that that currency symbol shouldn't be displayed at all, it + // was switched to DecimalPipe + return this.decimalPipe.transform(value, '1.2-2'); case 'bool': // Slightly better than a bare 't' or 'f'. diff --git a/Open-ILS/src/eg2/src/app/core/format.spec.ts b/Open-ILS/src/eg2/src/app/core/format.spec.ts index d0d3bfd196..6ff53467f7 100644 --- a/Open-ILS/src/eg2/src/app/core/format.spec.ts +++ b/Open-ILS/src/eg2/src/app/core/format.spec.ts @@ -1,4 +1,4 @@ -import {DatePipe, CurrencyPipe, registerLocaleData} from '@angular/common'; +import {DatePipe, DecimalPipe, registerLocaleData} from '@angular/common'; import {IdlService} from './idl.service'; import {EventService} from './event.service'; import {DbStoreService} from './db-store.service'; @@ -18,7 +18,7 @@ import localeFrCA from '@angular/common/locales/fr-CA'; describe('FormatService', () => { - let currencyPipe: CurrencyPipe; + let decimalPipe: DecimalPipe; let datePipe: DatePipe; let idlService: IdlService; let netService: NetService; @@ -35,7 +35,7 @@ describe('FormatService', () => { let service: FormatService; beforeEach(() => { - currencyPipe = new CurrencyPipe('en'); + decimalPipe = new DecimalPipe('en'); datePipe = new DatePipe('en'); idlService = new IdlService(); evtService = new EventService(); @@ -99,7 +99,7 @@ describe('FormatService', () => { value: '12.1', datatype: 'money' }); - expect(str).toBe('$12.10'); + expect(str).toBe('12.10'); }); it('should transform M/d/yy, h:mm a Angular format string to a valid MomentJS one', () => {