mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-04-12 05:10:45 -04:00
editing and creating new preview functions and backlinks
This commit is contained in:
@@ -54,7 +54,7 @@
|
||||
|
||||
.sms-message-recipient {
|
||||
color: color('gray-cool-90');
|
||||
margin: 0 0 units(1);
|
||||
margin: units(1) 0 units(1);
|
||||
}
|
||||
|
||||
.sms-message-status {
|
||||
@@ -131,7 +131,7 @@
|
||||
&-label,
|
||||
&-button-label {
|
||||
font-weight: bold;
|
||||
font-size: 19px;
|
||||
font-size: 19px;
|
||||
display: block;
|
||||
margin: 0 0 10px 0;
|
||||
}
|
||||
|
||||
@@ -527,11 +527,17 @@ def _check_messages(service_id, template_id, upload_id, preview_row):
|
||||
back_link = url_for(
|
||||
"main.send_one_off", service_id=service_id, template_id=template.id
|
||||
)
|
||||
back_link_from_preview = url_for(
|
||||
"main.send_one_off", service_id=service_id, template_id=template.id
|
||||
)
|
||||
choose_time_form = None
|
||||
else:
|
||||
back_link = url_for(
|
||||
"main.send_messages", service_id=service_id, template_id=template.id
|
||||
)
|
||||
back_link_from_preview = url_for(
|
||||
"main.check_messages", service_id=service_id, template_id=template.id, upload_id=upload_id
|
||||
)
|
||||
choose_time_form = ChooseTimeForm()
|
||||
|
||||
if preview_row < 2:
|
||||
@@ -559,6 +565,7 @@ def _check_messages(service_id, template_id, upload_id, preview_row):
|
||||
remaining_messages=remaining_messages,
|
||||
choose_time_form=choose_time_form,
|
||||
back_link=back_link,
|
||||
back_link_from_preview=back_link_from_preview,
|
||||
first_recipient_column=recipients.recipient_column_headers[0],
|
||||
preview_row=preview_row,
|
||||
sent_previously=job_api_client.has_sent_previously(
|
||||
@@ -612,6 +619,34 @@ def check_messages(service_id, template_id, upload_id, row_index=2):
|
||||
return render_template("views/check/ok.html", **data)
|
||||
|
||||
|
||||
@main.route(
|
||||
"/services/<uuid:service_id>/<uuid:template_id>/check/<uuid:upload_id>/preview",
|
||||
methods=["POST"],
|
||||
)
|
||||
@user_has_permissions("send_messages", restrict_admin_usage=True)
|
||||
def preview_job(service_id, template_id, upload_id, row_index=2):
|
||||
session['scheduled_for'] = request.form.get('scheduled_for', 'Not specified')
|
||||
data = _check_messages(service_id, template_id, upload_id, row_index)
|
||||
data["allowed_file_extensions"] = Spreadsheet.ALLOWED_FILE_EXTENSIONS
|
||||
if (
|
||||
data["recipients"].too_many_rows
|
||||
or not data["count_of_recipients"]
|
||||
or not data["recipients"].has_recipient_columns
|
||||
or data["recipients"].duplicate_recipient_column_headers
|
||||
or data["recipients"].missing_column_headers
|
||||
or data["sent_previously"]
|
||||
):
|
||||
return render_template("views/check/column-errors.html", **data)
|
||||
|
||||
if data["row_errors"]:
|
||||
return render_template("views/check/row-errors.html", **data)
|
||||
|
||||
if data["errors"]:
|
||||
return render_template("views/check/column-errors.html", **data)
|
||||
|
||||
return render_template('views/check/preview.html', scheduled_for=session['scheduled_for'], **data,
|
||||
)
|
||||
|
||||
@main.route("/services/<uuid:service_id>/start-job/<uuid:upload_id>", methods=["POST"])
|
||||
@user_has_permissions("send_messages", restrict_admin_usage=True)
|
||||
def start_job(service_id, upload_id):
|
||||
@@ -633,49 +668,6 @@ def start_job(service_id, upload_id):
|
||||
)
|
||||
|
||||
|
||||
@main.route(
|
||||
"/services/<uuid:service_id>/<uuid:template_id>/check/<uuid:upload_id>/preview",
|
||||
methods=["POST"],
|
||||
)
|
||||
@user_has_permissions("send_messages", restrict_admin_usage=True)
|
||||
def preview_job(service_id, template_id, upload_id, row_index=2):
|
||||
# Store form data in session temporarily
|
||||
session['scheduled_for'] = request.form.get('scheduled_for', 'Not specified')
|
||||
# session.pop("sender_id", None)
|
||||
data = _check_messages(service_id, template_id, upload_id, row_index)
|
||||
data["allowed_file_extensions"] = Spreadsheet.ALLOWED_FILE_EXTENSIONS
|
||||
|
||||
if (
|
||||
data["recipients"].too_many_rows
|
||||
or not data["count_of_recipients"]
|
||||
or not data["recipients"].has_recipient_columns
|
||||
or data["recipients"].duplicate_recipient_column_headers
|
||||
or data["recipients"].missing_column_headers
|
||||
or data["sent_previously"]
|
||||
):
|
||||
return render_template("views/check/column-errors.html", **data)
|
||||
|
||||
if data["row_errors"]:
|
||||
return render_template("views/check/row-errors.html", **data)
|
||||
|
||||
if data["errors"]:
|
||||
return render_template("views/check/column-errors.html", **data)
|
||||
|
||||
metadata_kwargs = {
|
||||
"notification_count": data["count_of_recipients"],
|
||||
"template_id": template_id,
|
||||
"valid": True,
|
||||
"original_file_name": data.get("original_file_name", ""),
|
||||
}
|
||||
|
||||
if session.get("sender_id"):
|
||||
metadata_kwargs["sender_id"] = session["sender_id"]
|
||||
|
||||
set_metadata_on_csv_upload(service_id, upload_id, **metadata_kwargs)
|
||||
|
||||
return render_template('views/check/preview.html', data=session['scheduled_for'], **data, metadata_kwargs=metadata_kwargs)
|
||||
|
||||
|
||||
def fields_to_fill_in(template, prefill_current_user=False):
|
||||
if not prefill_current_user:
|
||||
return first_column_headings[template.template_type] + list(
|
||||
@@ -721,7 +713,15 @@ def get_send_test_page_title(template_type, entering_recipient, name=None):
|
||||
return "Personalize this message"
|
||||
|
||||
|
||||
def get_back_link(service_id, template, step_index, placeholders=None):
|
||||
def get_back_link(service_id, template, step_index, placeholders=None, preview=False,):
|
||||
if preview:
|
||||
return url_for(
|
||||
"main.check_notification",
|
||||
service_id=service_id,
|
||||
template_id=template.id,
|
||||
)
|
||||
|
||||
|
||||
if step_index == 0:
|
||||
if should_skip_template_page(template._template):
|
||||
return url_for(
|
||||
@@ -826,6 +826,8 @@ def _check_notification(service_id, template_id, exception=None):
|
||||
|
||||
back_link = get_back_link(service_id, template, len(placeholders), placeholders)
|
||||
|
||||
back_link_from_preview = get_back_link(service_id, template, len(placeholders), placeholders, preview=True)
|
||||
|
||||
choose_time_form = ChooseTimeForm()
|
||||
|
||||
if (not session.get("recipient")) or not all_placeholders_in_session(
|
||||
@@ -839,6 +841,7 @@ def _check_notification(service_id, template_id, exception=None):
|
||||
return dict(
|
||||
template=template,
|
||||
back_link=back_link,
|
||||
back_link_from_preview=back_link_from_preview,
|
||||
choose_time_form=choose_time_form,
|
||||
**(get_template_error_dict(exception) if exception else {}),
|
||||
)
|
||||
@@ -869,6 +872,29 @@ def get_template_error_dict(exception):
|
||||
"original_file_name": False,
|
||||
}
|
||||
|
||||
@main.route(
|
||||
"/services/<uuid:service_id>/template/<uuid:template_id>/notification/check/preview",
|
||||
methods=["POST"],
|
||||
)
|
||||
@user_has_permissions("send_messages", restrict_admin_usage=True)
|
||||
def preview_notification(service_id, template_id):
|
||||
recipient = get_recipient()
|
||||
if not recipient:
|
||||
return redirect(
|
||||
url_for(
|
||||
".send_one_off",
|
||||
service_id=service_id,
|
||||
template_id=template_id,
|
||||
)
|
||||
)
|
||||
|
||||
session['scheduled_for'] = request.form.get('scheduled_for', 'Not specified')
|
||||
|
||||
return render_template(
|
||||
"views/notifications/preview.html",
|
||||
**_check_notification(service_id, template_id), data=session['scheduled_for']
|
||||
)
|
||||
|
||||
|
||||
@main.route(
|
||||
"/services/<uuid:service_id>/template/<uuid:template_id>/notification/check",
|
||||
@@ -876,6 +902,7 @@ def get_template_error_dict(exception):
|
||||
)
|
||||
@user_has_permissions("send_messages", restrict_admin_usage=True)
|
||||
def send_notification(service_id, template_id):
|
||||
scheduled_for = session.pop('scheduled_for', None)
|
||||
recipient = get_recipient()
|
||||
if not recipient:
|
||||
return redirect(
|
||||
@@ -910,7 +937,7 @@ def send_notification(service_id, template_id):
|
||||
job_api_client.create_job(
|
||||
upload_id,
|
||||
service_id,
|
||||
scheduled_for=request.form.get("scheduled_for", ""),
|
||||
scheduled_for=scheduled_for,
|
||||
template_id=template_id,
|
||||
original_file_name=filename,
|
||||
notification_count=1,
|
||||
|
||||
@@ -41,50 +41,11 @@
|
||||
<h3 id="{{ file_contents_header_id }}">{{ original_file_name }}</h3>
|
||||
{% endif %}
|
||||
{% set button_text %}
|
||||
Preview send
|
||||
<!-- {{ count_of_recipients|message_count(template.template_type) }} -->
|
||||
Preview
|
||||
{% endset %}
|
||||
{{ usaButton({ "text": button_text }) }}
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- <div class="fullscreen-content" data-module="fullscreen-table">
|
||||
{% call(item, row_number) list_table(
|
||||
recipients.displayed_rows,
|
||||
caption=original_file_name,
|
||||
caption_visible=False,
|
||||
field_headings=[
|
||||
'<span class="usa-sr-only">Row in file</span><span aria-hidden="true">1</span>'|safe
|
||||
] + recipients.column_headers
|
||||
) %}
|
||||
{% call index_field() %}
|
||||
<span>
|
||||
{% if (item.index + 2) == preview_row %}
|
||||
{{ item.index + 2 }}
|
||||
{% else %}
|
||||
<a class="usa-link" href="{{ url_for('.check_messages', service_id=current_service.id, template_id=template.id, upload_id=upload_id, row_index=(item.index + 2), original_file_name=original_file_name) }}">{{ item.index + 2 }}</a>
|
||||
{% endif %}
|
||||
</span>
|
||||
{% endcall %}
|
||||
{% for column in recipients.column_headers %}
|
||||
{% if item[column].ignore %}
|
||||
{{ text_field(item[column].data or '', status='default') }}
|
||||
{% else %}
|
||||
{{ text_field(item[column].data or '') }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if item[None].data %}
|
||||
{% for column in item[None].data %}
|
||||
{{ text_field(column, status='default') }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endcall %}
|
||||
</div> -->
|
||||
|
||||
<!-- {% if count_of_displayed_recipients < count_of_recipients %}
|
||||
<p class="table-show-more-link">
|
||||
Only showing the first {{ count_of_displayed_recipients }} rows
|
||||
</p>
|
||||
{% endif %} -->
|
||||
{% endblock %}
|
||||
|
||||
@@ -14,35 +14,23 @@
|
||||
|
||||
|
||||
{% block backLink %}
|
||||
{{ usaBackLink({ "href": back_link }) }}
|
||||
{{ usaBackLink({ "href": back_link_from_preview }) }}
|
||||
{% endblock %}
|
||||
|
||||
{% block maincolumn_content %}
|
||||
|
||||
{{ page_header('Send messages') }}
|
||||
{{ page_header('Preview') }}
|
||||
<h2 id="{{ file_contents_header_id }}">Message</h2>
|
||||
{% if data %}
|
||||
<p>Time: {{data | format_datetime_short_america}}</p>
|
||||
{% if scheduled_for %}
|
||||
<p class="sms-message-sender">Time: {{scheduled_for}}</p>
|
||||
{% endif %}
|
||||
<p class="sms-message-sender">File: {{metadata_kwargs.original_file_name}}</p>
|
||||
<p class="sms-message-sender">File: {{original_file_name}}</p>
|
||||
{{ template|string }}
|
||||
<div class="bottom-gutter-3-2">
|
||||
<form method="post" enctype="multipart/form-data" action="{{url_for('main.start_job', service_id=current_service.id, upload_id=upload_id)}}" class='page-footer'>
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
|
||||
<!-- {% if choose_time_form %}
|
||||
{{ choose_time_form.scheduled_for(param_extensions={
|
||||
'formGroup': {'classes': 'bottom-gutter-2-3'},
|
||||
'attributes': {
|
||||
'data-module': 'radio-select',
|
||||
'data-categories': choose_time_form.scheduled_for.categories|join(','),
|
||||
'data-show-now-as-default': 'true'
|
||||
}
|
||||
}) }}
|
||||
{% endif %} -->
|
||||
{% if not request.args.from_test %}
|
||||
|
||||
<h2 class="font-body-lg">Preview list</h2>
|
||||
|
||||
<ul class="usa-icon-list">
|
||||
<li class="usa-icon-list__item">
|
||||
<div class="usa-icon-list__icon" >
|
||||
@@ -53,8 +41,6 @@
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
<div>
|
||||
{% call(item, row_number) list_table(
|
||||
recipients.displayed_rows,
|
||||
@@ -76,25 +62,15 @@
|
||||
{% endif %}
|
||||
{% endcall %}
|
||||
</div>
|
||||
|
||||
{% endif %}
|
||||
<p>The service be charged 10 message parts for a total of 20 messages when this batch it sent
|
||||
There are 480 of 500 messages remaining in your service</p>
|
||||
<!-- <p>The service be charged 10 message parts for a total of 20 messages when this batch it sent
|
||||
There are 480 of 500 messages remaining in your service</p> -->
|
||||
<h3>Does everything look good?</h3>
|
||||
{% set button_text %}
|
||||
Send
|
||||
<!-- {{ count_of_recipients|message_count(template.template_type) }} -->
|
||||
{% endset %}
|
||||
{{ usaButton({ "text": button_text }) }}
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- {% if count_of_displayed_recipients < count_of_recipients %}
|
||||
<p class="table-show-more-link">
|
||||
Only showing the first {{ count_of_displayed_recipients }} rows
|
||||
</p>
|
||||
{% endif %} -->
|
||||
{% endblock %}
|
||||
|
||||
@@ -40,17 +40,16 @@
|
||||
{% endcall %}
|
||||
</div>
|
||||
{% else %}
|
||||
{{ page_header('Preview of ‘{}’'.format(template.name)) }}
|
||||
{{ page_header('Select delivery time') }}
|
||||
{% endif %}
|
||||
|
||||
{{ template|string }}
|
||||
|
||||
<div class="js-stick-at-bottom-when-scrolling">
|
||||
<form method="post" enctype="multipart/form-data" action="{{url_for(
|
||||
'main.send_notification',
|
||||
'main.preview_notification',
|
||||
service_id=current_service.id,
|
||||
template_id=template.id,
|
||||
help='3' if help else 0
|
||||
template_id=template.id
|
||||
)}}" class='page-footer'>
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
|
||||
{% if not error %}
|
||||
@@ -64,7 +63,9 @@
|
||||
}
|
||||
}) }}
|
||||
{% endif %}
|
||||
{% set button_text %}Send 1 {{ 1|message_count_label(template.template_type, suffix='') }}{% endset %}
|
||||
{% set button_text %}
|
||||
Preview
|
||||
{% endset %}
|
||||
{{ usaButton({ "text": button_text }) }}
|
||||
{% endif %}
|
||||
</form>
|
||||
|
||||
65
app/templates/views/notifications/preview.html
Normal file
65
app/templates/views/notifications/preview.html
Normal file
@@ -0,0 +1,65 @@
|
||||
{% extends "withnav_template.html" %}
|
||||
{% from "components/banner.html" import banner_wrapper %}
|
||||
{% from "components/page-header.html" import page_header %}
|
||||
{% from "components/components/back-link/macro.njk" import usaBackLink %}
|
||||
{% from "components/components/button/macro.njk" import usaButton %}
|
||||
|
||||
{% block service_page_title %}
|
||||
{{ "Error" if error else "Preview of ‘{}’".format(template.name) }}
|
||||
{% endblock %}
|
||||
|
||||
{% block backLink %}
|
||||
{{ usaBackLink({ "href": back_link_from_preview }) }}
|
||||
{% endblock %}
|
||||
|
||||
{% block maincolumn_content %}
|
||||
{% if error == 'not-allowed-to-send-to' %}
|
||||
<div class="bottom-gutter">
|
||||
{% call banner_wrapper(type='dangerous') %}
|
||||
{% with
|
||||
count_of_recipients=1,
|
||||
template_type_label=(
|
||||
'phone number' if template.template_type == 'sms' else 'email address'
|
||||
)
|
||||
%}
|
||||
{% include "partials/check/not-allowed-to-send-to.html" %}
|
||||
{% endwith %}
|
||||
{% endcall %}
|
||||
</div>
|
||||
{% elif error == 'too-many-messages' %}
|
||||
<div class="bottom-gutter">
|
||||
{% call banner_wrapper(type='dangerous') %}
|
||||
{% include "partials/check/too-many-messages.html" %}
|
||||
{% endcall %}
|
||||
</div>
|
||||
{% elif error == 'message-too-long' %}
|
||||
{# the only row_errors we can get when sending one off messages is that the message is too long #}
|
||||
<div class="bottom-gutter">
|
||||
{% call banner_wrapper(type='dangerous') %}
|
||||
{% include "partials/check/message-too-long.html" %}
|
||||
{% endcall %}
|
||||
</div>
|
||||
{% else %}
|
||||
{{ page_header('Preview of ‘{}’'.format(template.name)) }}
|
||||
{% endif %}
|
||||
|
||||
{{ template|string }}
|
||||
|
||||
<div class="js-stick-at-bottom-when-scrolling">
|
||||
<form method="post" enctype="multipart/form-data" action="{{url_for(
|
||||
'main.send_notification',
|
||||
service_id=current_service.id,
|
||||
template_id=template.id,
|
||||
help='3' if help else 0
|
||||
)}}" class='page-footer'>
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
|
||||
{% if not error %}
|
||||
{% set button_text %}
|
||||
Send
|
||||
{% endset %}
|
||||
{{ usaButton({ "text": button_text }) }}
|
||||
{% endif %}
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user