mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-05 08:31:00 -04:00
Merge pull request #1382 from alphagov/break-up-platform-admin
Break up platform admin
This commit is contained in:
@@ -30,14 +30,41 @@ def platform_admin():
|
||||
services = service_api_client.get_services(api_args)['data']
|
||||
|
||||
return render_template(
|
||||
'views/platform-admin.html',
|
||||
'views/platform-admin/index.html',
|
||||
include_from_test_key=form.include_from_test_key.data,
|
||||
form=form,
|
||||
**get_statistics(sorted(
|
||||
services,
|
||||
key=lambda service: (service['active'], sum_service_usage(service), service['created_at']),
|
||||
reverse=True
|
||||
))
|
||||
global_stats=create_global_stats(services),
|
||||
)
|
||||
|
||||
|
||||
@main.route("/platform-admin/live-services", endpoint='live_services')
|
||||
@main.route("/platform-admin/trial-services", endpoint='trial_services')
|
||||
@login_required
|
||||
@user_has_permissions(admin_override=True)
|
||||
def platform_admin_services():
|
||||
form = DateFilterForm(request.args)
|
||||
api_args = {'detailed': True, # specifically DO get inactive services
|
||||
'include_from_test_key': form.include_from_test_key.data
|
||||
}
|
||||
|
||||
if form.start_date.data:
|
||||
api_args['start_date'] = form.start_date.data
|
||||
api_args['end_date'] = form.end_date.data or datetime.utcnow().date()
|
||||
|
||||
services = filter_and_sort_services(
|
||||
service_api_client.get_services(api_args)['data'],
|
||||
trial_mode_services=request.endpoint == 'main.trial_services',
|
||||
)
|
||||
|
||||
return render_template(
|
||||
'views/platform-admin/services.html',
|
||||
include_from_test_key=form.include_from_test_key.data,
|
||||
form=form,
|
||||
services=list(format_stats_by_service(services)),
|
||||
page_title='{} services'.format(
|
||||
'Trial mode' if request.endpoint == 'main.trial_services' else 'Live'
|
||||
),
|
||||
global_stats=create_global_stats(services),
|
||||
)
|
||||
|
||||
|
||||
@@ -48,16 +75,19 @@ def sum_service_usage(service):
|
||||
return total
|
||||
|
||||
|
||||
def get_statistics(services):
|
||||
return {
|
||||
'global_stats': create_global_stats(services),
|
||||
'live_services': format_stats_by_service(
|
||||
service for service in services if not service['restricted']
|
||||
),
|
||||
'trial_mode_services': format_stats_by_service(
|
||||
service for service in services if service['restricted']
|
||||
),
|
||||
}
|
||||
def filter_and_sort_services(services, trial_mode_services=False):
|
||||
return (
|
||||
service for service in sorted(
|
||||
services,
|
||||
key=lambda service: (
|
||||
service['active'],
|
||||
sum_service_usage(service),
|
||||
service['created_at']
|
||||
),
|
||||
reverse=True,
|
||||
)
|
||||
if service['restricted'] == trial_mode_services
|
||||
)
|
||||
|
||||
|
||||
def create_global_stats(services):
|
||||
|
||||
@@ -49,12 +49,6 @@
|
||||
<li>
|
||||
<a href="{{ url_for('main.platform_admin') }}">Platform admin</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{ url_for('main.view_providers') }}">Providers</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{ url_for('main.letter_jobs') }}">Letter jobs</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li>
|
||||
<a href="{{ url_for('main.sign_out')}}">Sign out</a>
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{% extends "withoutnav_template.html" %}
|
||||
{% extends "views/platform-admin/_base_template.html" %}
|
||||
{% from "components/page-footer.html" import page_footer %}
|
||||
|
||||
{% block per_page_title %}
|
||||
Letter jobs
|
||||
{% endblock %}
|
||||
|
||||
{% block maincolumn_content %}
|
||||
{% block platform_admin_content %}
|
||||
|
||||
<h1 class="heading-large">Letter jobs</h1>
|
||||
|
||||
|
||||
34
app/templates/views/platform-admin/_base_template.html
Normal file
34
app/templates/views/platform-admin/_base_template.html
Normal file
@@ -0,0 +1,34 @@
|
||||
{% extends "withoutnav_template.html" %}
|
||||
{% from "components/textbox.html" import textbox %}
|
||||
{% from "components/checkbox.html" import checkbox %}
|
||||
{% from "components/page-footer.html" import page_footer %}
|
||||
|
||||
{% block maincolumn_content %}
|
||||
|
||||
<div class="grid-row">
|
||||
<div class="column-one-quarter">
|
||||
<p class="heading-medium">
|
||||
Platform admin
|
||||
</p>
|
||||
<nav class="navigation">
|
||||
{% for link_text, url in [
|
||||
('Summary', url_for('main.platform_admin')),
|
||||
('Live services', url_for('main.live_services')),
|
||||
('Trial mode services', url_for('main.trial_services')),
|
||||
('Providers', url_for('main.view_providers')),
|
||||
('Letter jobs', url_for('main.letter_jobs'))
|
||||
] %}
|
||||
<li>
|
||||
<a href="{{ url }}">
|
||||
{{ link_text }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</nav>
|
||||
</div>
|
||||
<div class="column-three-quarters">
|
||||
{% block platform_admin_content %}{% endblock %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
22
app/templates/views/platform-admin/_global_stats.html
Normal file
22
app/templates/views/platform-admin/_global_stats.html
Normal file
@@ -0,0 +1,22 @@
|
||||
{% from "components/big-number.html" import big_number_with_status %}
|
||||
{% from "components/message-count-label.html" import message_count_label %}
|
||||
<div class="grid-row bottom-gutter">
|
||||
<div class="column-half">
|
||||
{{ big_number_with_status(
|
||||
global_stats.email.delivered + global_stats.email.failed,
|
||||
message_count_label(global_stats.email.delivered, 'email'),
|
||||
global_stats.email.failed,
|
||||
global_stats.email.failure_rate,
|
||||
global_stats.email.failure_rate|float > 3,
|
||||
) }}
|
||||
</div>
|
||||
<div class="column-half">
|
||||
{{ big_number_with_status(
|
||||
global_stats.sms.delivered + global_stats.sms.failed,
|
||||
message_count_label(global_stats.sms.delivered, 'sms'),
|
||||
global_stats.sms.failed,
|
||||
global_stats.sms.failure_rate,
|
||||
global_stats.sms.failure_rate|float > 3,
|
||||
) }}
|
||||
</div>
|
||||
</div>
|
||||
27
app/templates/views/platform-admin/index.html
Normal file
27
app/templates/views/platform-admin/index.html
Normal file
@@ -0,0 +1,27 @@
|
||||
{% extends "views/platform-admin/_base_template.html" %}
|
||||
{% from "components/textbox.html" import textbox %}
|
||||
{% from "components/big-number.html" import big_number %}
|
||||
{% from "components/checkbox.html" import checkbox %}
|
||||
{% from "components/page-footer.html" import page_footer %}
|
||||
{% from "components/table.html" import mapping_table, field, stats_fields, row_group, row, right_aligned_field_heading, hidden_field_heading, text_field %}
|
||||
|
||||
{% block per_page_title %}
|
||||
Platform admin
|
||||
{% endblock %}
|
||||
|
||||
{% block platform_admin_content %}
|
||||
|
||||
<details>
|
||||
<summary>Apply filters</summary>
|
||||
<form autocomplete="off" method="get">
|
||||
{{ textbox(form.start_date, hint="Enter start date in format YYYY-MM-DD") }}
|
||||
{{ textbox(form.end_date, hint="Enter end date in format YYYY-MM-DD") }}
|
||||
{{ checkbox(form.include_from_test_key) }}
|
||||
</br>
|
||||
<input type="submit" class="button">
|
||||
</form>
|
||||
</details>
|
||||
|
||||
{% include "views/platform-admin/_global_stats.html" %}
|
||||
|
||||
{% endblock %}
|
||||
@@ -1,4 +1,4 @@
|
||||
{% extends "withoutnav_template.html" %}
|
||||
{% extends "views/platform-admin/_base_template.html" %}
|
||||
{% from "components/textbox.html" import textbox %}
|
||||
{% from "components/checkbox.html" import checkbox %}
|
||||
{% from "components/page-footer.html" import page_footer %}
|
||||
@@ -29,7 +29,7 @@
|
||||
{% macro services_table(services, caption) %}
|
||||
{% call(item, row_number) mapping_table(
|
||||
caption=caption,
|
||||
caption_visible=True,
|
||||
caption_visible=False,
|
||||
field_headings=[
|
||||
'Service',
|
||||
hidden_field_heading('Type'),
|
||||
@@ -81,13 +81,13 @@
|
||||
|
||||
|
||||
{% block per_page_title %}
|
||||
Platform admin
|
||||
{{ page_title|capitalize }}
|
||||
{% endblock %}
|
||||
|
||||
{% block maincolumn_content %}
|
||||
{% block platform_admin_content %}
|
||||
|
||||
<h1 class="heading-large">
|
||||
Platform admin
|
||||
{{ page_title|capitalize }}
|
||||
</h1>
|
||||
|
||||
<details>
|
||||
@@ -101,29 +101,8 @@
|
||||
</form>
|
||||
</details>
|
||||
|
||||
<div class="grid-row bottom-gutter">
|
||||
<div class="column-half">
|
||||
{{ big_number_with_status(
|
||||
global_stats.email.delivered + global_stats.email.failed,
|
||||
message_count_label(global_stats.email.delivered, 'email'),
|
||||
global_stats.email.failed,
|
||||
global_stats.email.failure_rate,
|
||||
global_stats.email.failure_rate|float > 3,
|
||||
) }}
|
||||
</div>
|
||||
<div class="column-half">
|
||||
{{ big_number_with_status(
|
||||
global_stats.sms.delivered + global_stats.sms.failed,
|
||||
message_count_label(global_stats.sms.delivered, 'sms'),
|
||||
global_stats.sms.failed,
|
||||
global_stats.sms.failure_rate,
|
||||
global_stats.sms.failure_rate|float > 3,
|
||||
) }}
|
||||
</div>
|
||||
</div>
|
||||
{% include "views/platform-admin/_global_stats.html" %}
|
||||
|
||||
{{ services_table(live_services, 'Live services') }}
|
||||
|
||||
{{ services_table(trial_mode_services, 'Trial mode services') }}
|
||||
{{ services_table(services, page_title|capitalize) }}
|
||||
|
||||
{% endblock %}
|
||||
@@ -1,4 +1,4 @@
|
||||
{% extends "withoutnav_template.html" %}
|
||||
{% extends "views/platform-admin/_base_template.html" %}
|
||||
{% from "components/table.html" import list_table, field, text_field, link_field, right_aligned_field_heading, hidden_field_heading %}
|
||||
{% from "components/show-more.html" import show_more %}
|
||||
|
||||
@@ -6,112 +6,107 @@
|
||||
Providers
|
||||
{% endblock %}
|
||||
|
||||
{% block maincolumn_content %}
|
||||
{% block platform_admin_content %}
|
||||
|
||||
<div class="grid-row">
|
||||
<div class="column-two-thirds">
|
||||
<h1 class="heading-large">Providers</h1>
|
||||
<h1 class="heading-large">Providers</h1>
|
||||
|
||||
<h2 class="heading-medium">SMS</h2>
|
||||
<h2 class="heading-medium">SMS</h2>
|
||||
|
||||
{% call(item, row_number) list_table(
|
||||
domestic_sms_providers,
|
||||
caption="Domestic SMS providers",
|
||||
caption_visible=False,
|
||||
empty_message='No domestic sms providers',
|
||||
field_headings=['Provider', 'Priority', 'Active', 'Last Updated', 'Updated By'],
|
||||
field_headings_visible=True
|
||||
) %}
|
||||
{% call(item, row_number) list_table(
|
||||
domestic_sms_providers,
|
||||
caption="Domestic SMS providers",
|
||||
caption_visible=False,
|
||||
empty_message='No domestic sms providers',
|
||||
field_headings=['Provider', 'Priority', 'Active', 'Last Updated', 'Updated By'],
|
||||
field_headings_visible=True
|
||||
) %}
|
||||
|
||||
{{ link_field(item.display_name, url_for('main.view_provider', provider_id=item.id)) }}
|
||||
{{ link_field(item.display_name, url_for('main.view_provider', provider_id=item.id)) }}
|
||||
|
||||
{{ text_field(item.priority) }}
|
||||
{{ text_field(item.priority) }}
|
||||
|
||||
{{ text_field(item.active) }}
|
||||
{{ text_field(item.active) }}
|
||||
|
||||
{% if item.updated_at %}
|
||||
{{ text_field(item.updated_at|format_datetime_short) }}
|
||||
{% else %}
|
||||
{{ text_field('None') }}
|
||||
{% endif %}
|
||||
{% if item.updated_at %}
|
||||
{{ text_field(item.updated_at|format_datetime_short) }}
|
||||
{% else %}
|
||||
{{ text_field('None') }}
|
||||
{% endif %}
|
||||
|
||||
{% if item.created_by %}
|
||||
{{ text_field(item.created_by.name) }}
|
||||
{% else %}
|
||||
{{ text_field('None') }}
|
||||
{% endif %}
|
||||
{% if item.created_by %}
|
||||
{{ text_field(item.created_by.name) }}
|
||||
{% else %}
|
||||
{{ text_field('None') }}
|
||||
{% endif %}
|
||||
|
||||
{{ link_field('change', url_for('main.edit_provider', provider_id=item.id)) }}
|
||||
{{ link_field('change', url_for('main.edit_provider', provider_id=item.id)) }}
|
||||
|
||||
{% endcall %}
|
||||
{% endcall %}
|
||||
|
||||
<h2 class="heading-medium">Email</h2>
|
||||
<h2 class="heading-medium">Email</h2>
|
||||
|
||||
{% call(item, row_number) list_table(
|
||||
email_providers,
|
||||
caption="Email providers",
|
||||
caption_visible=False,
|
||||
empty_message='No email providers',
|
||||
field_headings=['Provider', 'Priority', 'Active', 'Last Updated', 'Updated By'],
|
||||
field_headings_visible=True
|
||||
) %}
|
||||
{% call(item, row_number) list_table(
|
||||
email_providers,
|
||||
caption="Email providers",
|
||||
caption_visible=False,
|
||||
empty_message='No email providers',
|
||||
field_headings=['Provider', 'Priority', 'Active', 'Last Updated', 'Updated By'],
|
||||
field_headings_visible=True
|
||||
) %}
|
||||
|
||||
{{ link_field(item.display_name, url_for('main.view_provider', provider_id=item.id)) }}
|
||||
{{ link_field(item.display_name, url_for('main.view_provider', provider_id=item.id)) }}
|
||||
|
||||
{{ text_field(item.priority) }}
|
||||
{{ text_field(item.priority) }}
|
||||
|
||||
{{ text_field(item.active) }}
|
||||
{{ text_field(item.active) }}
|
||||
|
||||
{% if item.updated_at %}
|
||||
{{ text_field(item.updated_at|format_datetime_short) }}
|
||||
{% else %}
|
||||
{{ text_field('None') }}
|
||||
{% endif %}
|
||||
{% if item.updated_at %}
|
||||
{{ text_field(item.updated_at|format_datetime_short) }}
|
||||
{% else %}
|
||||
{{ text_field('None') }}
|
||||
{% endif %}
|
||||
|
||||
{% if item.created_by %}
|
||||
{{ text_field(item.created_by.name) }}
|
||||
{% else %}
|
||||
{{ text_field('None') }}
|
||||
{% endif %}
|
||||
{% if item.created_by %}
|
||||
{{ text_field(item.created_by.name) }}
|
||||
{% else %}
|
||||
{{ text_field('None') }}
|
||||
{% endif %}
|
||||
|
||||
{{ link_field('change', url_for('main.edit_provider', provider_id=item.id)) }}
|
||||
{{ link_field('change', url_for('main.edit_provider', provider_id=item.id)) }}
|
||||
|
||||
{% endcall %}
|
||||
{% endcall %}
|
||||
|
||||
<h1 class="heading-large">International SMS Providers</h1>
|
||||
<h1 class="heading-large">International SMS Providers</h1>
|
||||
|
||||
{% call(item, row_number) list_table(
|
||||
intl_sms_providers,
|
||||
caption="International SMS providers",
|
||||
caption_visible=False,
|
||||
empty_message='No international sms providers',
|
||||
field_headings=['Provider', 'Priority', 'Active', 'Last Updated', 'Updated By'],
|
||||
field_headings_visible=True
|
||||
) %}
|
||||
{% call(item, row_number) list_table(
|
||||
intl_sms_providers,
|
||||
caption="International SMS providers",
|
||||
caption_visible=False,
|
||||
empty_message='No international sms providers',
|
||||
field_headings=['Provider', 'Priority', 'Active', 'Last Updated', 'Updated By'],
|
||||
field_headings_visible=True
|
||||
) %}
|
||||
|
||||
{{ link_field(item.display_name, url_for('main.view_provider', provider_id=item.id)) }}
|
||||
{{ link_field(item.display_name, url_for('main.view_provider', provider_id=item.id)) }}
|
||||
|
||||
{{ text_field(item.priority) }}
|
||||
{{ text_field(item.priority) }}
|
||||
|
||||
{{ text_field(item.active) }}
|
||||
{{ text_field(item.active) }}
|
||||
|
||||
{% if item.updated_at %}
|
||||
{{ text_field(item.updated_at|format_datetime_short) }}
|
||||
{% else %}
|
||||
{{ text_field('None') }}
|
||||
{% endif %}
|
||||
{% if item.updated_at %}
|
||||
{{ text_field(item.updated_at|format_datetime_short) }}
|
||||
{% else %}
|
||||
{{ text_field('None') }}
|
||||
{% endif %}
|
||||
|
||||
{% if item.created_by %}
|
||||
{{ text_field(item.created_by.name) }}
|
||||
{% else %}
|
||||
{{ text_field('None') }}
|
||||
{% endif %}
|
||||
{% if item.created_by %}
|
||||
{{ text_field(item.created_by.name) }}
|
||||
{% else %}
|
||||
{{ text_field('None') }}
|
||||
{% endif %}
|
||||
|
||||
{{ link_field('change', url_for('main.edit_provider', provider_id=item.id)) }}
|
||||
{{ link_field('change', url_for('main.edit_provider', provider_id=item.id)) }}
|
||||
|
||||
{% endcall %}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
{% endcall %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user