Merge pull request #434 from alphagov/single-template-view

Add view for a single template
This commit is contained in:
Chris Hill-Scott
2016-04-13 16:07:24 +01:00
9 changed files with 138 additions and 81 deletions

View File

@@ -47,10 +47,10 @@
z-index: 50;
}
%sms-message-use-links,
.sms-message-use-links {
@include copy-19;
margin-top: 52px;
a {
display: block;
@@ -65,6 +65,11 @@
}
.sms-message-use-links-with-title {
@extend %sms-message-use-links;
margin-top: 52px;
}
.sms-message-from {
@include bold-19;
display: block;

View File

@@ -79,7 +79,7 @@ def choose_template(service_id, template_type):
abort(404)
return render_template(
'views/choose-template.html',
'views/templates/choose.html',
templates=[
Template(
template,

View File

@@ -1,10 +1,12 @@
from flask import request, render_template, redirect, url_for, flash, abort
from flask_login import login_required
from utils.template import Template
from app.main import main
from app.utils import user_has_permissions
from app.main.forms import SMSTemplateForm, EmailTemplateForm
from app import service_api_client
from app import service_api_client, current_service
form_objects = {
@@ -18,6 +20,26 @@ page_headings = {
}
@main.route("/services/<service_id>/templates/<template_id>", methods=['GET'])
@login_required
@user_has_permissions(
'view_activity',
'send_texts',
'send_emails',
'manage_templates',
'manage_api_keys',
admin_override=True, any_=True
)
def view_template(service_id, template_id):
return render_template(
'views/templates/template.html',
template=Template(
service_api_client.get_service_template(service_id, template_id)['data'],
prefix=current_service['name']
)
)
@main.route("/services/<service_id>/templates/add-<template_type>", methods=['GET', 'POST'])
@login_required
@user_has_permissions('manage_templates', admin_override=True)
@@ -48,7 +70,7 @@ def add_service_template(service_id, template_type):
)
@main.route("/services/<service_id>/templates/<template_id>", methods=['GET', 'POST'])
@main.route("/services/<service_id>/templates/<template_id>/edit", methods=['GET', 'POST'])
@login_required
@user_has_permissions('manage_templates', admin_override=True)
def edit_service_template(service_id, template_id):

View File

@@ -1,75 +0,0 @@
{% extends "withnav_template.html" %}
{% from "components/email-message.html" import email_message %}
{% from "components/sms-message.html" import sms_message %}
{% from "components/page-footer.html" import page_footer %}
{% from "components/textbox.html" import textbox %}
{% block page_title %}
{{ page_heading }} GOV.UK Notify
{% endblock %}
{% block maincolumn_content %}
{% if not templates %}
<h1 class="heading-large">{{ page_heading }}</h1>
{% if current_user.has_permissions(permissions=['manage_templates'], any_=True) %}
<p class="bottom-gutter">
There are no
{{ 'email' if 'email' == template_type else 'text message' }}
templates
</p>
<a href="{{ url_for('.add_service_template', service_id=current_service.id, template_type=template_type) }}" class="button">Add a new template</a>
{% else %}
<p>You need to ask your service manager to add templates before you can send messages</p>
{% endif %}
{% else %}
<div class="grid-row">
<div class="column-two-thirds">
<h1 class="heading-large">{{ page_heading }}</h1>
</div>
{% if current_user.has_permissions(permissions=['manage_templates'], admin_override=True) %}
<div class="column-one-third">
<a href="{{ url_for('.add_service_template', service_id=current_service.id, template_type=template_type) }}" class="button align-with-heading">Add new template</a>
</div>
{% endif %}
</div>
<div class="grid-row">
{% for template in templates %}
<div class="column-two-thirds">
{% if 'email' == template_type %}
{{ email_message(
None,
template.formatted_as_markup,
name=template.name,
) }}
{% elif 'sms' == template_type %}
{{ sms_message(
template.formatted_as_markup,
name=template.name
) }}
{% endif %}
</div>
<div class="column-one-third">
<div class="sms-message-use-links">
{% if current_user.has_permissions(permissions=['send_texts', 'send_emails', 'send_letters']) %}
<a href="{{ url_for(".send_messages", service_id=current_service.id, template_id=template.id) }}">Send from a CSV file</a>
<a href="{{ url_for(".send_message_to_self", service_id=current_service.id, template_id=template.id) }}">Send yourself a test</a>
{% endif %}
{% if current_user.has_permissions(permissions=['manage_api_keys']) %}
<a href="{{ url_for(".send_from_api", service_id=current_service.id, template_id=template.id) }}">API integration</a>
{% endif %}
{% if current_user.has_permissions(permissions=['manage_templates'], admin_override=True) %}
<a href="{{ url_for(".edit_service_template", service_id=current_service.id, template_id=template.id) }}">Edit template</a>
{% endif %}
</div>
</div>
{% endfor %}
</div>
{% endif %}
{% endblock %}

View File

@@ -6,7 +6,7 @@
field_headings=['Template', hidden_field_heading('Type'), right_aligned_field_heading('Messages sent')]
) %}
{% call field() %}
<a href="{{ url_for('.edit_service_template', service_id=current_service.id, template_id=item.template.id) }}">
<a href="{{ url_for('.view_template', service_id=current_service.id, template_id=item.template.id) }}">
{{ item.template.name }}
</a>
{% endcall %}

View File

@@ -20,6 +20,7 @@
<a href="{{ url_for(".view_notifications", service_id=current_service.id, status=['delivered'], page=1) }}">Successful messages</a>&emsp;
<a href="{{ url_for(".view_notifications", service_id=current_service.id, status=['failed'], page=1) }}">Failed messages</a>
</p>
{% call(item, row_number) list_table(
notifications,
caption="Recent activity",
@@ -31,7 +32,7 @@
{{ item.to }}
{% endcall %}
{% call field() %}
<a href="{{ url_for(".choose_template", service_id=current_service.id, template_type=item.template.template_type, _anchor=item.template.name|linkable_name) }}">{{ item.template.name }}</a>
<a href="{{ url_for('.view_template', service_id=current_service.id, template_id=item.template.id) }}">{{ item.template.name }}</a>
{% endcall %}
{% call field() %}
{{ item.template.template_type }}

View File

@@ -0,0 +1,31 @@
{% from "components/email-message.html" import email_message %}
{% from "components/sms-message.html" import sms_message %}
<div class="column-two-thirds">
{% if 'email' == template.template_type %}
{{ email_message(
None,
template.formatted_as_markup,
name=template.name if show_title else None
) }}
{% elif 'sms' == template.template_type %}
{{ sms_message(
template.formatted_as_markup,
name=template.name if show_title else None
) }}
{% endif %}
</div>
<div class="column-one-third">
<div class="sms-message-use-links{% if show_title %}-with-title{% endif %}">
{% if current_user.has_permissions(permissions=['send_texts', 'send_emails', 'send_letters']) %}
<a href="{{ url_for(".send_messages", service_id=current_service.id, template_id=template.id) }}">Send from a CSV file</a>
<a href="{{ url_for(".send_message_to_self", service_id=current_service.id, template_id=template.id) }}">Send yourself a test</a>
{% endif %}
{% if current_user.has_permissions(permissions=['manage_api_keys']) %}
<a href="{{ url_for(".send_from_api", service_id=current_service.id, template_id=template.id) }}">API integration</a>
{% endif %}
{% if current_user.has_permissions(permissions=['manage_templates'], admin_override=True) %}
<a href="{{ url_for(".edit_service_template", service_id=current_service.id, template_id=template.id) }}">Edit template</a>
{% endif %}
</div>
</div>

View File

@@ -0,0 +1,45 @@
{% extends "withnav_template.html" %}
{% block page_title %}
{{ page_heading }} GOV.UK Notify
{% endblock %}
{% block maincolumn_content %}
{% if not templates %}
<h1 class="heading-large">{{ page_heading }}</h1>
{% if current_user.has_permissions(permissions=['manage_templates'], any_=True) %}
<p class="bottom-gutter">
You need a template before you can send
{{ 'emails' if 'email' == template_type else 'text messages' }}
</p>
<a href="{{ url_for('.add_service_template', service_id=current_service.id, template_type=template_type) }}" class="button">Add a new template</a>
{% else %}
<p>You need to ask your service manager to add templates before you can send messages</p>
{% endif %}
{% else %}
<div class="grid-row">
<div class="column-two-thirds">
<h1 class="heading-large">{{ page_heading }}</h1>
</div>
{% if current_user.has_permissions(permissions=['manage_templates'], admin_override=True) %}
<div class="column-one-third">
<a href="{{ url_for('.add_service_template', service_id=current_service.id, template_type=template_type) }}" class="button align-with-heading">Add new template</a>
</div>
{% endif %}
</div>
<div class="grid-row">
{% for template in templates %}
{% with show_title=True %}
{% include 'views/templates/_template.html' %}
{% endwith %}
{% endfor %}
</div>
{% endif %}
{% endblock %}

View File

@@ -0,0 +1,28 @@
{% extends "withnav_template.html" %}
{% from "components/email-message.html" import email_message %}
{% from "components/sms-message.html" import sms_message %}
{% from "components/page-footer.html" import page_footer %}
{% from "components/textbox.html" import textbox %}
{% block page_title %}
{{ template.name }} GOV.UK Notify
{% endblock %}
{% block maincolumn_content %}
<h1 class="heading-large">{{ template.name }}</h1>
<div class="grid-row">
{% include 'views/templates/_template.html' %}
</div>
<p>
<a href="{{ url_for('.choose_template', service_id=current_service.id, template_type=template.template_type) }}">
All
{{ 'email' if 'email' == template.template_type else 'text message' }}
templates
</a>
</p>
{% endblock %}