diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index ee289c3e5..8013acb9d 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -325,13 +325,19 @@ def aggregate_template_usage(template_statistics, sort_key="count"): key=lambda x: x["template_id"], ): template_stats = list(v) - + first_stat = template_stats[0] if template_stats else None templates.append( { "template_id": k, - "template_name": template_stats[0]["template_name"], - "template_type": template_stats[0]["template_type"], + "template_name": first_stat.get("template_name"), + "template_type": first_stat.get("template_type"), "count": sum(s["count"] for s in template_stats), + "created_by": first_stat.get("created_by"), + "created_by_id": first_stat.get("created_by_id"), + "last_used": first_stat.get("last_used"), + "status": first_stat.get("status"), + "template_folder": first_stat.get("template_folder"), + "template_folder_id": first_stat.get("template_folder_id"), } ) diff --git a/app/templates/views/dashboard/template-statistics.html b/app/templates/views/dashboard/template-statistics.html index 77efbea50..da9a4be52 100644 --- a/app/templates/views/dashboard/template-statistics.html +++ b/app/templates/views/dashboard/template-statistics.html @@ -1,35 +1,45 @@ -{% from "components/table.html" import list_table, field, right_aligned_field_heading, row_heading, spark_bar_field %} -
- {% if template_statistics|length > 0 %} -

Recent templates

-
- {% call(item, row_number) list_table( - template_statistics, - caption="Messages sent by template", - caption_visible=False, - border_visible=True, - empty_message='', - field_headings=[ - 'Template', - 'Messages sent' - ], - field_headings_visible=False - ) %} - - {% call row_heading() %} - {{ item.template_name }} - - {{ 1|message_count_label(item.template_type, suffix='template')|capitalize }} - - {% endcall %} - - {{ spark_bar_field(item.count, most_used_template_count, id=item.template_id) }} - {% endcall %} - See templates used by month + {% if template_statistics|length > 1 %} +

Most Used Templates

+
+ + + + + + + + + + + + + {% for item in template_statistics[:8] %} + + + + + + + + {% endfor %} + +
+ Messages sent by template +
+ Template name + + Folder + + Last used + + Created by + + # Times used +
+ {{ item.template_name }} +

{{ item.template_folder }}

{{ item.last_used|format_datetime_table}}

{{ item.created_by }}

{{ item.count }}

+ See templates by month
{% endif %}
diff --git a/tests/app/main/views/test_dashboard.py b/tests/app/main/views/test_dashboard.py index 7be8afc28..97cf42d68 100644 --- a/tests/app/main/views/test_dashboard.py +++ b/tests/app/main/views/test_dashboard.py @@ -133,6 +133,11 @@ stub_template_stats = [ "template_id": "id-1", "status": "created", "count": 50, + "last_used": "2024-01-25T23:02:25+00:00", + "created_by": "Test user", + "created_by_id": "987654", + "template_folder": "Some_folder", + "template_folder_id": "123456", }, { "template_type": "email", @@ -140,6 +145,11 @@ stub_template_stats = [ "template_id": "id-2", "status": "created", "count": 100, + "last_used": "2024-01-25T23:02:25+00:00", + "created_by": "Test user", + "created_by_id": "987654", + "template_folder": "Some_folder", + "template_folder_id": "123456", }, { "template_type": "email", @@ -147,6 +157,11 @@ stub_template_stats = [ "template_id": "id-2", "status": "technical-failure", "count": 100, + "last_used": "2024-01-25T23:02:25+00:00", + "created_by": "Test user", + "created_by_id": "987654", + "template_folder": "Some_folder", + "template_folder_id": "123456", }, { "template_type": "sms", @@ -154,6 +169,11 @@ stub_template_stats = [ "template_id": "id-1", "status": "delivered", "count": 50, + "last_used": "2024-01-25T23:02:25+00:00", + "created_by": "Test user", + "created_by_id": "987654", + "template_folder": "Some_folder", + "template_folder_id": "123456", }, ]