Make a macro for the AJAX update module

This is less repetitive than typing out the HTML with all its attributes
every time.

It also lets us wrap up the idea of ‘finished’ as a parameter, so the
AJAX code will only be initiated when it’s needed, eg if a job is still
processing.
This commit is contained in:
Chris Hill-Scott
2016-06-28 09:21:46 +01:00
parent c761d57d1d
commit fa01c1bc5c
7 changed files with 53 additions and 68 deletions

View File

@@ -4,6 +4,7 @@
{% 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 %}
{% from "components/ajax-block.html" import ajax_block %}
{% block page_title %}
{{ current_service.name }} GOV.UK Notify
@@ -29,30 +30,18 @@
In the last 7 days
</h2>
<div
data-module="update-content"
data-resource="{{url_for(".service_dashboard_updates", service_id=current_service.id)}}"
data-key="totals"
data-interval-seconds="2"
aria-live="polite"
>
{% call ajax_block(updates_url, 'totals') %}
{% include 'views/dashboard/_totals.html' %}
</div>
{% endcall %}
{{ show_more(
url_for('.weekly', service_id=current_service.id),
'Compare to previous weeks'
) }}
{% if template_statistics|length %}
<div
data-module="update-content"
data-resource="{{url_for(".service_dashboard_updates", service_id=current_service.id)}}"
data-key="template-statistics"
data-interval-seconds="2"
aria-live="polite"
>
{% call ajax_block(updates_url, 'template-statistics') %}
{% include 'views/dashboard/template-statistics.html' %}
</div>
{% endcall %}
{{ show_more(
url_for('.template_history', service_id=current_service.id),
'See all templates used this year'
@@ -60,14 +49,9 @@
{% endif %}
{% if jobs %}
<div
data-module="update-content"
data-resource="{{url_for(".service_dashboard_updates", service_id=current_service.id)}}"
data-key="jobs"
data-interval-seconds="2"
aria-live="polite"
>
{% include 'views/dashboard/_jobs.html' %}
{% call ajax_block(updates_url, 'jobs') %}
{% include 'views/dashboard/_jobs.html' %}
{% endcall %}
{{ show_more(
url_for('.view_jobs', service_id=current_service.id),
'See all uploaded files'
@@ -76,15 +60,9 @@
{% if current_user.has_permissions(['manage_settings'], admin_override=True) %}
<h2 class='heading-medium'>This year</h2>
<div
data-module="update-content"
data-resource="{{url_for(".service_dashboard_updates", service_id=current_service.id)}}"
data-key="usage"
data-interval-seconds="2"
aria-live="polite"
>
{% call ajax_block(updates_url, 'usage') %}
{% include 'views/dashboard/_usage.html' %}
</div>
{% endcall %}
{{ show_more(
url_for(".usage", service_id=current_service['id']),
'See usage breakdown'