Put uploaded files on the dashboard

This commit depends on and uses the data returned by:
- [x] https://github.com/alphagov/notifications-api/pull/345
- [x] https://github.com/alphagov/notifications-api/pull/347
- [x] https://github.com/alphagov/notifications-admin/pull/612

It puts the last 5 jobs on the dashboard. This should be changed to all the jobs
from the last 7 days when that parameter is available.

It also:
- links to the jobs page
- makes the numbers on the jobs page consistent with the dashboard
- makes the numbers on an individual job consistent with the appearance of the
  dashboard
This commit is contained in:
Chris Hill-Scott
2016-05-25 13:36:35 +01:00
parent fe38a46798
commit 16d83faa72
14 changed files with 130 additions and 107 deletions

View File

@@ -202,7 +202,7 @@ def format_datetime_normal(date):
def format_datetime_short(date):
return gmt_timezones(date).strftime('%d %B at %H:%M')
return gmt_timezones(date).strftime('%d %B at %H:%M').lstrip('0')
def format_time(date):

View File

@@ -1,6 +1,16 @@
.dashboard {
table th {
font-size: 0;
table {
th {
@include core-16;
padding-top: 0;
border: 0;
}
td {
@include core-19;
border: 0;
}
}
}
@@ -15,12 +25,9 @@
box-sizing: border-box;
display: block;
width: 100%;
text-align: right;
margin-bottom: $gutter-half;
height: $gutter-half;
color: $govuk-blue;
text-align: left;
color: $govuk-blue;
span {
box-sizing: border-box;
@@ -47,3 +54,17 @@
}
}
.file-list {
&-filename {
@include bold-19;
}
&-hint {
@include core-16;
display: block;
color: $secondary-text-colour;
}
}

View File

@@ -16,6 +16,7 @@ from flask_login import login_required
from app.main import main
from app import (
job_api_client,
statistics_api_client,
service_api_client,
template_statistics_client
@@ -217,4 +218,5 @@ def get_dashboard_statistics_for_service(service_id):
'sms_allowance_remaining': max(0, (sms_free_allowance - sms_sent)),
'sms_chargeable': max(0, sms_sent - sms_free_allowance),
'sms_rate': sms_rate,
'jobs': job_api_client.get_job(service_id, limit_days=7)['data']
}

View File

@@ -90,12 +90,13 @@ def view_job(service_id, job_id):
return render_template(
'views/jobs/job.html',
notifications=notifications['notifications'],
counts={
'queued': 0 if finished else job['notification_count'],
'sent': job['notification_count'] if finished else 0
},
job=job,
uploaded_at=job['created_at'],
finished_at=job['updated_at'] if finished else None,
finished=job.get('notifications_sent', 0) and ((
job.get('notifications_sent', 0) -
job.get('notifications_delivered', 0) -
job.get('notifications_failed', 0)
) == 0),
uploaded_file_name=job['original_file_name'],
first_email_template=[
template for template in service_api_client.get_service_templates(service_id)['data']
@@ -104,9 +105,7 @@ def view_job(service_id, job_id):
template=Template(
template,
prefix=current_service['name']
),
job_id=job_id,
created_by=job['created_by']['name']
)
)
@@ -116,24 +115,27 @@ def view_job(service_id, job_id):
def view_job_updates(service_id, job_id):
job = job_api_client.get_job(service_id, job_id)['data']
notifications = notification_api_client.get_notifications_for_service(service_id, job_id)
finished = job['status'] == 'finished'
finished = (
job.get('notifications_sent', 0) -
job.get('notifications_delivered', 0) -
job.get('notifications_failed', 0)
) == 0
return jsonify(**{
'counts': render_template(
'partials/jobs/count.html',
counts={
'queued': 0 if finished else job['notification_count'],
'sent': job['notification_count'] if finished else 0
}
job=job,
finished=finished
),
'notifications': render_template(
'partials/jobs/notifications.html',
notifications=notifications['notifications']
job=job,
notifications=notifications['notifications'],
finished=finished
),
'status': render_template(
'partials/jobs/status.html',
uploaded_at=job['created_at'],
finished_at=job['updated_at'] if finished else None,
created_by=job['created_by']['name']
job=job,
finished=finished
),
})

View File

@@ -14,7 +14,7 @@
{% if label_link %}
<a class="big-number-label" href="{{ label_link }}">{{ label }}</a>
<a class="big-number-overlay-link" href="{{ label_link }}" aria-hidden="true"></a>
{% else %}
{% elif label %}
<span class="big-number-label">{{ label }}</span>
{% endif %}
</div>

View File

@@ -1,9 +1,9 @@
{% from "components/big-number.html" import big_number %}
<div
{% if not finished_at %}
{% if not finished %}
data-module="update-content"
data-resource="{{url_for(".view_job_updates", service_id=current_service.id, job_id=job_id)}}"
data-resource="{{url_for(".view_job_updates", service_id=current_service.id, job_id=job.id)}}"
data-key="counts"
aria-live="polite"
{% endif %}
@@ -12,12 +12,17 @@
<ul class="grid-row job-totals">
<li class="column-one-quarter">
{{ big_number(
counts.queued, 'queued'
job.get('notifications_sent', 0) - job.get('notifications_delivered', 0) - job.get('notifications_failed', 0), 'sending'
)}}
</li>
<li class="column-one-quarter">
{{ big_number(
counts.sent, 'processed'
job.get('notifications_delivered', 0), 'delivered'
)}}
</li>
<li class="column-one-quarter">
{{ big_number(
job.notifications_failed, 'failed'
)}}
</li>
</ul>

View File

