From 0c19f3b88d13a797cd20724ffaa24b1a7413ed20 Mon Sep 17 00:00:00 2001 From: Adriaan Date: Sun, 29 Mar 2020 21:37:34 +0200 Subject: [PATCH] Fix number formating and move function to server.ts (#479) * Fix number formating and move function to server.ts * Remove thousandSeparator --- app/server.ts | 7 ++++++- app/views/pages/report.ejs | 16 ++++++---------- app/views/pages/statistics.ejs | 17 ++++++++--------- app/views/pages/thank-you.ejs | 4 +--- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/app/server.ts b/app/server.ts index b2c0826a..9524e864 100644 --- a/app/server.ts +++ b/app/server.ts @@ -74,7 +74,12 @@ app.use((req, res, next) => { res.locals.zipPattern = config.ZIP_PATTERN; res.locals.zipPlaceHolder = config.ZIP_PLACEHOLDER; res.locals.redirectToGovernment = config.REDIRECT_TO_GOVERNMENT; - res.locals.thousandSeparator = config.THOUSAND_SEPARATOR; + + // eslint-disable-next-line @typescript-eslint/ban-ts-ignore + // @ts-ignore + res.locals.formatNumber = x => + x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, config.THOUSAND_SEPARATOR); + next(); }); diff --git a/app/views/pages/report.ejs b/app/views/pages/report.ejs index 03002d76..ccdb80b4 100644 --- a/app/views/pages/report.ejs +++ b/app/views/pages/report.ejs @@ -3,7 +3,7 @@ profile, passcode, baseUrl, - thousandSeparator = ' ', + formatNumber, urls } = locals; const age = profile && locals.profile.age; @@ -31,10 +31,6 @@ const symptomSlimeCough = symptoms && symptoms['SLIME_COUGH']; const symptomRunnyNose = symptoms && symptoms['RUNNY_NOSE']; const symptomNauseaOrVomiting = symptoms && symptoms['NAUSEA_OR_VOMITING']; - - function numberWithSpaces(x) { - return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, thousandSeparator); - } %> <%- include('partials/header', { home: true, menu: false }) -%> @@ -82,25 +78,25 @@ <%- include('partials/app-stats-block', { image: '/static/images/napkin.svg', title: __('Total reports'), - number: numberWithSpaces(aggregated.numberOfReports) + number: formatNumber(aggregated.numberOfReports) }) -%> <%- include('partials/app-stats-block', { image: '/static/images/temperature-check.svg', title: __('Infected / Have been tested'), - number: `${numberWithSpaces(aggregated.numberOfConfirmedInfected)}/${numberWithSpaces(aggregated.numberOfTested)}` + number: `${formatNumber(aggregated.numberOfConfirmedInfected)}/${formatNumber(aggregated.numberOfTested)}` }) -%> <%- include('partials/app-stats-block', { image: '/static/images/transfer.svg', title: __(`In close contact with someone who's infected`), - number: numberWithSpaces(aggregated.numberOfContacts) + number: formatNumber(aggregated.numberOfContacts) }) -%> <%- include('partials/app-stats-block', { image: '/static/images/symptoms.svg', title: __('Has symptoms'), - number: numberWithSpaces(aggregated.numberOfPeopleShowingSymptoms) + number: formatNumber(aggregated.numberOfPeopleShowingSymptoms) }) -%> @@ -448,7 +444,7 @@

<%= __(`Contribute and share {{ hostname }} on`, { hostname: baseUrl }) %>

- <%- include('partials/share', { amount: numberWithSpaces(aggregated.numberOfReports) }) -%> + <%- include('partials/share', { amount: formatNumber(aggregated.numberOfReports) }) -%>
diff --git a/app/views/pages/statistics.ejs b/app/views/pages/statistics.ejs index 55beadcc..cb385afa 100644 --- a/app/views/pages/statistics.ejs +++ b/app/views/pages/statistics.ejs @@ -2,8 +2,7 @@ locals.inContactWithInfectedStats.total; const totalInfectedPeopleWithSymptoms = locals.infectedStats.symptomStats.total; const totalPeopleWithSymptoms = locals.allSymptomsStats.symptomStats.total; const totalTested = -locals.totalTested; function numberWithSpaces(x) { return -x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " "); } %> +locals.totalTested; const { formatNumber } = locals; %> @@ -30,8 +29,8 @@ x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " "); } %> <%= __(`COVID-19 infected`) %>

- <%= __(`In total`) %> <%= numberWithSpaces(totalInfectedPeopleWithSymptoms) %> - <%= __(`people have reported that they have tested positive for COVID-19 and + <%= __(`In total`) %> <%= formatNumber(totalInfectedPeopleWithSymptoms) %> <%= + __(`people have reported that they have tested positive for COVID-19 and experience symptoms.`) %>

@@ -43,8 +42,8 @@ x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " "); } %>

<%= __(`Test results`) %>

- <%= __(`In total`) %> <%= numberWithSpaces(totalTested) %> <%= __(`people - have reported that they have been tested for COVID-19.`) %> + <%= __(`In total`) %> <%= formatNumber(totalTested) %> <%= __(`people have + reported that they have been tested for COVID-19.`) %>

@@ -54,8 +53,8 @@ x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " "); } %> <%= __(`Close contacts`) %>

- <%= __(`In total`) %> <%= numberWithSpaces(totalPeopleInContactWithInfected) - %> <%= __(`people have reported that they have been in close contact with a + <%= __(`In total`) %> <%= formatNumber(totalPeopleInContactWithInfected) %> + <%= __(`people have reported that they have been in close contact with a person who was tested positive for COVID-19.`) %>

@@ -102,7 +101,7 @@ x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " "); } %> <%= __(`All submissions`) %>

- <%= __("In total") %> <%= numberWithSpaces(totalPeopleWithSymptoms) %> <%= + <%= __("In total") %> <%= formatNumber(totalPeopleWithSymptoms) %> <%= __(`people have reported that they experience symptoms.`) %>

diff --git a/app/views/pages/thank-you.ejs b/app/views/pages/thank-you.ejs index ed9985b2..3ed03e17 100644 --- a/app/views/pages/thank-you.ejs +++ b/app/views/pages/thank-you.ejs @@ -1,6 +1,4 @@ -<% const numberWithSpaces = x => x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, -locals.thousandSeparator || ' '); const amount = -numberWithSpaces(aggregated.numberOfReports) %> +<% const amount = locals.formatNumber(aggregated.numberOfReports) %> <%- include('partials/header') -%>