Split the JSON responses into one key per section

Previously, the AJAX update for the dashboard was returning a big blob
of JSON with one key.

This commit splits it up to return:

- one key for each section of the page
- each containing a smaller chunk of HTML rendered from a partial

The jobs page was already working this way (pretty much) but just needed
a little tweaking to get it the same.
This commit is contained in:
Chris Hill-Scott
2016-06-28 09:07:04 +01:00
parent fe1d63675d
commit c761d57d1d
9 changed files with 135 additions and 131 deletions

View File

@@ -32,47 +32,64 @@
<div
data-module="update-content"
data-resource="{{url_for(".service_dashboard_updates", service_id=current_service.id)}}"
data-key="today"
data-key="totals"
data-interval-seconds="2"
aria-live="polite"
>
<div class="grid-row">
{% include 'views/dashboard/_totals.html' %}
<div class="column-whole">
{{ show_more(
url_for('.weekly', service_id=current_service.id),
'Compare to previous weeks'
) }}
</div>
</div>
{% if template_statistics|length %}
{% include 'views/dashboard/template-statistics.html' %}
{{ show_more(
url_for('.template_history', service_id=current_service.id),
'See all templates used this year'
) }}
{% 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>
{% include 'views/dashboard/_jobs.html' %}
{{ show_more(
url_for(".usage", service_id=current_service['id']),
'See usage breakdown'
) }}
{% endif %}
{% include 'views/dashboard/_totals.html' %}
</div>
{{ 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"
>
{% include 'views/dashboard/template-statistics.html' %}
</div>
{{ show_more(
url_for('.template_history', service_id=current_service.id),
'See all templates used this year'
) }}
{% 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' %}
{{ 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>
<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"
>
{% include 'views/dashboard/_usage.html' %}
</div>
{{ show_more(
url_for(".usage", service_id=current_service['id']),
'See usage breakdown'
) }}
{% endif %}
</div>