Summarise scheduled jobs on the dashboard

Scheduled jobs push everything else on the dashboard down, which makes
them very prominent. This is exacerbated by people scheduling more jobs
simultaneously than we expected when we originally designed the feature.

We also want to remove all jobs from the dashboard, in favour of putting
them on the uploads page.

So this commit replaces them with one of our new dashboard banners (used
for received text messages in returned letters) which summarises:
- how many scheduled jobs you have
- when the first one is going out (i.e. how long you have to stop it, if
  you need to)
This commit is contained in:
Chris Hill-Scott
2020-02-20 11:38:43 +00:00
parent 7157b1cee8
commit f2f531a7e6
4 changed files with 77 additions and 49 deletions

View File

@@ -4,38 +4,24 @@
<div class="ajax-block-container"> <div class="ajax-block-container">
{% if current_service.scheduled_jobs %} {% if current_service.scheduled_jobs %}
<div class='dashboard-table'> <h2 class="heading-medium heading-upcoming-jobs">
{% if not hide_heading %} In the next few days
<h2 class="heading-medium heading-upcoming-jobs"> </h2>
In the next few days <a class="govuk-link govuk-link--no-visited-state banner-dashboard" href="{{ url_for('.uploads', service_id=current_service.id) }}">
</h2> <span class="banner-dashboard-count">
{% endif %} {{ current_service.scheduled_jobs|length }}
{% call(item, row_number) list_table( </span>
current_service.scheduled_jobs, <span class="banner-dashboard-count-label">
caption="In the next few days", {% if current_service.scheduled_jobs|length == 1 %}
caption_visible=False, file waiting to send
empty_message='Nothing to see here', {% else %}
field_headings=[ files waiting to send
'File', {% endif %}
'Messages to be sent' </span>
], <span class="banner-dashboard-meta">
field_headings_visible=True sending starts
) %} {{ current_service.scheduled_jobs[0].scheduled_for|format_datetime_relative }}
{% call row_heading() %} </span>
<div class="file-list"> </a>
<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">
Sending {{ item.scheduled_for|format_datetime_relative }}
</span>
</div>
{% endcall %}
{% call field() %}
{{ big_number(
item.notification_count,
smallest=True
) }}
{% endcall %}
{% endcall %}
</div>
{% endif %} {% endif %}
</div> </div>

View File

@@ -0,0 +1,34 @@
{% from "components/table.html" import list_table, field, right_aligned_field_heading, row_heading %}
{% from "components/big-number.html" import big_number %}
{% from "components/show-more.html" import show_more %}
{% if current_service.scheduled_jobs %}
<div class='dashboard-table'>
{% call(item, row_number) list_table(
current_service.scheduled_jobs,
caption="In the next few days",
caption_visible=False,
empty_message='Nothing to see here',
field_headings=[
'File',
'Messages to be sent'
],
field_headings_visible=True
) %}
{% call row_heading() %}
<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">
Sending {{ item.scheduled_for|format_datetime_relative }}
</span>
</div>
{% endcall %}
{% call field() %}
{{ big_number(
item.notification_count,
smallest=True
) }}
{% endcall %}
{% endcall %}
</div>
{% endif %}

View File

@@ -11,7 +11,7 @@
<div class="dashboard"> <div class="dashboard">
{% if show_scheduled_jobs %} {% if show_scheduled_jobs %}
{% with hide_heading = True %} {% with hide_heading = True %}
{% include 'views/dashboard/_upcoming.html' %} {% include 'views/jobs/_scheduled.html' %}
{% endwith %} {% endwith %}
{% endif %} {% endif %}
{% if jobs %} {% if jobs %}

View File