@@ -1,9 +1,9 @@
{% from "components/table.html" import list_table, field, right_aligned_field_heading %}
<div
{% if not finished_at %}
{% if not finished %}
data-module="update-content"
data-resource="{{url_for(".view_job_updates", service_id=current_service.id, job_id=job_id)}}"
data-resource="{{url_for(".view_job_updates", service_id=current_service.id, job_id=job.id)}}"
data-key="notifications"
aria-live="polite"
{% endif %}

View File

@@ -1,12 +1,12 @@
<div
{% if not finished_at %}
{% if not finished %}
data-module="update-content"
data-resource="{{url_for(".view_job_updates", service_id=current_service.id, job_id=job_id)}}"
data-resource="{{url_for(".view_job_updates", service_id=current_service.id, job_id=job.id)}}"
data-key="status"
aria-live="polite"
{% endif %}
>
<p class='heading-small'>
Sent by {{ created_by }} on {{ uploaded_at|format_datetime_short }}
Uploaded by {{ job.created_by.name }} on {{ job.created_at|format_datetime_short }}
</p>
</div>

View File

@@ -0,0 +1,35 @@
{% from "components/table.html" import list_table, field, right_aligned_field_heading %}
{% from "components/big-number.html" import big_number %}
{% call(item, row_number) list_table(
jobs,
caption="Recent batch jobs",
caption_visible=False,
empty_message='You havent sent any batch messages yet',
field_headings=[
'File',
right_aligned_field_heading('Sending'),
right_aligned_field_heading('Delivered'),
right_aligned_field_heading('Failed')
],
field_headings_visible=True
) %}
{% call field() %}
<div class="file-list">
<a class="file-list-filename" href="{{ url_for('.view_job', service_id=current_service.id, job_id=item.id) }}">{{ item.original_file_name }}</a>
<span class="file-list-hint">Uploaded {{ item.created_at|format_datetime_short }}</span>
</div
{% endcall %}
{% call field(align='right') %}
{{ big_number(
item.get('notifications_sent', 0) - item.get('notifications_delivered', 0) - item.get('notifications_failed', 0),
smaller=True
) }}
{% endcall %}
{% call field(align='right') %}
{{ big_number(item.get('notifications_delivered', 0), smaller=True) }}
{% endcall %}
{% call field(align='right', status='error' if 0 else '') %}
{{ big_number(item.get('notifications_failed', 0), smaller=True) }}
{% endcall %}
{% endcall %}

View File

@@ -8,9 +8,10 @@
) %}
{% call field() %}
<a href="{{ url_for('.view_job', service_id=current_service.id, job_id=item.id) }}">{{ item.original_file_name }}</a>
{{ item.created_at|format_datetime }}
{% endcall %}
{% call field() %}
{{ item.created_at|format_datetime }}
{% endcall %}
{% call field(align='right') %}
{{ item.notification_count }}

View File

@@ -1,6 +1,7 @@
{% from "components/big-number.html" import big_number, big_number_with_status %}
{% from "components/show-more.html" import show_more %}
{% from "components/message-count-label.html" import message_count_label %}
{% from "components/table.html" import list_table, field, right_aligned_field_heading, hidden_field_heading %}
<div
data-module="update-content"
@@ -39,7 +40,7 @@
) }}
</div>
</div>
{% if template_statistics|length %}
{% include 'views/dashboard/template-statistics.html' %}
{{ show_more(
@@ -48,8 +49,16 @@
) }}
{% endif %}
{% if jobs %}
{% include 'views/dashboard/_jobs.html' %}
{{ show_more(
url_for('.view_jobs', service_id=current_service.id),
'See all uploaded files'
) }}
{% endif %}
{% if current_user.has_permissions(['manage_settings'], admin_override=True) %}
<h2 class='heading-medium'>This year</h2>
<h2 class='heading-medium'>This year</h2>
<div class='grid-row'>
<div class='column-half'>

View File

@@ -1,44 +1,12 @@
{% extends "withnav_template.html" %}
{% from "components/table.html" import list_table, field, right_aligned_field_heading %}
{% block page_title %}
Notifications activity GOV.UK Notify
{% endblock %}
{% block maincolumn_content %}
<h1 class="heading-large">Notifications activity</h1>
<p>
<a href="{{ url_for(".view_notifications", service_id=current_service.id, job_id=job_id, page=1) }}">All messages</a>
</p>
<p>
<a href="{{ url_for(".view_notifications", service_id=current_service.id, job_id=job_id, type="sms", page=1) }}">Text messages</a>&emsp;
<a href="{{ url_for(".view_notifications", service_id=current_service.id, job_id=job_id, type="email", page=1) }}">Email messages</a>
</p>
<p>
<a href="{{ url_for(".view_notifications", service_id=current_service.id, job_id=job_id, status=['sent', 'delivered'], page=1) }}">Successful messages</a>&emsp;
<a href="{{ url_for(".view_notifications", service_id=current_service.id, job_id=job_id, status=['failed', 'complaint', 'bounce'], page=1) }}">Failed messages</a>
</p>
{% call(item, row_number) list_table(
jobs,
caption="Recent activity",
caption_visible=False,
empty_message='You havent sent any notifications yet',
field_headings=['Job', 'Time', 'Uploaded by', right_aligned_field_heading('Status')]
) %}
{% call field() %}
<a href="{{ url_for('.view_job', service_id=current_service.id, job_id=item.id) }}">{{ item.original_file_name }}</a>
{% endcall %}
{% call field() %}
{{ item.created_at | format_datetime}}
{% endcall %}
{% call field() %}
{{ item.created_by.name }}
{% endcall %}
{% call field(align='right') %}
{{ item.status }}
{% endcall %}
{% endcall %}
<h1 class="heading-large">Uploaded files</h1>
<div class="dashboard">
{% include 'views/dashboard/_jobs.html' %}
</div>
{% endblock %}