diff --git a/app/assets/javascripts/activityChart.js b/app/assets/javascripts/activityChart.js index efdda477f..9ba1e4338 100644 --- a/app/assets/javascripts/activityChart.js +++ b/app/assets/javascripts/activityChart.js @@ -130,11 +130,12 @@ .append('g') .attr('class', 'bar-group') .attr('fill', d => color(d.key)); - + const minBarHeight = 5; barGroups.selectAll('rect') .data(d => d) .enter() .append('rect') + .filter(d => d[1] - d[0] > 0) .attr('x', d => x(d.data.label)) .attr('y', height) .attr('height', 0) @@ -155,8 +156,10 @@ .transition() .duration(1000) .attr('y', d => y(d[1])) - .attr('height', d => y(d[0]) - y(d[1])); - }; + .attr('height', d => { + const calculatedHeight = y(d[0]) - y(d[1]); + return calculatedHeight < minBarHeight ? minBarHeight : calculatedHeight; + }); }; // Function to create an accessible table const createTable = function(tableId, chartType, labels, deliveredData, failedData, pendingData) { @@ -238,9 +241,6 @@ failedData.push(data[dateString].sms.failure); pendingData.push(data[dateString].sms.pending || 0); totalMessages += data[dateString].sms.delivered + data[dateString].sms.failure + data[dateString].sms.pending; - - // Calculate the total number of messages - totalMessages += data[dateString].sms.delivered + data[dateString].sms.failure; } } diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index 6b5edf6f4..b7dce493a 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): @@ -89,7 +115,6 @@ def get_daily_stats(service_id): @main.route("/services//daily-stats-by-user.json") @user_has_permissions() def get_daily_stats_by_user(service_id): - service_id = session.get("service_id") date_range = get_stats_date_range() stats = service_api_client.get_user_service_notification_statistics_by_day( service_id, diff --git a/app/templates/partials/jobs/status.html b/app/templates/partials/jobs/status.html index 0f3288813..d56d73201 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 }} @@ -64,7 +64,7 @@

- 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 %}