Make list of templates filterable by type

When users are trying to find a template there’s a fair chance that they
know whether or not it’s an email/text message/(letter) that they’re
looking for.

Making them scroll past a whole bunch of templates of a different type
means it will take them longer to find the template they are looking
for.

We already have search on the templates page, but this is only good for
where they can remember the name of the template. This will be
sometimes but not always.

This commit adds some navigation to filter down the list of templates to
only show one type at a time. By default it will show all templates. It
adapts the pattern we use for filtering notifications by
sending/failed/delivered, but without the counts of how many things are
in each bucket (I don’t think there’s any value in knowing you have X
text message templates; on this page you only really care
about the one template you’re looking for).

_Note: required re-arranging the functions in `templates.py`. The route
for `/template/:uuid` needs to come before the route for
`template/:string` otherwise Flask tries to interpret a template’s ID
as its type.
This commit is contained in:
Chris Hill-Scott
2017-06-13 15:28:33 +01:00
parent 114bac7b80
commit 358edf7f20
4 changed files with 100 additions and 24 deletions

View File

@@ -43,26 +43,7 @@ page_headings = {
}
@main.route("/services/<service_id>/templates", methods=['GET'])
@login_required
@user_has_permissions(
'view_activity',
'send_texts',
'send_emails',
'manage_templates',
'manage_api_keys',
admin_override=True,
any_=True,
)
def choose_template(service_id):
return render_template(
'views/templates/choose.html',
templates=service_api_client.get_service_templates(service_id)['data'],
search_form=SearchTemplatesForm(),
)
@main.route("/services/<service_id>/templates/<template_id>")
@main.route("/services/<service_id>/templates/<uuid:template_id>")
@login_required
@user_has_permissions(
'view_activity',
@@ -73,7 +54,7 @@ def choose_template(service_id):
admin_override=True, any_=True
)
def view_template(service_id, template_id):
template = service_api_client.get_service_template(service_id, template_id)['data']
template = service_api_client.get_service_template(service_id, str(template_id))['data']
return render_template(
'views/templates/template.html',
template=get_template(
@@ -92,6 +73,43 @@ def view_template(service_id, template_id):
)
@main.route("/services/<service_id>/templates")
@main.route("/services/<service_id>/templates/<template_type>")
@login_required
@user_has_permissions(
'view_activity',
'send_texts',
'send_emails',
'manage_templates',
'manage_api_keys',
admin_override=True,
any_=True,
)
def choose_template(service_id, template_type='all'):
templates = service_api_client.get_service_templates(service_id)['data']
template_nav_items = [
(label, key, url_for('.choose_template', service_id=current_service['id'], template_type=key), '')
for label, key in filter(None, [
('All', 'all'),
('Text message', 'sms'),
('Email', 'email'),
('Letter', 'letter') if current_service['can_send_letters'] else None,
])
]
return render_template(
'views/templates/choose.html',
templates=[
template for template in templates
if template_type in ['all', template['template_type']]
],
template_nav_items=template_nav_items,
template_type=template_type,
search_form=SearchTemplatesForm(),
)
@main.route("/services/<service_id>/templates/<template_id>.<filetype>")
@login_required
@user_has_permissions('view_activity', admin_override=True)