From 9c311fb6e93ac523d53daed15afb624c5fe1d10a Mon Sep 17 00:00:00 2001 From: Benji Schwartz-Gilbert Date: Fri, 2 Oct 2015 20:19:34 -0700 Subject: [PATCH] Fix and refactor the auto-refresh control so that 'disabled' does not constantly try to refresh --- mrq/dashboard/static/js/views/index.js | 26 +++++++++++++++++--------- mrq/dashboard/templates/index.html | 2 +- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/mrq/dashboard/static/js/views/index.js b/mrq/dashboard/static/js/views/index.js index 4f62d336..e6e5709c 100644 --- a/mrq/dashboard/static/js/views/index.js +++ b/mrq/dashboard/static/js/views/index.js @@ -107,27 +107,35 @@ define(["jquery", "underscore", "views/generic/page", "models", "moment", "circl refreshStats: function (poolSize, currentJobs, utilization, doneJobs) { var self = this; var values = self.addToCounter("overall-done-jobs", doneJobs, 50).join(","); - var refreshInterval = parseInt($(".js-autorefresh").val(), 10) * 1000; self.$(".inlinesparkline").attr("values", values); self.$(".inlinesparkline").sparkline("html", {"width": "250px", "height": "200px", "defaultPixelsPerValue": 1}); self.refreshCircleStats(poolSize, currentJobs, utilization); - - setTimeout(function () { - self.fetchStats(self.refreshStats); - }, refreshInterval); + self.autoUpdateStats(); }, render: function() { var self = this; - var refreshInterval = parseInt($(".js-autorefresh").val(), 10) * 1000; self.renderTemplate(); self.fetchStats(self.renderStats); + self.autoUpdateStats(); + }, - setTimeout(function () { - self.fetchStats(self.refreshStats); - }, refreshInterval); + autoUpdateStats: function() { + var self = this; + var refreshInterval = parseInt($(".js-autorefresh").val(), 10) * 1000; + + if(refreshInterval > 0) { + setTimeout(function () { + self.fetchStats(self.refreshStats); + }, refreshInterval); + } else { + // Check if the option has changed again in 2 seconds + setTimeout(function () { + self.autoUpdateStats(); + }, 2000); + } } }); diff --git a/mrq/dashboard/templates/index.html b/mrq/dashboard/templates/index.html index 063173ca..dec6b9d9 100644 --- a/mrq/dashboard/templates/index.html +++ b/mrq/dashboard/templates/index.html @@ -78,7 +78,7 @@ - +