From f2fc384586ff2f02fe7623a11e208bf51a51056d Mon Sep 17 00:00:00 2001 From: CyberMind-FR Date: Wed, 31 Dec 2025 11:06:36 +0100 Subject: [PATCH] fix(netdata-dashboard): add missing utility functions to API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added utility functions that views depend on: - formatKB() - Format kilobytes with automatic unit conversion (KB/MB/GB/TB) - getStatusClass() - Return CSS class based on percentage thresholds (good: <50%, info: 50-74%, warning: 75-89%, critical: >=90%) - getTempClass() - Return CSS class based on temperature in Celsius (good: <60°C, info: 60-69°C, warning: 70-79°C, critical: >=80°C) Resolves "API.formatKB is not a function", "API.getStatusClass is not a function", and "API.getTempClass is not a function" errors. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- .../resources/netdata-dashboard/api.js | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/luci-app-netdata-dashboard/htdocs/luci-static/resources/netdata-dashboard/api.js b/luci-app-netdata-dashboard/htdocs/luci-static/resources/netdata-dashboard/api.js index 9c4048f5..f730a946 100644 --- a/luci-app-netdata-dashboard/htdocs/luci-static/resources/netdata-dashboard/api.js +++ b/luci-app-netdata-dashboard/htdocs/luci-static/resources/netdata-dashboard/api.js @@ -128,6 +128,33 @@ function formatUptime(seconds) { return parts.join(' ') || '0m'; } +function formatKB(kb) { + if (!kb || kb === 0) return '0 KB'; + var units = ['KB', 'MB', 'GB', 'TB']; + var i = 0; + var size = kb; + while (size >= 1024 && i < units.length - 1) { + size = size / 1024; + i++; + } + return size.toFixed(2) + ' ' + units[i]; +} + +function getStatusClass(percent) { + if (percent >= 90) return 'critical'; + if (percent >= 75) return 'warning'; + if (percent >= 50) return 'info'; + return 'good'; +} + +function getTempClass(temp) { + if (!temp) return 'good'; + if (temp >= 80) return 'critical'; + if (temp >= 70) return 'warning'; + if (temp >= 60) return 'info'; + return 'good'; +} + return baseclass.extend({ // System stats getStats: callStats, @@ -175,5 +202,8 @@ return baseclass.extend({ // Utility functions formatBytes: formatBytes, - formatUptime: formatUptime + formatKB: formatKB, + formatUptime: formatUptime, + getStatusClass: getStatusClass, + getTempClass: getTempClass });