Browse Source

Added method to update rather than replace new charts

Henry Whitaker 6 years ago
parent
commit
34c5a92080
2 changed files with 22 additions and 6 deletions
  1. 1 1
      api/functions/homepage-connect-functions.php
  2. 21 5
      js/functions.js

+ 1 - 1
api/functions/homepage-connect-functions.php

@@ -2713,7 +2713,7 @@ function getNetdata()
 		$url = qualifyURL($GLOBALS['netdataURL']);
 
 		for($i = 1; $i < 7; $i++) {
-			if($GLOBALS['netdata'.($i).'Data'] != '') {
+			if($GLOBALS['netdata'.($i).'Enabled']) {
 				switch($GLOBALS['netdata'.$i.'Data']) {
 					case 'disk-read':
 						$data = disk('in', $url);

+ 21 - 5
js/functions.js

@@ -7418,7 +7418,7 @@ function buildNetdataItem(array){
             $('#easyPieChart`+(i+1)+`').easyPieChart({
                 size: 183,
                 lineWidth: 7,
-                animate: false,
+                //animate: false,
                 scaleColor: false,
                 barColor: '#`+e.colour+`',
                 trackColor: '#bababa',
@@ -7431,7 +7431,7 @@ function buildNetdataItem(array){
     return html;
 }
 function buildNetdata(array){
-    console.log(array);
+    // console.log(array);
     var data = array.data;
     if(array === false){ return ''; }
 
@@ -7592,9 +7592,11 @@ function homepageNetdata(timeout){
             orgErrorAlert('<h4>' + e + '</h4>' + formatDebug(data));
             return false;
         }
-        document.getElementById('homepageOrderNetdata').innerHTML = '';
-        if(response.data !== null){
-            $('#homepageOrderNetdata').html(buildNetdata(response.data));
+        if(!tryUpdateNetdata(response.data.data)) {
+            document.getElementById('homepageOrderNetdata').innerHTML = '';
+            if(response.data !== null){
+                $('#homepageOrderNetdata').html(buildNetdata(response.data));
+            }
         }
     }).fail(function(xhr) {
         console.error("Organizr Function: API Connection Failed");
@@ -7603,6 +7605,20 @@ function homepageNetdata(timeout){
     if(typeof timeouts[timeoutTitle] !== 'undefined'){ clearTimeout(timeouts[timeoutTitle]); }
     timeouts[timeoutTitle] = setTimeout(function(){ homepageNetdata(timeout); }, timeout);
 }
+function tryUpdateNetdata(array){
+    var existing = false;
+    array.forEach((e,i) => {
+        var id = i + 1;
+        if($('#easyPieChart' + id).length) {
+            $('#easyPieChart' + id).data('easyPieChart').update(e.percent);
+            $('#easyPieChart' + id + 'Value').html(parseFloat(e.value).toFixed(1));
+            existing = true;
+        } else {
+            existing = false;
+        }
+    });
+    return existing;
+}
 // Thanks Swifty!
 function PopupCenter(url, title, w, h) {
     // Fixes dual-screen position                         Most browsers      Firefox