diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index 6b5edf6f4..5c890156c 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -62,20 +62,46 @@ def service_dashboard(service_id): job_response = job_api_client.get_jobs(service_id)["data"] service_data_retention_days = 7 - filtered_jobs = [job for job in job_response if job["job_status"] != "cancelled"] - sorted_jobs = sorted(filtered_jobs, key=lambda job: job["created_at"], reverse=True) + active_jobs = [job for job in job_response if job["job_status"] != "cancelled"] + sorted_jobs = sorted(active_jobs, key=lambda job: job["created_at"], reverse=True) + job_lists = [ + { + **job_dict, + "finished_processing": job_is_finished(job_dict) + } + for job_dict in sorted_jobs + ] return render_template( "views/dashboard/dashboard.html", updates_url=url_for(".service_dashboard_updates", service_id=service_id), partials=get_dashboard_partials(service_id), - jobs=sorted_jobs, + jobs=job_lists, service_data_retention_days=service_data_retention_days, sms_sent=sms_sent, sms_allowance_remaining=sms_allowance_remaining, ) +def job_is_finished(job_dict): + done_statuses = [ + "delivered", + "sent", + "failed", + "technical-failure", + "temporary-failure", + "permanent-failure", + "cancelled" + ] + + processed_count = sum( + stat["count"] + for stat in job_dict["statistics"] + if stat["status"] in done_statuses + ) + return job_dict["notification_count"] == processed_count + + @main.route("/services//daily-stats.json") @user_has_permissions() def get_daily_stats(service_id): diff --git a/app/templates/partials/jobs/status.html b/app/templates/partials/jobs/status.html index 0f3288813..3cdc83012 100644 --- a/app/templates/partials/jobs/status.html +++ b/app/templates/partials/jobs/status.html @@ -25,7 +25,7 @@ {% if job.scheduled_for %}
-

Your message has been scheduled

+

Your {{ 'message has' if job.notification_count == 1 else 'messages have' }} been scheduled

{{ job.template_name }} - {{ current_service.name }} was scheduled on {{ job.scheduled_for|format_datetime_normal }} by {{ job.created_by.name }}

@@ -37,7 +37,7 @@

- Your message is sending + Your {{ 'message is' if job.notification_count == 1 else 'messages are' }} sending

{{ job.template_name }} - {{ current_service.name }} @@ -49,7 +49,7 @@

- Your message is pending + Your {{ 'message is' if job.notification_count == 1 else 'messages are' }} pending

{{ job.template_name }} - {{ current_service.name }} @@ -60,11 +60,11 @@ {% endif %} {{display_message_status}} {% endif %} - {% elif arrived_from_preview_page_url %} + {% else %}

- Your message has been sent + Your {{ 'message has' if job.notification_count == 1 else 'messages have' }} been sent

{{ job.template_name }} - {{ current_service.name }} diff --git a/app/templates/views/dashboard/activity-table.html b/app/templates/views/dashboard/activity-table.html index 7a8bd7736..1dbb2bc7d 100644 --- a/app/templates/views/dashboard/activity-table.html +++ b/app/templates/views/dashboard/activity-table.html @@ -46,14 +46,16 @@ {{ job.template_name }} - {% if job.scheduled_for and not job.processing_finished %} - Scheduled for {{ job.scheduled_for|format_datetime_table }} - {% elif job.processing_finished and not job.statistics|selectattr('status', 'equalto', 'sending')|list %} - Sent on {{ job.processing_finished|format_datetime_table }} - {% elif job.processing_started %} - Sending since {{ job.processing_started|format_datetime_table }} + {% if not job.finished_processing %} + {% if job.scheduled_for%} + Scheduled for {{ job.scheduled_for|format_datetime_table }} + {% elif job.processing_started %} + Sending since {{ job.processing_started|format_datetime_table }} + {% else %} + Pending since {{ job.created_at|format_datetime_table }} + {% endif %} {% else %} - Pending since {{ job.created_at|format_datetime_table }} + Sent on {{ job.processing_started|format_datetime_table }} {% endif %} {{ job.created_by.name }} diff --git a/app/templates/views/jobs/job.html b/app/templates/views/jobs/job.html index 1643715f4..d5d3711d5 100644 --- a/app/templates/views/jobs/job.html +++ b/app/templates/views/jobs/job.html @@ -11,7 +11,7 @@ {% block maincolumn_content %} {{ page_header("Message status") }} - {% if not job.processing_finished %} + {% if not job.finished_processing %}

{% endif %} {{ partials['status']|safe }} - {% if not job.processing_finished %} + {% if not job.finished_processing %}
{% endif %} {% if not finished %}