From 5c57f5b5884083d2ccf2954a1315c05579dc78bb Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 23 Mar 2016 08:43:45 +0000 Subject: [PATCH] Make dashboard stats update dynamically https://www.pivotaltracker.com/story/show/115874485 This uses the same component as on the jobs page to make a partial section of the page update itself periodically. --- app/main/views/dashboard.py | 17 ++++++++++++++++- app/templates/views/dashboard/dashboard.html | 10 +++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index 6fc17c49c..8cec638b4 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -1,7 +1,8 @@ from flask import ( render_template, session, - flash + flash, + jsonify ) from flask_login import login_required @@ -41,6 +42,20 @@ def service_dashboard(service_id): service_id=str(service_id)) +@main.route("/services//dashboard.json") +@login_required +def service_dashboard_updates(service_id): + + statistics = statistics_api_client.get_statistics_for_service(service_id)['data'] + + return jsonify(**{ + 'today': render_template( + 'views/dashboard/today.html', + statistics=expand_statistics(statistics), + ) + }) + + def expand_statistics(statistics, danger_zone=25): if not statistics or not statistics[0]: diff --git a/app/templates/views/dashboard/dashboard.html b/app/templates/views/dashboard/dashboard.html index 67fb31a53..d41e85f4d 100644 --- a/app/templates/views/dashboard/dashboard.html +++ b/app/templates/views/dashboard/dashboard.html @@ -13,7 +13,15 @@ {% if not jobs %} {% include 'views/dashboard/get-started.html' %} {% else %} - {% include 'views/dashboard/today.html' %} + +
+ {% include 'views/dashboard/today.html' %} +
+ {% include 'views/dashboard/jobs.html' %} {% endif %}