From 3158b91378c5155c63f2fc2b6d7d220c19777dfd Mon Sep 17 00:00:00 2001 From: Beverly Nguyen Date: Thu, 29 Aug 2024 14:28:37 -0700 Subject: [PATCH 1/7] new revised table --- app/main/views/dashboard.py | 6 ++ app/templates/views/dashboard/dashboard.html | 4 +- .../views/dashboard/template-statistics.html | 71 +++++++++++-------- 3 files changed, 49 insertions(+), 32 deletions(-) diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index d5d26f0a35..447a4b552d 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -327,6 +327,12 @@ def aggregate_template_usage(template_statistics, sort_key="count"): "template_name": template_stats[0]["template_name"], "template_type": template_stats[0]["template_type"], "count": sum(s["count"] for s in template_stats), + "last_used": max(s["last_used"] for s in template_stats if s["last_used"]), + "created_by": template_stats[0]["created_by"], + "created_by_id": template_stats[0]["created_by_id"], + "status": template_stats[0]["status"], + "template_folder": template_stats[0]["template_folder"], + "template_folder_id": template_stats[0]["template_folder_id"], } ) diff --git a/app/templates/views/dashboard/dashboard.html b/app/templates/views/dashboard/dashboard.html index 114667f2dd..a6b410105d 100644 --- a/app/templates/views/dashboard/dashboard.html +++ b/app/templates/views/dashboard/dashboard.html @@ -52,9 +52,7 @@

- {% if current_user.has_permissions('manage_service') %}{% endif %} - {{ ajax_block(partials, updates_url, 'template-statistics') }}

Recent Batches

@@ -122,7 +120,7 @@

Recent Batches

-

Recent templates

+

Most Used Templates

