Remove template type filter from activity

This commit splits the activity page into two pages, one for emails
and one for SMS.

Technically this means moving from having template type in the
querystring and putting in it the URL, eg:

*Before*:
`/services/abc/notifications/?template_type=sms`

*After*:
`/services/abc/notifications/sms`
This commit changes the activity page to only have controls
This commit is contained in:
Chris Hill-Scott
2016-06-07 11:17:33 +01:00
parent 2e2e15bd95
commit 06903d54be
5 changed files with 70 additions and 146 deletions

View File

@@ -51,11 +51,6 @@ def _set_status_filters(filter_args):
filter_args['status'] = ['delivered', 'failed', 'temporary-failure', 'permanent-failure', 'technical-failure']
def _set_template_filters(filter_args):
if not filter_args.get('template_type'):
filter_args['template_type'] = ['email', 'sms']
@main.route("/services/<service_id>/jobs")
@login_required
@user_has_permissions('view_activity', admin_override=True)
@@ -144,26 +139,30 @@ def view_job_updates(service_id, job_id):
})
@main.route('/services/<service_id>/notifications')
@main.route('/services/<service_id>/notifications/<message_type>')
@login_required
@user_has_permissions('view_activity', admin_override=True)
def view_notifications(service_id):
def view_notifications(service_id, message_type):
# TODO get the api to return count of pages as well.
page = get_page_from_request()
if page is None:
abort(404, "Invalid page argument ({}) reverting to page 1.".format(request.args['page'], None))
if message_type not in ['email', 'sms']:
abort(404)
filter_args = _parse_filter_args(request.args)
_set_status_filters(filter_args)
_set_template_filters(filter_args)
notifications = notification_api_client.get_notifications_for_service(
service_id=service_id,
page=page,
template_type=filter_args.get('template_type'),
template_type=[message_type],
status=filter_args.get('status'),
limit_days=current_app.config['ACTIVITY_STATS_LIMIT_DAYS'])
view_dict = MultiDict(request.args)
view_dict = dict(
message_type=message_type,
status=request.args.get('status')
)
prev_page = None
if notifications['links'].get('prev', None):
prev_page = generate_previous_next_dict(
@@ -188,7 +187,7 @@ def view_notifications(service_id):
service_id=service_id,
page=page,
page_size=notifications['total'],
template_type=filter_args.get('template_type') if 'template_type' in filter_args else ['email', 'sms'],
template_type=[message_type],
status=filter_args.get('status'),
limit_days=current_app.config['ACTIVITY_STATS_LIMIT_DAYS'])['notifications'])
return csv_content, 200, {
@@ -202,28 +201,17 @@ def view_notifications(service_id):
prev_page=prev_page,
next_page=next_page,
request_args=request.args,
type_filters=[
[item[0], item[1], url_for(
'.view_notifications',
service_id=current_service['id'],
template_type=item[1],
status=request.args.get('status', 'delivered,failed')
)] for item in [
['Emails', 'email'],
['Text messages', 'sms'],
['Both', 'email,sms']
]
],
message_type=message_type,
status_filters=[
[item[0], item[1], url_for(
'.view_notifications',
service_id=current_service['id'],
template_type=request.args.get('template_type', 'email,sms'),
message_type=message_type,
status=item[1]
)] for item in [
['Successful', 'delivered'],
['Failed', 'failed'],
['Both', 'delivered,failed']
['', 'delivered,failed']
]
]
)

View File

@@ -18,8 +18,8 @@
statistics.emails_failed,
statistics.get('emails_failure_rate', 0.0),
statistics.get('emails_failure_rate', 0)|float > 3,
failure_link=url_for(".view_notifications", service_id=current_service.id, template_type='email', status='failed'),
label_link=url_for(".view_notifications", service_id=current_service.id, template_type='email', status='delivered,failed')
failure_link=url_for(".view_notifications", service_id=current_service.id, message_type='email', status='failed'),
label_link=url_for(".view_notifications", service_id=current_service.id, message_type='email', status='delivered,failed')
) }}
</div>
<div class="column-half">
@@ -29,8 +29,8 @@
statistics.sms_failed,
statistics.get('sms_failure_rate', 0.0),
statistics.get('sms_failure_rate', 0)|float > 3,
failure_link=url_for(".view_notifications", service_id=current_service.id, template_type='sms', status='failed'),
label_link=url_for(".view_notifications", service_id=current_service.id, template_type='sms', status='delivered,failed')
failure_link=url_for(".view_notifications", service_id=current_service.id, message_type='sms', status='failed'),
label_link=url_for(".view_notifications", service_id=current_service.id, message_type='sms', status='delivered,failed')
) }}
</div>
<div class="column-whole">

View File

@@ -3,60 +3,34 @@
{% from "components/previous-next-navigation.html" import previous_next_navigation %}
{% from "components/page-footer.html" import page_footer %}
{% from "components/pill.html" import pill %}
{% from "components/message-count-label.html" import message_count_label %}
{% block page_title %}
Activity GOV.UK Notify
{{ message_count_label(99, message_type, suffix='') | capitalize }} GOV.UK Notify
{% endblock %}
{% block maincolumn_content %}
<h1 class="heading-large">
{%- if (request_args.get('template_type', 'email,sms') == 'email,sms') and (request_args.get('status', 'delivered,failed') == 'delivered,failed') -%}
Activity
{%- else -%}
<span class="visually-hidden">
{%- if request_args.get('status') != 'delivered,failed' -%}
{%- for label, option, _ in status_filters -%}
{%- if request_args.get('status', 'delivered,failed') == option -%}{{label}} {% endif -%}
{%- endfor -%}
{%- endif -%}
</span>
{%- if request_args.get('template_type', 'email,sms') == 'email,sms' %} emails and text messages
{%- else -%}
{%- for template_label, template_option, _ in type_filters -%}
{%- if request_args.get('template_type') == template_option -%}
{%- if request_args.get('status', 'delivered,failed') == 'delivered,failed' -%}
{{ template_label }}
{%- else -%}
{{ template_label | lower }}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- endif -%}
{{- message_count_label(99, message_type, suffix='') | capitalize }}
</h1>
<div class='grid-row bottom-gutter'>
<div class='column-half'>
{{ pill(
'Status',
status_filters,
request_args.get('status', '')
) }}
</div>
<div class='column-half'>
{{ pill(
'Type',
type_filters,
request_args.get('template_type', '')
) }}
</div>
<div class='bottom-gutter'>
{{ pill(
'Status',
status_filters,
request_args.get('status', '')
) }}
</div>
{% if notifications %}