From 292c60efd66fe8f13a2b8515e530053d636a5e7e Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Thu, 18 Apr 2024 11:53:26 +0200 Subject: [PATCH] fix: replace removed success and complete callbacks also reduced the polling intervals a bit to decrease load Signed-off-by: Daniel Kesselberg --- js/script.js | 57 ++++++++++++++++++++-------------------------------- 1 file changed, 22 insertions(+), 35 deletions(-) diff --git a/js/script.js b/js/script.js index 74ae1415..ebd7ad3c 100644 --- a/js/script.js +++ b/js/script.js @@ -50,24 +50,21 @@ function updateInfo() { const url = OC.generateUrl('/apps/serverinfo/update') - $.get(url).success(function(response) { - updateCPUStatistics(response.system.cpuload) - updateMemoryStatistics(response.system.mem_total, response.system.mem_free, response.system.swap_total, response.system.swap_free) - }).complete(function() { - setTimeout(updateInfo, 300) - }) + $.get(url) + .done(function (response) { + updateCPUStatistics(response.system.cpuload) + updateMemoryStatistics(response.system.mem_total, response.system.mem_free, response.system.swap_total, response.system.swap_free) + }) + .always(function () { + setTimeout(updateInfo, 2000) + }) } setTimeout(updateInfo, 0) }); - $(window).load(function(){ - resizeSystemCharts(); - }); - - $(window).resize(function () { - resizeSystemCharts(); - }); + window.addEventListener('load', resizeSystemCharts) + window.addEventListener('resize', resizeSystemCharts) function getThemedPrimaryColor() { return OCA.Theming ? OCA.Theming.color : 'rgb(54, 129, 195)'; @@ -241,10 +238,9 @@ } function initDiskCharts() { - $.ajax({ - url: OC.linkToOCS('apps/serverinfo/api/v1/', 2) + 'diskdata?format=json', - method: "GET", - success: function (response) { + const url = OC.linkToOCS('apps/serverinfo/api/v1/', 2) + 'diskdata?format=json'; + $.get(url) + .done(function (response) { var diskdata = response.ocs.data; var diskcharts = document.querySelectorAll(".DiskChart"); var i; @@ -278,35 +274,26 @@ } }); } - }, - error: function (data) { - console.log(data); - } - }); + }); - var interval = 1000; // 1000 = 1 second, 3000 = 3 seconds + var interval = 10000; // 1000 = 1 second, 3000 = 3 seconds function doAjax() { - $.ajax({ - url: OC.linkToOCS('apps/serverinfo/api/v1/', 2) + 'basicdata?format=json', - method: "GET", - success: function (response) { + const url = OC.linkToOCS('apps/serverinfo/api/v1/', 2) + 'basicdata?format=json'; + $.get(url) + .done(function (response) { var data = response.ocs.data; document.getElementById("servertime").innerHTML = data.servertime; document.getElementById("uptime").innerHTML = data.uptime; for (const thermalzone of data.thermalzones) { document.getElementById(thermalzone.zone).textContent = thermalzone.temp; } - }, - error: function (data) { - console.log(data); - }, - complete: function (data) { + }) + .always(function () { setTimeout(doAjax, interval); - } - }); + }); } - setTimeout(doAjax, interval); + setTimeout(doAjax, 0); } })(jQuery, OC);