diff --git a/app/__init__.py b/app/__init__.py index cb370773b..d4211a033 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -111,6 +111,7 @@ def create_app(): application.add_template_filter(format_date_normal) application.add_template_filter(format_date_short) application.add_template_filter(format_notification_status) + application.add_template_filter(format_notification_status_as_field_status) application.after_request(useful_headers_after_request) application.after_request(save_service_after_request) @@ -229,15 +230,36 @@ def valid_phone_number(phone_number): return False -def format_notification_status(status): - m = {'failed': 'Failed', - 'technical-failure': 'Technical failure', - 'temporary-failure': 'Temporarily failed', - 'permanent-failure': 'Permanently failed', - 'delivered': 'Delivered', - 'sending': 'Sending' - } - return m.get(status, status) +def format_notification_status(status, template_type): + return { + 'email': { + 'failed': 'Failed', + 'technical-failure': 'Technical failure', + 'temporary-failure': 'Temporary failure', + 'permanent-failure': 'Email address does not exist', + 'delivered': 'Delivered', + 'sending': 'Sending' + }, + 'sms': { + 'failed': 'Failed', + 'technical-failure': 'Technical failure', + 'temporary-failure': 'Temporary failure', + 'permanent-failure': 'Phone number does not exist', + 'delivered': 'Delivered', + 'sending': 'Sending' + } + }.get(template_type).get(status, status) + + +def format_notification_status_as_field_status(status): + return { + 'failed': 'error', + 'technical-failure': 'error', + 'temporary-failure': 'error', + 'permanent-failure': 'error', + 'delivered': None, + 'sending': 'default' + }.get(status, 'error') @login_manager.user_loader diff --git a/app/assets/stylesheets/components/table.scss b/app/assets/stylesheets/components/table.scss index efe70d644..05079605f 100644 --- a/app/assets/stylesheets/components/table.scss +++ b/app/assets/stylesheets/components/table.scss @@ -1,5 +1,7 @@ .table { margin-bottom: $gutter; + width: 100%; + table-layout: fixed; } .table-heading { @@ -13,6 +15,20 @@ } } +.table-row { + th { + display: table-cell; + width: 52.5%; + font-weight: normal; + + .hint { + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } + } +} + %table-field, .table-field { @@ -77,6 +93,10 @@ width: 15px; } + &-date { + white-space: nowrap; + } + p { margin: 0 0 5px 0; } @@ -85,6 +105,10 @@ .table-field-heading { + &-first { + width: 52.5%; + } + &:last-child { padding-right: 0; } diff --git a/app/assets/stylesheets/views/dashboard.scss b/app/assets/stylesheets/views/dashboard.scss index 1f4d2022e..6069a8f20 100644 --- a/app/assets/stylesheets/views/dashboard.scss +++ b/app/assets/stylesheets/views/dashboard.scss @@ -3,8 +3,7 @@ table { th { @include core-16; - padding-top: 0; - border: 0; + border-bottom: 0; } td { @@ -59,6 +58,10 @@ &-filename { @include bold-19; + display: block; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; } &-hint { diff --git a/app/templates/components/table.html b/app/templates/components/table.html index 5f96508ce..95ba0264f 100644 --- a/app/templates/components/table.html +++ b/app/templates/components/table.html @@ -55,12 +55,24 @@ {%- endmacro %} +{% macro row_heading() -%} + + {{ caller() }} + +{%- endmacro %} + {% macro index_field(text) -%} {{ text }} {%- endmacro %} +{% macro date_field(text) -%} + + {{ text }} + +{% endmacro %} + {% macro text_field(text) -%} {% call field() %} {{ text }} diff --git a/app/templates/partials/jobs/notifications.html b/app/templates/partials/jobs/notifications.html index 2dd4ecdc8..cb87d6280 100644 --- a/app/templates/partials/jobs/notifications.html +++ b/app/templates/partials/jobs/notifications.html @@ -1,4 +1,4 @@ -{% from "components/table.html" import list_table, field, right_aligned_field_heading %} +{% from "components/table.html" import list_table, field, right_aligned_field_heading, date_field, row_heading %}
-
- {% if notifications|length > 0 and notifications[0].job_row_number is not none %} - {% call(item, row_number) list_table( - notifications, - caption=uploaded_file_name, - caption_visible=False, - empty_message="No messages to show yet", - field_headings=[ - 'Recipient', - right_aligned_field_heading('Status') - ] - ) %} - {% call field() %} - {{ item.to }} - {% endcall %} - {% call field( - align='right', - status='error' if item.status == 'Failed' else 'default' - ) %} - {{ item.status|format_notification_status }} at {{ (item.updated_at or item.created_at)|format_time }} - {% endcall %} - {% endcall %} - {% else %} - {% call(item, row_number) list_table( - notifications, - caption=uploaded_file_name, - caption_visible=False, - empty_message="No messages to show yet", - field_headings=[ - 'Recipient', - right_aligned_field_heading('Status') - ] - ) %} - {% call field() %} - {{ item.to }} - {% endcall %} - {% call field( - align='right', - status='error' if item.status == 'Failed' else 'default' - ) %} - {{ item.status|format_notification_status }} at {{ item.updated_at|format_time }} - {% endcall %} + {% call(item, row_number) list_table( + notifications, + caption=uploaded_file_name, + caption_visible=False, + empty_message="No messages to show yet", + field_headings=[ + 'Recipient', + 'Time', + 'Status' + ], + field_headings_visible=False + ) %} + {% call row_heading() %} + {{ item.to }} {% endcall %} - {% endif %} -
+ {{ date_field( + (item.updated_at or item.created_at)|format_datetime_short + ) }} + {% call field( + align='right', + status=item.status|format_notification_status_as_field_status + ) %} + {{ item.status|format_notification_status(item.template.template_type) }} + {% endcall %} + {% endcall %}
diff --git a/app/templates/views/dashboard/_jobs.html b/app/templates/views/dashboard/_jobs.html index 26dc0acca..4b21598f8 100644 --- a/app/templates/views/dashboard/_jobs.html +++ b/app/templates/views/dashboard/_jobs.html @@ -1,4 +1,4 @@ -{% from "components/table.html" import list_table, field, right_aligned_field_heading %} +{% from "components/table.html" import list_table, field, right_aligned_field_heading, row_heading %} {% from "components/big-number.html" import big_number %} {% call(item, row_number) list_table( @@ -8,28 +8,28 @@ empty_message='You haven’t sent any batch messages yet', field_headings=[ 'File', - right_aligned_field_heading('Sending'), - right_aligned_field_heading('Delivered'), - right_aligned_field_heading('Failed') + 'Sending', + 'Delivered', + 'Failed' ], field_headings_visible=True ) %} - {% call field() %} + {% call row_heading() %}
{{ item.original_file_name }} Uploaded {{ item.created_at|format_datetime_short }}
{{ item.to }}

- {{ item.template.name }} - sent from {% if item.job %} - {{ item.job.original_file_name }} + From {{ item.job.original_file_name }} {% else %} - an API call + {{ item.template.name }} + from an API call {% endif %}

{% endcall %} - {{ text_field(item.status|format_notification_status) }} + {{ date_field( + (item.updated_at or item.created_at)|format_datetime_short + ) }} - {% call field(align='right') %} - {{ (item.updated_at or item.created_at)|format_datetime_short }} + {% call field(status=item.status|format_notification_status_as_field_status, align='right') %} + {{ item.status|format_notification_status(item.template.template_type) }} {% endcall %} + {% endcall %} {{ previous_next_navigation(prev_page, next_page) }} diff --git a/tests/app/main/views/test_jobs.py b/tests/app/main/views/test_jobs.py index 473367424..791183dd7 100644 --- a/tests/app/main/views/test_jobs.py +++ b/tests/app/main/views/test_jobs.py @@ -47,7 +47,8 @@ def test_should_show_page_for_one_job( content = response.get_data(as_text=True) assert "{}: Your vehicle tax is about to expire".format(service_one['name']) in content assert file_name in content - assert "Delivered at 11:10" in content + assert 'Delivered' in content + assert '11:10' in content @freeze_time("2016-01-01 11:09:00.061258") @@ -75,7 +76,8 @@ def test_should_show_updates_for_one_job_as_json( assert '07123456789' in content['notifications'] assert 'Status' in content['notifications'] assert job_json['status'] in content['status'] - assert 'Delivered at 11:10' in content['notifications'] + assert 'Delivered' in content['notifications'] + assert '11:10' in content['notifications'] assert 'Uploaded by Test User on 1 January at 11:09' in content['status']