Files
notifications-admin/app/templates/components/message-count-label.html
Chris Hill-Scott 82d8207612 Refactor template list logic into one place
The Jinja template for the ‘choose templates’ page is now pulling in
data from a lot of diparate places in order to work out what to show. As
we add more logic about what to show (in order to make the live search
work) it’s going to get harder to have all this logic in the Jinja
template.

This commit refactors it back into Python where we have more language
features for managing complex logic.

It’s a bit weird to call this file a model, in that it’s dealing with
some presentational logic, rather than just data. Conceptually it’s more
like a view model[1].

1. https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93viewmodel
2018-11-23 14:00:40 +00:00

58 lines
1.3 KiB
HTML

{% macro message_count_label(count, template_type, suffix='sent') -%}
{% if template_type == None %}
{%- if count == 1 -%}
message
{%- else -%}
messages
{%- endif -%}
{% endif %}
{%- if template_type == 'sms' -%}
{%- if count == 1 -%}
text message
{%- else -%}
text messages
{%- endif -%}
{%- elif template_type == 'email' -%}
{%- if count == 1 -%}
email
{%- else -%}
emails
{%- endif -%}
{%- elif template_type == 'letter' -%}
{%- if count == 1 -%}
letter
{%- else -%}
letters
{%- endif -%}
{%- endif %} {{ suffix }}
{%- endmacro %}
{% macro recipient_count_label(count, template_type) -%}
{% if template_type == None %}
{%- if count == 1 -%}
recipient
{%- else -%}
recipients
{%- endif -%}
{% endif %}
{%- if template_type == 'sms' -%}
{%- if count == 1 -%}
phone number
{%- else -%}
phone numbers
{%- endif -%}
{%- elif template_type == 'email' -%}
{%- if count == 1 -%}
email address
{%- else -%}
email addresses
{%- endif -%}
{%- elif template_type == 'letter' -%}
{%- if count == 1 -%}
address
{%- else -%}
addresses
{%- endif -%}
{%- endif %}
{%- endmacro %}