Skip to content

Commit

Permalink
Fix number formating and move function to server.ts (BustByte#479)
Browse files Browse the repository at this point in the history
* Fix number formating and move function to server.ts

* Remove thousandSeparator
  • Loading branch information
Adriaan authored Mar 29, 2020
1 parent 843576e commit 0c19f3b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
7 changes: 6 additions & 1 deletion app/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down
16 changes: 6 additions & 10 deletions app/views/pages/report.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
profile,
passcode,
baseUrl,
thousandSeparator = ' ',
formatNumber,
urls
} = locals;
const age = profile && locals.profile.age;
Expand Down Expand Up @@ -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 }) -%>
Expand Down Expand Up @@ -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)
}) -%>
</ul>
</div>
Expand Down Expand Up @@ -448,7 +444,7 @@
<section class="w-full self-center text-center m-8">
<p class="pb-2 text-cvs-red text-lg md:text-xl lg:text-2xl font-bold"><%= __(`Contribute and share {{ hostname }} on`, { hostname: baseUrl }) %></p>
<%- include('partials/share', { amount: numberWithSpaces(aggregated.numberOfReports) }) -%>
<%- include('partials/share', { amount: formatNumber(aggregated.numberOfReports) }) -%>
</section>
<section class="custom-section custom-section-about px-6 lg:px-0 py-12 lg:py-24 bg-white">
Expand Down
17 changes: 8 additions & 9 deletions app/views/pages/statistics.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -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; %>

<!-- prettier spacer -->

Expand All @@ -30,8 +29,8 @@ x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " "); } %>
<%= __(`COVID-19 infected`) %>
</h2>
<p>
<%= __(`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.`) %>
</p>

Expand All @@ -43,8 +42,8 @@ x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " "); } %>
<div>
<h3><%= __(`Test results`) %></h3>
<p>
<%= __(`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.`) %>
</p>
<canvas id="testResultStats"></canvas>
</div>
Expand All @@ -54,8 +53,8 @@ x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " "); } %>
<%= __(`Close contacts`) %>
</h2>
<p>
<%= __(`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.`) %>
</p>

Expand Down Expand Up @@ -102,7 +101,7 @@ x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " "); } %>
<%= __(`All submissions`) %>
</h2>
<p>
<%= __("In total") %> <%= numberWithSpaces(totalPeopleWithSymptoms) %> <%=
<%= __("In total") %> <%= formatNumber(totalPeopleWithSymptoms) %> <%=
__(`people have reported that they experience symptoms.`) %>
</p>

Expand Down
4 changes: 1 addition & 3 deletions app/views/pages/thank-you.ejs
Original file line number Diff line number Diff line change
@@ -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') -%>

Expand Down

0 comments on commit 0c19f3b

Please sign in to comment.