From 358edf7f205fcff0f5631917dc214bd60a7b38de Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 13 Jun 2017 15:28:33 +0100 Subject: [PATCH 1/4] Make list of templates filterable by type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- app/main/views/templates.py | 60 +++++++++++++++-------- app/templates/components/pill.html | 5 +- app/templates/views/templates/choose.html | 7 ++- tests/app/main/views/test_templates.py | 52 +++++++++++++++++++- 4 files changed, 100 insertions(+), 24 deletions(-) diff --git a/app/main/views/templates.py b/app/main/views/templates.py index c417576f4..95023c9d4 100644 --- a/app/main/views/templates.py +++ b/app/main/views/templates.py @@ -43,26 +43,7 @@ page_headings = { } -@main.route("/services//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//templates/") +@main.route("/services//templates/") @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//templates") +@main.route("/services//templates/") +@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//templates/.") @login_required @user_has_permissions('view_activity', admin_override=True) diff --git a/app/templates/components/pill.html b/app/templates/components/pill.html index efd895069..9456309ee 100644 --- a/app/templates/components/pill.html +++ b/app/templates/components/pill.html @@ -3,7 +3,8 @@ {% macro pill( items=[], current_value=None, - big_number_args={'smaller': True} + big_number_args={'smaller': True}, + show_count=True ) %}