Merge pull request #1910 from GSA/1487-display-data-most-used-templates-table

Display data: Most used templates table
This commit is contained in:
Carlo Costino
2024-09-04 15:59:21 -04:00
committed by GitHub
3 changed files with 70 additions and 34 deletions

View File

@@ -325,13 +325,19 @@ def aggregate_template_usage(template_statistics, sort_key="count"):
key=lambda x: x["template_id"], key=lambda x: x["template_id"],
): ):
template_stats = list(v) template_stats = list(v)
first_stat = template_stats[0] if template_stats else None
templates.append( templates.append(
{ {
"template_id": k, "template_id": k,
"template_name": template_stats[0]["template_name"], "template_name": first_stat.get("template_name"),
"template_type": template_stats[0]["template_type"], "template_type": first_stat.get("template_type"),
"count": sum(s["count"] for s in template_stats), "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"),
} }
) )

View File

@@ -1,35 +1,45 @@
{% from "components/table.html" import list_table, field, right_aligned_field_heading, row_heading, spark_bar_field %}
<div class="ajax-block-container"> <div class="ajax-block-container">
{% if template_statistics|length > 0 %} {% if template_statistics|length > 1 %}
<h2 class="margin-top-4 margin-bottom-1">Recent templates</h2> <h2 class="margin-top-4 margin-bottom-1">Most Used Templates</h2>
<div class='template-statistics-table table-overflow-x-auto'> <div class="template-statistics-table table-overflow-x-auto">
{% call(item, row_number) list_table( <table class="usa-table width-full">
template_statistics, <caption class="font-body-lg table-heading usa-sr-only">
caption="Messages sent by template", Messages sent by template
caption_visible=False, </caption>
border_visible=True, <thead class="table-field-headings">
empty_message='', <tr>
field_headings=[ <th class="table-field-heading-first" width="">
'Template', <span>Template name</span>
'Messages sent' </th>
], <th class="table-field-heading" width="">
field_headings_visible=False <span>Folder</span>
) %} </th>
<th class="table-field-heading" width="">
{% call row_heading() %} <span>Last used</span>
<a class="usa-link template-statistics-table-template-name" href="{{ url_for('.view_template', service_id=current_service.id, template_id=item.template_id) }}">{{ item.template_name }}</a> </th>
<span class="template-statistics-table-hint"> <th class="table-field-heading" width="">
{{ 1|message_count_label(item.template_type, suffix='template')|capitalize }} <span>Created by</span>
</span> </th>
{% endcall %} <th class="table-field-heading" width="">
<span># Times used</span>
{{ spark_bar_field(item.count, most_used_template_count, id=item.template_id) }} </th>
{% endcall %} </tr>
<a </thead>
href="{{ url_for('.template_usage', service_id=current_service.id) }}" <tbody>
class="usa-link show-more-no-border" {% for item in template_statistics[:8] %}
><span>See templates used by month</span></a> <tr class="table-row">
<td>
<a class="usa-link template-statistics-table-template-name" href="{{ url_for('.view_template', service_id=current_service.id, template_id=item.template_id) }}">{{ item.template_name }}</a>
</td>
<td><p>{{ item.template_folder }}</p></td>
<td><p>{{ item.last_used|format_datetime_table}}</p></td>
<td><p>{{ item.created_by }}</p></td>
<td><p>{{ item.count }}</p></td>
</tr>
{% endfor %}
</tbody>
</table>
<a href="/services/78409625-0c0a-485e-b82c-b19c8f4b1bdb/template-usage" class="usa-link show-more-no-border"><span>See templates by month</span></a>
</div> </div>
{% endif %} {% endif %}
</div> </div>

View File

@@ -133,6 +133,11 @@ stub_template_stats = [
"template_id": "id-1", "template_id": "id-1",
"status": "created", "status": "created",
"count": 50, "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", "template_type": "email",
@@ -140,6 +145,11 @@ stub_template_stats = [
"template_id": "id-2", "template_id": "id-2",
"status": "created", "status": "created",
"count": 100, "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", "template_type": "email",
@@ -147,6 +157,11 @@ stub_template_stats = [
"template_id": "id-2", "template_id": "id-2",
"status": "technical-failure", "status": "technical-failure",
"count": 100, "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", "template_type": "sms",
@@ -154,6 +169,11 @@ stub_template_stats = [
"template_id": "id-1", "template_id": "id-1",
"status": "delivered", "status": "delivered",
"count": 50, "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",
}, },
] ]