Only show template navigation when it’s useful

There are lots of services that only send emails, or only send text
messages. For these services, being able to filter the list of templates
but type is pointless – it won’t cut the list down at all.

This commit adds some logic to only show the navigation if the service
has some variety of template types.
This commit is contained in:
Chris Hill-Scott
2017-06-13 15:27:29 +01:00
parent 358edf7f20
commit f386b991cb
4 changed files with 38 additions and 3 deletions

View File

@@ -88,6 +88,10 @@ def view_template(service_id, template_id):
def choose_template(service_id, template_type='all'):
templates = service_api_client.get_service_templates(service_id)['data']
has_multiple_template_types = len({
template['template_type'] for template in templates
}) > 1
template_nav_items = [
(label, key, url_for('.choose_template', service_id=current_service['id'], template_type=key), '')
for label, key in filter(None, [
@@ -104,6 +108,7 @@ def choose_template(service_id, template_type='all'):
template for template in templates
if template_type in ['all', template['template_type']]
],
show_template_nav=has_multiple_template_types,
template_nav_items=template_nav_items,
template_type=template_type,
search_form=SearchTemplatesForm(),

View File

@@ -48,9 +48,11 @@
{% endif %}
</div>
<div class="bottom-gutter-2-3">
{{ pill(template_nav_items, current_value=template_type, show_count=False) }}
</div>
{% if show_template_nav %}
<div class="bottom-gutter-2-3">
{{ pill(template_nav_items, current_value=template_type, show_count=False) }}
</div>
{% endif %}
{% if templates|length > 7 %}
<div data-module="autofocus">