From 8e947f315d9b864f79ffd8771b36cd0061eacc3d Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 20 Jul 2017 09:20:01 +0100 Subject: [PATCH] Refactor check error templates to repeat less MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There was a lot of repetetive wrapping code being repeated for every conditional block in these files. Let’s wrap it around the whole conditional bit once instead. --- .../check/not-allowed-to-send-to.html | 37 +++----- .../partials/check/too-many-messages.html | 84 +++++++++---------- app/templates/views/check/column-errors.html | 56 +++++-------- 3 files changed, 73 insertions(+), 104 deletions(-) diff --git a/app/templates/partials/check/not-allowed-to-send-to.html b/app/templates/partials/check/not-allowed-to-send-to.html index 5d2f001fb..5b1537ac2 100644 --- a/app/templates/partials/check/not-allowed-to-send-to.html +++ b/app/templates/partials/check/not-allowed-to-send-to.html @@ -1,25 +1,12 @@ -{% from "components/banner.html" import banner_wrapper %} - -{% macro skip_to_file_contents() %} -

- Skip to file contents -

-{% endmacro %} - -
- {% call banner_wrapper(type='dangerous') %} -

- You can’t send to - {{ 'this' if count_of_recipients == 1 else 'these' }} - {{ template_type_label }} - {%- if count_of_recipients != 1 -%} - {{ 'es' if 'email address' == template_type_label else 's' }} - {%- endif %} -

-

- In trial mode you can only - send to yourself and members of your team -

- {{ skip_to_file_contents() }} - {% endcall %} -
+

+ You can’t send to + {{ 'this' if count_of_recipients == 1 else 'these' }} + {{ template_type_label }} + {%- if count_of_recipients != 1 -%} + {{ 'es' if 'email address' == template_type_label else 's' }} + {%- endif %} +

+

+ In trial mode you can only + send to yourself and members of your team +

diff --git a/app/templates/partials/check/too-many-messages.html b/app/templates/partials/check/too-many-messages.html index 217ebad33..1f42c87f1 100644 --- a/app/templates/partials/check/too-many-messages.html +++ b/app/templates/partials/check/too-many-messages.html @@ -1,46 +1,40 @@ -{% from "components/banner.html" import banner_wrapper %} - -
- {% call banner_wrapper(type='dangerous') %} -

- {% if original_file_name %} - Too many recipients - {% else %} - Daily limit reached - {% endif %} -

-

- You can only send {{ current_service.message_limit }} messages per day - {%- if current_service.restricted %} - in trial mode - {%- endif -%} - . -

- {% if original_file_name %} -

- {% if current_service.message_limit != remaining_messages %} - You can still send {{ remaining_messages }} messages today, but - {% endif %} - ‘{{ original_file_name }}’ contains - {{ count_of_recipients }} - {% if count_of_recipients == 1 -%} - {%- if template.template_type == 'email' -%} - email address - {%- elif template.template_type == 'sms' -%} - phone number - {%- elif template.template_type == 'letter' -%} - address - {%- endif -%} - {%- else -%} - {%- if template.template_type == 'email' -%} - email addresses - {%- elif template.template_type == 'sms' -%} - phone numbers - {%- elif template.template_type == 'letter' -%} - addresses - {%- endif -%} - {%- endif -%}. -

+

+ {% if original_file_name %} + Too many recipients + {% else %} + Daily limit reached + {% endif %} +

+

+ You can only send {{ current_service.message_limit }} messages per day + {%- if current_service.restricted %} + in trial mode + {%- endif -%} + . +

+{% if original_file_name %} +

+ {% if current_service.message_limit != remaining_messages %} + You can still send {{ remaining_messages }} messages today, but {% endif %} - {% endcall %} -

+ ‘{{ original_file_name }}’ contains + {{ count_of_recipients }} + {% if count_of_recipients == 1 -%} + {%- if template.template_type == 'email' -%} + email address + {%- elif template.template_type == 'sms' -%} + phone number + {%- elif template.template_type == 'letter' -%} + address + {%- endif -%} + {%- else -%} + {%- if template.template_type == 'email' -%} + email addresses + {%- elif template.template_type == 'sms' -%} + phone numbers + {%- elif template.template_type == 'letter' -%} + addresses + {%- endif -%} + {%- endif -%}. +

+{% endif %} diff --git a/app/templates/views/check/column-errors.html b/app/templates/views/check/column-errors.html index d331eb1a2..032b4dd8c 100644 --- a/app/templates/views/check/column-errors.html +++ b/app/templates/views/check/column-errors.html @@ -19,10 +19,11 @@ {% block maincolumn_content %} - {% if recipients.too_many_rows %} +
+ {% call banner_wrapper(type='dangerous') %} + + {% if recipients.too_many_rows %} -
- {% call banner_wrapper(type='dangerous') %}

Your file has too many rows

@@ -31,14 +32,9 @@ {{ "{:,}".format(recipients.max_rows) }} rows at once. Your file has {{ "{:,}".format(recipients|length) }} rows.

- {{ skip_to_file_contents() }} - {% endcall %} -
- {% elif not count_of_recipients %} + {% elif not count_of_recipients %} -
- {% call banner_wrapper(type='dangerous') %}

Your file is missing some rows

@@ -48,14 +44,9 @@ prefix_plural='columns called' ) }}.

- {{ skip_to_file_contents() }} - {% endcall %} -
- {% elif not recipients.has_recipient_columns %} + {% elif not recipients.has_recipient_columns %} -
- {% call banner_wrapper(type='dangerous') %}

Your file needs {{ recipients.recipient_column_headers | formatted_list( prefix='a column called', @@ -68,14 +59,9 @@ prefix_plural='columns called ' ) }}.

- {{ skip_to_file_contents() }} - {% endcall %} -

- {% elif recipients.missing_column_headers %} + {% elif recipients.missing_column_headers %} -
- {% call banner_wrapper(type='dangerous') %}

The columns in your file need to match the double brackets in your template @@ -87,20 +73,22 @@ prefix_plural='columns called ' ) }}.

- {{ skip_to_file_contents() }} - {% endcall %} -

- {% elif not recipients.allowed_to_send_to %} - {% with - count_of_recipients=count_of_recipients, - template_type_label=recipients.recipient_column_headers[0] - %} - {% include "partials/check/not-allowed-to-send-to.html" %} - {% endwith %} - {% elif recipients.more_rows_than_can_send %} - {% include "partials/check/too-many-messages.html" %} - {% endif %} + {% elif not recipients.allowed_to_send_to %} + {% with + count_of_recipients=count_of_recipients, + template_type_label=recipients.recipient_column_headers[0] + %} + {% include "partials/check/not-allowed-to-send-to.html" %} + {% endwith %} + {% elif recipients.more_rows_than_can_send %} + {% include "partials/check/too-many-messages.html" %} + {% endif %} + + {{ skip_to_file_contents() }} + + {% endcall %} +
{% if request.args.from_test %}