mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-19 05:59:44 -04:00
Merge pull request #3022 from GSA/3021-create-aggregate-table-of-services-per-org
3021 create aggregate table of services per org
This commit is contained in:
@@ -76,6 +76,39 @@ def get_organization_message_allowance(org_id):
|
||||
}
|
||||
|
||||
|
||||
def get_services_dashboard_data(organization, year):
|
||||
try:
|
||||
dashboard_data = organizations_client.get_organization_dashboard(organization.id, year)
|
||||
services = dashboard_data.get("services", [])
|
||||
except Exception as e:
|
||||
current_app.logger.error(f"Error fetching dashboard data: {e}")
|
||||
return []
|
||||
|
||||
for service in services:
|
||||
service["id"] = service.get("service_id")
|
||||
service["name"] = service.get("service_name")
|
||||
service["recent_template"] = service.get("recent_sms_template_name") or "N/A"
|
||||
service["primary_contact"] = service.get("primary_contact") or "N/A"
|
||||
|
||||
emails_sent = service.get("emails_sent", 0)
|
||||
sms_sent = service.get("sms_billable_units", 0)
|
||||
sms_remainder = service.get("sms_remainder", 0)
|
||||
sms_cost = service.get("sms_cost", 0)
|
||||
|
||||
usage_parts = []
|
||||
if emails_sent > 0:
|
||||
usage_parts.append(f"{emails_sent:,} emails")
|
||||
if sms_sent > 0 or sms_remainder > 0:
|
||||
if sms_cost > 0:
|
||||
usage_parts.append(f"{sms_sent:,} sms ({sms_remainder:,} remaining, ${sms_cost:,.2f})")
|
||||
else:
|
||||
usage_parts.append(f"{sms_sent:,} sms ({sms_remainder:,} remaining)")
|
||||
|
||||
service["usage"] = ", ".join(usage_parts) if usage_parts else "No usage"
|
||||
|
||||
return services
|
||||
|
||||
|
||||
@main.route("/organizations/<uuid:org_id>", methods=["GET"])
|
||||
@user_has_permissions()
|
||||
def organization_dashboard(org_id):
|
||||
@@ -86,9 +119,12 @@ def organization_dashboard(org_id):
|
||||
|
||||
message_allowance = get_organization_message_allowance(org_id)
|
||||
|
||||
services_with_usage = get_services_dashboard_data(current_organization, year)
|
||||
|
||||
return render_template(
|
||||
"views/organizations/organization/index.html",
|
||||
selected_year=year,
|
||||
services=services_with_usage,
|
||||
live_services=len(current_organization.live_services),
|
||||
trial_services=len(current_organization.trial_services),
|
||||
suspended_services=len(current_organization.suspended_services),
|
||||
|
||||
@@ -83,5 +83,11 @@ class OrganizationsClient(NotifyAdminAPIClient):
|
||||
url="/organizations/{}/message-allowance".format(org_id),
|
||||
)
|
||||
|
||||
def get_organization_dashboard(self, org_id, year):
|
||||
return self.get(
|
||||
url=f"/organizations/{org_id}/dashboard",
|
||||
params={"year": str(year)},
|
||||
)
|
||||
|
||||
|
||||
organizations_client = OrganizationsClient()
|
||||
|
||||
@@ -58,19 +58,65 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<details class="usa-details">
|
||||
<summary class="usa-details__summary font-heading-lg ">What is a service?</summary>
|
||||
<div class="usa-details__content">
|
||||
<p class="usa-body">
|
||||
When you join Notify, you're added to a service. This is your organization's workspace for sending text messages and emails. Within your service, you can:
|
||||
</p>
|
||||
<ol class="usa-list">
|
||||
<li>Create and edit message templates</li>
|
||||
<li>Send messages to recipients</li>
|
||||
<li>View message status and history</li>
|
||||
<li>Manage team members and permissions</li>
|
||||
<li>Track usage and delivery statistics</li>
|
||||
<li>If you work for multiple organizations, you may belong to multiple services and can switch between them.</li>
|
||||
</ol>
|
||||
</div>
|
||||
</details>
|
||||
|
||||
|
||||
|
||||
<div class="margin-bottom-5">
|
||||
<h2 class="font-heading-lg">What is a service?</h2>
|
||||
<p class="usa-body">
|
||||
When you join Notify, you're added to a service. This is your organization's workspace for sending text messages and emails. Within your service, you can:
|
||||
</p>
|
||||
<ol class="usa-list">
|
||||
<li>Create and edit message templates</li>
|
||||
<li>Send messages to recipients</li>
|
||||
<li>View message status and history</li>
|
||||
<li>Manage team members and permissions</li>
|
||||
<li>Track usage and delivery statistics</li>
|
||||
<li>If you work for multiple organizations, you may belong to multiple services and can switch between them.</li>
|
||||
</ol>
|
||||
<h2 class="font-heading-lg margin-bottom-2">Services Overview</h2>
|
||||
<div class="table-overflow-x-auto">
|
||||
<table class="usa-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col" role="columnheader">Name</th>
|
||||
<th scope="col" role="columnheader">Status</th>
|
||||
<th scope="col" role="columnheader">Usage</th>
|
||||
<th scope="col" role="columnheader">Primary Contact</th>
|
||||
<th scope="col" role="columnheader">Recent Template Used</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% if services %}
|
||||
{% for service in services %}
|
||||
<tr>
|
||||
<td><a href="{{ url_for('main.service_dashboard', service_id=service.id) }}" class="usa-link">{{ service.name }}</a></td>
|
||||
<td>
|
||||
{% if not service.active %}
|
||||
Suspended
|
||||
{% elif service.restricted %}
|
||||
Trial
|
||||
{% else %}
|
||||
Live
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ service.usage }}</td>
|
||||
<td>{{ service.primary_contact }}</td>
|
||||
<td>{{ service.recent_template }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<tr>
|
||||
<td colspan="5" class="table-empty-message">No services found within this organization</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user