Refactor to make it logic clearer

The logic around what gets shown on the uploads page was hard to follow.
This commit makes three changes to hopefully make it easier:
- remove the passing-around of a string containing the contents of a
  rendered partial
- encapsulate everything in one `show_scheduled_jobs` variable, rather
  than mixing between `scheduled_jobs` and
  `current_service.scheduled_jobs`
- adds a comment to explain why we still render `_jobs.html` even when
  we know we have no jobs
This commit is contained in:
Chris Hill-Scott
2020-02-24 10:59:57 +00:00
parent c20ec82cd2
commit 3dab9c2915
3 changed files with 21 additions and 18 deletions

View File

@@ -51,19 +51,16 @@ def view_jobs(service_id):
if jobs.next_page:
next_page = generate_next_dict('main.view_jobs', service_id, jobs.current_page)
scheduled_jobs = ''
if not current_user.has_permissions('view_activity') and jobs.current_page == 1:
scheduled_jobs = render_template(
'views/dashboard/_upcoming.html',
hide_heading=True,
)
return render_template(
'views/jobs/jobs.html',
jobs=jobs,
prev_page=prev_page,
next_page=next_page,
scheduled_jobs=scheduled_jobs,
show_scheduled_jobs=(
jobs.current_page == 1
and not current_user.has_permissions('view_activity')
and current_service.scheduled_jobs
),
)

View File

@@ -52,19 +52,14 @@ def uploads(service_id):
if uploads.prev_page:
next_page = generate_next_dict('main.uploads', service_id, uploads.current_page)
scheduled_jobs = ''
if uploads.current_page == 1:
scheduled_jobs = render_template(
'views/dashboard/_upcoming.html',
hide_heading=True,
)
return render_template(
'views/jobs/jobs.html',
jobs=uploads,
prev_page=prev_page,
next_page=next_page,
scheduled_jobs=scheduled_jobs,
show_scheduled_jobs=(
uploads.current_page == 1 and current_service.scheduled_jobs
),
)

View File

@@ -9,8 +9,19 @@
{% block maincolumn_content %}
<h1 class="heading-large">Uploads</h1>
<div class="dashboard">
{{ scheduled_jobs|safe }}
{% if jobs or not current_service.scheduled_jobs %}
{% if show_scheduled_jobs %}
{% with hide_heading = True %}
{% include 'views/dashboard/_upcoming.html' %}
{% endwith %}
{% endif %}
{% if jobs %}
{% include 'views/dashboard/_jobs.html' %}
{% endif %}
{% if not jobs and not show_scheduled_jobs %}
{#
`_jobs.html` will show the You have no jobs message when
passed an empty list of jobs
#}
{% include 'views/dashboard/_jobs.html' %}
{% endif %}
{{ previous_next_navigation(prev_page, next_page) }}