From 4a7a60f5d20968ddefbe6ee709d6961bb3afe444 Mon Sep 17 00:00:00 2001 From: Wim Brand Date: Mon, 8 Jun 2020 16:17:25 +0200 Subject: [PATCH] live updating admin graph --- res/include/script/admin.js | 13 ++++++++++--- res/template/admin.html | 17 +++++++++-------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/res/include/script/admin.js b/res/include/script/admin.js index 339a3ef..3109fe5 100644 --- a/res/include/script/admin.js +++ b/res/include/script/admin.js @@ -83,10 +83,16 @@ var graph = new Chart( } ); -function setData(days, interval){ +let graphTimeout = null; +function loadGraph(minutes, interval, live){ + if (graphTimeout !== null) { clearTimeout(graphTimeout) } + if (live) { + graphTimeout = setTimeout(() => {loadGraph(60, 1, true)}, 3000) + } + let today = new Date() let start = new Date() - start.setDate(start.getDate()-days) + start.setMinutes(start.getMinutes()-minutes) fetch( apiEndpoint+"/admin/files/timeseries" + @@ -107,7 +113,8 @@ function setData(days, interval){ alert("Error requesting time series: "+e); }) } -setData(7, 60); + +loadGraph(60, 1, true); // Load performance statistics diff --git a/res/template/admin.html b/res/template/admin.html index d28139e..8976aed 100644 --- a/res/template/admin.html +++ b/res/template/admin.html @@ -12,14 +12,15 @@ {{if $isAdmin}}

Bandwidth and views

- - - - - - - - + + + + + + + + +