From 3bda3b2ef9b354104c43f5a983ebdec987aa4249 Mon Sep 17 00:00:00 2001 From: Alexandr Kostenko Date: Thu, 8 Dec 2022 17:13:06 +0200 Subject: [PATCH 1/6] remove filters number --- src/i18n/index.js | 12 ---- src/i18n/resources/en.json | 18 ------ src/main.js | 2 - src/vue/composables/index.js | 1 + src/vue/composables/useNumber.js | 25 ++++++++ src/vue/filters/formatNumber.js | 5 -- src/vue/pages/Limits/Limits.TableRenderer.vue | 57 ++++++++++--------- src/vue/pages/polls-all/PollAttributes.vue | 51 +++++++++-------- yarn.lock | 2 +- 9 files changed, 85 insertions(+), 88 deletions(-) create mode 100644 src/vue/composables/index.js create mode 100644 src/vue/composables/useNumber.js delete mode 100644 src/vue/filters/formatNumber.js diff --git a/src/i18n/index.js b/src/i18n/index.js index b41265547..6c913177b 100644 --- a/src/i18n/index.js +++ b/src/i18n/index.js @@ -193,18 +193,6 @@ class I18n { return param.currency ? result.concat(' ', param.currency) : result - case 'number': - return MathUtil - .format(param, _get(lngConfig, 'number.formats.default')) - case 'integer': - return MathUtil - .format(param, _get(lngConfig, 'number.formats.integer')) - case 'percent': - const convertedPercent = MathUtil.multiply(param, 100) - return MathUtil.format( - convertedPercent, - _get(lngConfig, 'number.formats.percent') - ) default: console.warn(`Unknown format: ${format}, skipping…`) return param diff --git a/src/i18n/resources/en.json b/src/i18n/resources/en.json index d45d2b260..921443c97 100644 --- a/src/i18n/resources/en.json +++ b/src/i18n/resources/en.json @@ -9,24 +9,6 @@ "groupSize": 3, "decimalPlaces": 6 } - }, - "default": { - "decimalSeparator": ".", - "groupSeparator": ",", - "groupSize": 3, - "decimalPlaces": 6 - }, - "integer": { - "groupSeparator": ",", - "groupSize": 3, - "decimalPlaces": 0 - }, - "percent": { - "decimalSeparator": ".", - "groupSeparator": ",", - "groupSize": 3, - "decimalPlaces": 6, - "suffix": "%" } } }, diff --git a/src/main.js b/src/main.js index c03325c6b..0e368e180 100644 --- a/src/main.js +++ b/src/main.js @@ -19,7 +19,6 @@ import { globalize } from '@/vue/filters/globalize' import { globalizeCountry } from './vue/filters/globalizeCountry' import { formatDate } from '@/vue/filters/formatDate' import { formatMoney } from '@/vue/filters/formatMoney' -import { formatNumber } from '@/vue/filters/formatNumber' import { formatInteger } from '@/vue/filters/formatInteger' import { formatPercent } from '@/vue/filters/formatPercent' import { formatCalendar } from '@/vue/filters/formatCalendar' @@ -59,7 +58,6 @@ async function init () { Vue.filter('formatDateDMY', formatDateDMY) Vue.filter('formatDateDMYT', formatDateDMYT) Vue.filter('formatMoney', formatMoney) - Vue.filter('formatNumber', formatNumber) Vue.filter('formatPercent', formatPercent) Vue.filter('formatInteger', formatInteger) Vue.filter('formatCalendar', formatCalendar) diff --git a/src/vue/composables/index.js b/src/vue/composables/index.js new file mode 100644 index 000000000..ec8ca6f9f --- /dev/null +++ b/src/vue/composables/index.js @@ -0,0 +1 @@ +export * from './useNumber' diff --git a/src/vue/composables/useNumber.js b/src/vue/composables/useNumber.js new file mode 100644 index 000000000..9526f15b6 --- /dev/null +++ b/src/vue/composables/useNumber.js @@ -0,0 +1,25 @@ +import { MathUtil } from '@/js/utils' + +export const useNumber = () => { + const formatNumber = ( + number, + decimalPlaces = 0, + ) => { + const cfg = + ({ + decimalSeparator: '.', + groupSeparator: '', + groupSize: 3, + decimalPlaces, + }) + + return MathUtil.format( + number, + cfg, + ) + } + + return { + formatNumber, + } +} diff --git a/src/vue/filters/formatNumber.js b/src/vue/filters/formatNumber.js deleted file mode 100644 index b6302f42e..000000000 --- a/src/vue/filters/formatNumber.js +++ /dev/null @@ -1,5 +0,0 @@ -import { globalize } from './globalize' - -export function formatNumber (value) { - return globalize('formats.number', { value }) -} diff --git a/src/vue/pages/Limits/Limits.TableRenderer.vue b/src/vue/pages/Limits/Limits.TableRenderer.vue index f67ed9cde..7a2e58553 100644 --- a/src/vue/pages/Limits/Limits.TableRenderer.vue +++ b/src/vue/pages/Limits/Limits.TableRenderer.vue @@ -39,9 +39,9 @@ @@ -53,9 +53,9 @@ @@ -67,9 +67,9 @@ @@ -81,9 +81,9 @@ @@ -115,25 +115,19 @@