Add a message count component

The logic to say ‘1 email sent’ vs ‘12 text messages sent’ is repeated
all over the place. So this commit adds a component to put it in one
place.
This commit is contained in:
Chris Hill-Scott
2016-05-13 09:58:07 +01:00
parent 3dc349c8a7
commit 8a4b0ba88c
4 changed files with 24 additions and 9 deletions

View File

@@ -0,0 +1,15 @@
{% macro message_count_label(count, template_type) -%}
{%- if template_type == 'sms' -%}
{%- if count == 1 -%}
text message
{%- else -%}
text messages
{%- endif -%}
{%- elif template_type == 'email' -%}
{%- if count == 1 -%}
email
{%- else -%}
emails
{%- endif -%}
{%- endif %} sent
{%- endmacro %}

View File

@@ -1,4 +1,4 @@
{% from "components/table.html" import list_table, field, hidden_field_heading, right_aligned_field_heading %}
{% from "components/message-count-label.html" import message_count_label %}
<dl>
{% for item in template_statistics %}
@@ -13,8 +13,7 @@
<dd class="column-half">
<span class="spark-bar">
<span style="width: {{ item.usage_count / most_used_template_count * 100 }}%"></span>
{{ item.usage_count }} {{ 'text messages' if item.template.template_type == 'sms' else 'emails' }} sent
{{ item.usage_count }} {{ message_count_label(item.usage_count, item.template.template_type) }}
</span>
</dd>

View File

@@ -1,5 +1,6 @@
{% from "components/big-number.html" import big_number, big_number_with_status %}
{% from "components/show-more.html" import show_more %}
{% from "components/message-count-label.html" import message_count_label %}
<div
data-module="update-content"
@@ -12,7 +13,7 @@
<div class="column-half">
{{ big_number_with_status(
statistics.emails_requested,
'email sent' if statistics.emails_requested == 1 else 'emails sent',
message_count_label(statistics.emails_requested, 'email'),
statistics.emails_failed,
statistics.get('emails_failure_rate', 0.0),
statistics.get('emails_failure_rate', 0)|float > 3,
@@ -23,7 +24,7 @@
<div class="column-half">
{{ big_number_with_status(
statistics.sms_requested,
'text message sent' if statistics.sms_requested == 1 else 'text messages sent',
message_count_label(statistics.sms_requested, 'sms'),
statistics.sms_failed,
statistics.get('sms_failure_rate', 0.0),
statistics.get('sms_failure_rate', 0)|float > 3,

View File

@@ -92,10 +92,10 @@ def test_should_show_recent_templates_on_dashboard(app_,
assert len(table_rows) == 2
assert page.find_all('dt')[0].text.strip() == 'Pickle feet'
assert page.find_all('dd')[0].text.strip() == '206 messages sent'
assert page.find_all('dd')[0].text.strip() == '206 text messages sent'
assert page.find_all('dt')[1].text.strip() == 'Brine Shrimp'
assert page.find_all('dd')[1].text.strip() == '13 messages sent'
assert page.find_all('dd')[1].text.strip() == '13 text messages sent'
def test_should_show_all_templates_on_template_statistics_page(
@@ -130,10 +130,10 @@ def test_should_show_all_templates_on_template_statistics_page(
assert len(table_rows) == 2
assert page.find_all('dt')[0].text.strip() == 'Pickle feet'
assert page.find_all('dd')[0].text.strip() == '206 messages sent'
assert page.find_all('dd')[0].text.strip() == '206 text messages sent'
assert page.find_all('dt')[1].text.strip() == 'Brine Shrimp'
assert page.find_all('dd')[1].text.strip() == '13 messages sent'
assert page.find_all('dd')[1].text.strip() == '13 text messages sent'
def _test_dashboard_menu(mocker, app_, usr, service, permissions):