From 43a922638b47b79801eb39d58bede1aa83e11438 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 28 Feb 2017 12:16:35 +0000 Subject: [PATCH] Merge email, text message + letter templates pages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Right now we have separate pages for email and text message templates. In the future we will also have a separate page for letter templates. This commit changes Notify to only have one page for all templates. What is the problem? --- The left-hand navigation is getting quite crowded, at 8 items for a service that can send letters. Research suggests that the number of objects an average human can hold in working memory is 7 ± 2 [1]. So we’re at the limit of how many items the navigation should have. In the future we will need to search/sort/filter templates by attributes other than type, for example: - show me the ‘confirmation’ templates - show me the most recently used templates - show me all templates containing the placeholder `((ref_no))` These are hypothetical for now, but these needs (or others) may become real in the future. At this point pre-filtering the list of templates by type would restrict what searches a user could do. So by making this change now we’re in a better position to iterate the design in the future. What’s the change? --- This commit replaces the ‘Email templates’, ‘Text message templates’ and ‘Letter templates’ pages with one page called ‘Templates’. This new templates page shows all the templates for the service, sorted by most recently created first (as before). To add a new template there is a new page with a form asking you what kind of template you want to create. This is necessary because in the past we knew what kind of template you wanted to create based on the kind you were looking at. What’s the impact of this change on new users? --- This change alters the onboarding process slightly. We still want to take people through the empty templates page from the call-to-action on the dashboard because it helps them understand that to send a message using Notify you need a template. But because we don’t have separate pages for emails/text messages we will have to send users through the extra step of choosing what kind of template to create. This is a bit clunkier on first use but: - it still gets the point across - it takes them through the actual flow they will be using to create new templates in the future (ie they’re learning how to use Notify, not just being taken through a special onboarding route) I’m not too worried about this change in terms of the experience for new users. Furthermore, by making it now we get to validate whether it’s causing any problems in the lab research booked for next week. What’s the impact of this change on current services? --- Looking at the top 15 services by number of templates[2], most are using either text messages or emails. So this change would not have a significant impact on these services because the page will not get any longer. In other words we wouldn’t be making it worse for them. Those services who do use both are not using as many templates. The worst-case scenario is SSCS, who have 16 templates, evenly split between email and text messages. So they would go from having 8 templates per page to 16, which is still less than half the number that HMPO or Digital Marketplace are managing. References --- 1. https://en.wikipedia.org/wiki/The_Magical_Number_Seven,_Plus_or_Minus_Two 2. Template usage by service Service name | Template count | Template types ---------------------------------------|----------------|--------------- Her Majesty's Passport Office | 40 | sms Digital Marketplace | 40 | email GovWifi-Staging | 19 | sms GovWifi | 18 | sms Digital Apprenticeship Service | 16 | email SSCS | 16 | both Crown Commercial Service MI Collection | 15 | email Help with Prison Visits | 12 | both Digital Future | 12 | email Export Licensing Service | 11 | email Civil Money Claims | 9 | both DVLA Drivers Medical Service | 9 | sms GOV.UK Notify | 8 | both Manage your benefit overpayments | 8 | both Tax Renewals | 8 | both --- app/main/forms.py | 20 +++++++ app/main/views/send.py | 35 +---------- app/main/views/templates.py | 56 +++++++++++++++++- app/templates/main_nav.html | 6 +- .../views/dashboard/write-first-messages.html | 15 ++--- app/templates/views/templates/add.html | 21 +++++++ app/templates/views/templates/choose.html | 25 +++++--- .../views/templates/choose_history.html | 2 +- app/templates/views/templates/template.html | 6 +- tests/app/main/views/test_dashboard.py | 21 ++----- tests/app/main/views/test_letters.py | 28 ++++++++- tests/app/main/views/test_main_nav.py | 58 ------------------- tests/app/main/views/test_send.py | 10 ++-- tests/app/main/views/test_templates.py | 2 +- tests/conftest.py | 6 +- 15 files changed, 168 insertions(+), 143 deletions(-) create mode 100644 app/templates/views/templates/add.html delete mode 100644 tests/app/main/views/test_main_nav.py diff --git a/app/main/forms.py b/app/main/forms.py index ca271dc2b..6e469be2b 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -558,3 +558,23 @@ class DateFilterForm(Form): start_date = DateField("Start Date", [validators.optional()]) end_date = DateField("End Date", [validators.optional()]) include_from_test_key = BooleanField("Include test keys", default="checked", false_values={"N"}) + + +class ChooseTemplateType(Form): + + template_type = RadioField( + 'What kind of template do you want to add?', + validators=[ + DataRequired() + ] + ) + + def __init__(self, include_letters=False, *args, **kwargs): + + super().__init__(*args, **kwargs) + + self.template_type.choices = filter(None, [ + ('email', 'Email'), + ('sms', 'Text message'), + ('letter', 'Letter') if include_letters else None + ]) diff --git a/app/main/views/send.py b/app/main/views/send.py index 5a47a8173..971e6c433 100644 --- a/app/main/views/send.py +++ b/app/main/views/send.py @@ -82,35 +82,6 @@ def get_example_letter_address(key): }.get(key, '') -@main.route("/services//send/", 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, template_type): - if template_type not in ['email', 'sms', 'letter']: - abort(404) - if not current_service['can_send_letters'] and template_type == 'letter': - abort(403) - return render_template( - 'views/templates/choose.html', - templates=[ - get_template( - template, - current_service, - letter_preview_url=url_for('.view_template', service_id=service_id, template_id=template['id']), - ) - for template in service_api_client.get_service_templates(service_id)['data'] - if template['template_type'] == template_type - ], - template_type=template_type, - page_heading=get_page_headings(template_type) - ) - - @main.route("/services//send//csv", methods=['GET', 'POST']) @login_required @user_has_permissions('send_texts', 'send_emails', 'send_letters') @@ -285,7 +256,7 @@ def _check_messages(service_id, template_type, upload_id, letters_as_pdf=False): ) else: back_link = url_for( - '.choose_template', service_id=service_id, template_type=template.template_type, **extra_args + '.choose_template', service_id=service_id, **extra_args ) choose_time_form = None else: @@ -359,7 +330,7 @@ def check_messages_as_png(service_id, template_type, upload_id): def recheck_messages(service_id, template_type, upload_id): if not session.get('upload_data'): - return redirect(url_for('main.choose_template', service_id=service_id, template_type=template_type)) + return redirect(url_for('main.choose_template', service_id=service_id)) return send_messages(service_id, session['upload_data'].get('template_id')) @@ -412,4 +383,4 @@ def get_check_messages_back_url(service_id, template_type): if len(templates) == 1: return url_for('.send_test', service_id=service_id, template_id=templates[0]['id'], help=1) - return url_for('main.choose_template', service_id=service_id, template_type=template_type) + return url_for('main.choose_template', service_id=service_id) diff --git a/app/main/views/templates.py b/app/main/views/templates.py index cd6699d3b..a261401ab 100644 --- a/app/main/views/templates.py +++ b/app/main/views/templates.py @@ -12,7 +12,7 @@ from notifications_python_client.errors import HTTPError from app.main import main from app.utils import user_has_permissions, get_template, png_from_pdf -from app.main.forms import SMSTemplateForm, EmailTemplateForm, LetterTemplateForm +from app.main.forms import ChooseTemplateType, SMSTemplateForm, EmailTemplateForm, LetterTemplateForm from app.main.views.send import get_example_csv_rows from app import service_api_client, current_service, template_statistics_client @@ -29,6 +29,32 @@ 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=[ + get_template( + template, + current_service, + letter_preview_url=url_for('.view_template', service_id=service_id, template_id=template['id']), + ) + for template in service_api_client.get_service_templates(service_id)['data'] + if should_show_template(template['template_type']) + ], + ) + + @main.route("/services//templates/") @login_required @user_has_permissions( @@ -139,6 +165,25 @@ def view_template_version_as_png(service_id, template_id, version): )) +@main.route("/services//templates/add", methods=['GET', 'POST']) +@login_required +@user_has_permissions('manage_templates', admin_override=True) +def add_template_by_type(service_id): + + form = ChooseTemplateType( + include_letters=current_service['can_send_letters'] + ) + + if form.validate_on_submit(): + return redirect(url_for( + '.add_service_template', + service_id=service_id, + template_type=form.template_type.data, + )) + + return render_template('views/templates/add.html', form=form) + + @main.route("/services//templates/add-", methods=['GET', 'POST']) @login_required @user_has_permissions('manage_templates', admin_override=True) @@ -173,7 +218,7 @@ def add_service_template(service_id, template_type): raise e else: return redirect( - url_for('.choose_template', service_id=service_id, template_type=template_type) + url_for('.choose_template', service_id=service_id) ) return render_template( @@ -362,3 +407,10 @@ def get_human_readable_delta(from_time, until_time): else: days = delta.days return '{} day{}'.format(days, '' if days == 1 else 's') + + +def should_show_template(template_type): + return ( + template_type != 'letter' or + current_service['can_send_letters'] + ) diff --git a/app/templates/main_nav.html b/app/templates/main_nav.html index 08975d1de..2dc588d0e 100644 --- a/app/templates/main_nav.html +++ b/app/templates/main_nav.html @@ -45,11 +45,7 @@
  • Dashboard
  • {% if current_user.has_permissions(['view_activity', 'manage_templates', 'manage_api_keys'], admin_override=True, any_=True) %} -
  • Email templates
  • -
  • Text message templates
  • - {% if current_service.can_send_letters %} -
  • Letter templates
  • - {% endif %} +
  • Templates
  • {% endif %} {% if current_user.has_permissions(['manage_users', 'manage_settings'], admin_override=True) %}
  • Team members
  • diff --git a/app/templates/views/dashboard/write-first-messages.html b/app/templates/views/dashboard/write-first-messages.html index ecf754b33..5cf6ae03d 100644 --- a/app/templates/views/dashboard/write-first-messages.html +++ b/app/templates/views/dashboard/write-first-messages.html @@ -1,10 +1,11 @@

    Get started

    -