{{ ajax_block(partials, updates_url, 'template-statistics') }} diff --git a/app/templates/views/dashboard/template-statistics.html b/app/templates/views/dashboard/template-statistics.html index 9acd142d6c..6e7b8e3a80 100644 --- a/app/templates/views/dashboard/template-statistics.html +++ b/app/templates/views/dashboard/template-statistics.html @@ -1,34 +1,47 @@ -{% from "components/table.html" import list_table, field, right_aligned_field_heading, row_heading, spark_bar_field %} -
{% if template_statistics|length > 1 %} -
- {% 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 +
+ + + + + + + + + + + + + {% for item in template_statistics[:8] %} + + + + + + + + {% endfor %} + +
+ Messages sent by template +
+ Template name + + Folder + + Last used + + Created by + + # Times used +
+ {{ item.template_name }} + + {{ 1|message_count_label(item.template_type, suffix='template')|capitalize }} + +

{{ item.template_folder }}

{{ item.last_used|format_datetime_table}}

{{ item.created_by }}

{{ item.count }}

+ See templates by month
{% endif %}
From 7fea566201cfae5e6ae553ee9ed286199fe1a54c Mon Sep 17 00:00:00 2001 From: Beverly Nguyen Date: Thu, 29 Aug 2024 14:52:04 -0700 Subject: [PATCH 2/7] dashboard edit --- app/templates/views/dashboard/dashboard.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/templates/views/dashboard/dashboard.html b/app/templates/views/dashboard/dashboard.html index a6b410105d..114667f2dd 100644 --- a/app/templates/views/dashboard/dashboard.html +++ b/app/templates/views/dashboard/dashboard.html @@ -52,7 +52,9 @@

+ {% if current_user.has_permissions('manage_service') %}{% endif %} + {{ ajax_block(partials, updates_url, 'template-statistics') }}

Recent Batches

@@ -120,7 +122,7 @@

Recent Batches

-

Most Used Templates

+

Recent templates

{{ ajax_block(partials, updates_url, 'template-statistics') }} From 5beb9fcce1d5e6dd9c8de25bb09d309d21f2ebbd Mon Sep 17 00:00:00 2001 From: Beverly Nguyen Date: Thu, 29 Aug 2024 14:56:12 -0700 Subject: [PATCH 3/7] reverting changes --- .../views/dashboard/template-statistics.html | 71 ++++++++----------- 1 file changed, 29 insertions(+), 42 deletions(-) diff --git a/app/templates/views/dashboard/template-statistics.html b/app/templates/views/dashboard/template-statistics.html index 6e7b8e3a80..9acd142d6c 100644 --- a/app/templates/views/dashboard/template-statistics.html +++ b/app/templates/views/dashboard/template-statistics.html @@ -1,47 +1,34 @@ +{% from "components/table.html" import list_table, field, right_aligned_field_heading, row_heading, spark_bar_field %} +
{% if template_statistics|length > 1 %} -
- - - - - - - - - - - - - {% for item in template_statistics[:8] %} - - - - - - - - {% endfor %} - -
- Messages sent by template -
- Template name - - Folder - - Last used - - Created by - - # Times used -
- {{ item.template_name }} - - {{ 1|message_count_label(item.template_type, suffix='template')|capitalize }} - -

{{ item.template_folder }}

{{ item.last_used|format_datetime_table}}

{{ item.created_by }}

{{ item.count }}

- See templates by month +
+ {% 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
{% endif %}
From e704cb1b788460f5a5361b6a8b2b220903e0011a Mon Sep 17 00:00:00 2001 From: Beverly Nguyen Date: Thu, 29 Aug 2024 15:10:08 -0700 Subject: [PATCH 4/7] added template-stats.html --- app/templates/views/dashboard/dashboard.html | 1 + .../views/dashboard/template-statistics.html | 74 +++++++++++-------- 2 files changed, 44 insertions(+), 31 deletions(-) diff --git a/app/templates/views/dashboard/dashboard.html b/app/templates/views/dashboard/dashboard.html index 9268b37e33..a2cb135808 100644 --- a/app/templates/views/dashboard/dashboard.html +++ b/app/templates/views/dashboard/dashboard.html @@ -137,6 +137,7 @@

Service activity

+

Most Used Templates

{{ ajax_block(partials, updates_url, 'template-statistics') }} diff --git a/app/templates/views/dashboard/template-statistics.html b/app/templates/views/dashboard/template-statistics.html index 77efbea509..6e7b8e3a80 100644 --- a/app/templates/views/dashboard/template-statistics.html +++ b/app/templates/views/dashboard/template-statistics.html @@ -1,35 +1,47 @@ -{% 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 %} +
+ + + + + + + + + + + + + {% for item in template_statistics[:8] %} + + + + + + + + {% endfor %} + +
+ Messages sent by template +
+ Template name + + Folder + + Last used + + Created by + + # Times used +
+ {{ item.template_name }} + + {{ 1|message_count_label(item.template_type, suffix='template')|capitalize }} + +

{{ item.template_folder }}

{{ item.last_used|format_datetime_table}}

{{ item.created_by }}

{{ item.count }}

+ See templates by month
{% endif %}
From 65ef22f26ecb5f58114a94438090d38e0412a63a Mon Sep 17 00:00:00 2001 From: Beverly Nguyen Date: Thu, 29 Aug 2024 15:19:51 -0700 Subject: [PATCH 5/7] removed template type --- app/templates/views/dashboard/dashboard.html | 1 - app/templates/views/dashboard/template-statistics.html | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/app/templates/views/dashboard/dashboard.html b/app/templates/views/dashboard/dashboard.html index a2cb135808..9268b37e33 100644 --- a/app/templates/views/dashboard/dashboard.html +++ b/app/templates/views/dashboard/dashboard.html @@ -137,7 +137,6 @@

Service activity

-

Most Used Templates

{{ ajax_block(partials, updates_url, 'template-statistics') }} diff --git a/app/templates/views/dashboard/template-statistics.html b/app/templates/views/dashboard/template-statistics.html index 6e7b8e3a80..da9a4be52b 100644 --- a/app/templates/views/dashboard/template-statistics.html +++ b/app/templates/views/dashboard/template-statistics.html @@ -1,5 +1,6 @@
{% if template_statistics|length > 1 %} +

Most Used Templates

From be14a4a0c4da14601f0d4ba508aa889d74402e3b Mon Sep 17 00:00:00 2001 From: Beverly Nguyen Date: Thu, 29 Aug 2024 17:10:51 -0700 Subject: [PATCH 6/7] fix testing --- app/main/views/dashboard.py | 32 +++++++++++++++++++------- tests/app/main/views/test_dashboard.py | 20 ++++++++++++++++ 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index 747641b040..344e9e031f 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -329,15 +329,31 @@ def aggregate_template_usage(template_statistics, sort_key="count"): templates.append( { "template_id": k, - "template_name": template_stats[0]["template_name"], - "template_type": template_stats[0]["template_type"], + "template_name": ( + template_stats[0].get("template_name") if template_stats else None + ), + "template_type": ( + template_stats[0].get("template_type") if template_stats else None + ), "count": sum(s["count"] for s in template_stats), - "last_used": max(s["last_used"] for s in template_stats if s["last_used"]), - "created_by": template_stats[0]["created_by"], - "created_by_id": template_stats[0]["created_by_id"], - "status": template_stats[0]["status"], - "template_folder": template_stats[0]["template_folder"], - "template_folder_id": template_stats[0]["template_folder_id"], + "created_by": ( + template_stats[0].get("created_by") if template_stats else None + ), + "created_by_id": ( + template_stats[0].get("created_by_id") if template_stats else None + ), + "last_used": ( + template_stats[0].get("last_used") if template_stats else None + ), + "status": template_stats[0].get("status") if template_stats else None, + "template_folder": ( + template_stats[0].get("template_folder") if template_stats else None + ), + "template_folder_id": ( + template_stats[0].get("template_folder_id") + if template_stats + else None + ), } ) diff --git a/tests/app/main/views/test_dashboard.py b/tests/app/main/views/test_dashboard.py index e2a7a6b587..5e04c8b7e2 100644 --- a/tests/app/main/views/test_dashboard.py +++ b/tests/app/main/views/test_dashboard.py @@ -133,6 +133,11 @@ "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 @@ "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 @@ "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 @@ "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", }, ] From c51a5593a7ee0fade2ec916457667c0b175fe2db Mon Sep 17 00:00:00 2001 From: Beverly Nguyen Date: Thu, 29 Aug 2024 17:34:24 -0700 Subject: [PATCH 7/7] clean up --- app/main/views/dashboard.py | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index 344e9e031f..8013acb9d2 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -325,35 +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].get("template_name") if template_stats else None - ), - "template_type": ( - template_stats[0].get("template_type") if template_stats else None - ), + "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": ( - template_stats[0].get("created_by") if template_stats else None - ), - "created_by_id": ( - template_stats[0].get("created_by_id") if template_stats else None - ), - "last_used": ( - template_stats[0].get("last_used") if template_stats else None - ), - "status": template_stats[0].get("status") if template_stats else None, - "template_folder": ( - template_stats[0].get("template_folder") if template_stats else None - ), - "template_folder_id": ( - template_stats[0].get("template_folder_id") - if template_stats - else None - ), + "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"), } )
@@ -29,9 +30,6 @@
{{ item.template_name }} - - {{ 1|message_count_label(item.template_type, suffix='template')|capitalize }} -

{{ item.template_folder }}

{{ item.last_used|format_datetime_table}}