@@ -227,7 +227,7 @@ def test_inbound_messages_shows_count_of_messages_when_there_are_messages(
'main.service_dashboard', 'main.service_dashboard',
service_id=SERVICE_ONE_ID, service_id=SERVICE_ONE_ID,
) )
banner = page.select_one('a.banner-dashboard') banner = page.select('a.banner-dashboard')[1]
assert normalize_spaces( assert normalize_spaces(
banner.text banner.text
) == '9,999 text messages received latest message just now' ) == '9,999 text messages received latest message just now'
@@ -254,7 +254,7 @@ def test_inbound_messages_shows_count_of_messages_when_there_are_no_messages(
'main.service_dashboard', 'main.service_dashboard',
service_id=SERVICE_ONE_ID, service_id=SERVICE_ONE_ID,
) )
banner = page.select_one('a.banner-dashboard') banner = page.select('a.banner-dashboard')[1]
assert normalize_spaces(banner.text) == '0 text messages received' assert normalize_spaces(banner.text) == '0 text messages received'
assert banner['href'] == url_for( assert banner['href'] == url_for(
'main.inbox', service_id=SERVICE_ONE_ID 'main.inbox', service_id=SERVICE_ONE_ID
@@ -625,7 +625,7 @@ def test_should_show_recent_templates_on_dashboard(
headers = [header.text.strip() for header in page.find_all('h2') + page.find_all('h1')] headers = [header.text.strip() for header in page.find_all('h2') + page.find_all('h1')]
assert 'In the last 7 days' in headers assert 'In the last 7 days' in headers
table_rows = page.find_all('tbody')[1].find_all('tr') table_rows = page.find_all('tbody')[0].find_all('tr')
assert len(table_rows) == 4 assert len(table_rows) == 4
@@ -825,20 +825,26 @@ def test_should_show_upcoming_jobs_on_dashboard(
'main.service_dashboard', 'main.service_dashboard',
service_id=SERVICE_ONE_ID, service_id=SERVICE_ONE_ID,
) )
second_call = mock_get_jobs.call_args_list[1] second_call = mock_get_jobs.call_args_list[1]
assert second_call[0] == (SERVICE_ONE_ID,) assert second_call[0] == (SERVICE_ONE_ID,)
assert second_call[1]['statuses'] == ['scheduled'] assert second_call[1]['statuses'] == ['scheduled']
table_rows = page.find_all('tbody')[0].find_all('tr') assert normalize_spaces(
assert len(table_rows) == 2 page.select_one('main h2').text
) == (
'In the next few days'
)
assert 'send_me_later.csv' in table_rows[0].find_all('th')[0].text assert normalize_spaces(
assert 'Sending today at 11:09am' in table_rows[0].find_all('th')[0].text page.select_one('a.banner-dashboard').text
assert table_rows[0].find_all('td')[0].text.strip() == '1' ) == (
assert 'even_later.csv' in table_rows[1].find_all('th')[0].text '2 files waiting to send '
assert 'Sending today at 11:09pm' in table_rows[1].find_all('th')[0].text 'sending starts today at 11:09am'
assert table_rows[1].find_all('td')[0].text.strip() == '1' )
assert page.select_one('a.banner-dashboard')['href'] == url_for(
'main.uploads', service_id=SERVICE_ONE_ID
)
@pytest.mark.parametrize('permissions', ( @pytest.mark.parametrize('permissions', (
@@ -919,7 +925,7 @@ def test_should_show_recent_jobs_on_dashboard(
assert third_call[1]['limit_days'] == 7 assert third_call[1]['limit_days'] == 7
assert 'scheduled' not in third_call[1]['statuses'] assert 'scheduled' not in third_call[1]['statuses']
table_rows = page.find_all('tbody')[1].find_all('tr') table_rows = page.select_one('tbody').select('tr')
assert len(table_rows) == 4 assert len(table_rows) == 4
@@ -1151,6 +1157,7 @@ def test_menu_send_messages_when_service_does_not_have_upload_letters_permission
mock_get_usage, mock_get_usage,
mock_get_inbound_sms_summary, mock_get_inbound_sms_summary,
mock_get_free_sms_fragment_limit, mock_get_free_sms_fragment_limit,
mock_get_returned_letter_summary_with_no_returned_letters,
): ):
with app_.test_request_context(): with app_.test_request_context():
resp = _test_dashboard_menu( resp = _test_dashboard_menu(
@@ -1159,8 +1166,9 @@ def test_menu_send_messages_when_service_does_not_have_upload_letters_permission
api_user_active, api_user_active,
service_one, service_one,
['view_activity', 'send_messages']) ['view_activity', 'send_messages'])
page = resp.get_data(as_text=True) page = BeautifulSoup(resp.data.decode('utf-8'), 'html.parser')
assert url_for('main.uploads', service_id=service_one['id']) not in page assert page.select_one('.navigation')
assert url_for('main.uploads', service_id=service_one['id']) not in page.select_one('.navigation')
def test_menu_manage_service( def test_menu_manage_service(