unraid / webgui

Unraid Web UI
158 stars 70 forks source link

Fix UPS settings page when config contains empty values #1793

Closed jbtwo closed 3 months ago

jbtwo commented 3 months ago

Issue:

When either of the UPS config options Battery level to initiate shutdown (%) or Runtime left to initiate shutdown (minutes) are set to empty, the UPS details section breaks. This is due to the getUPSstatus function passing values directly from the config, which results in an error if either value is empty.

UPSsettings 2024-07-16 19-38-05

Solution:

The fix sets and passes variables to the getUPSstatus function for each of the config options. The variables are either set to the value contained in the config file, or 0 if the config has no value set.

Tested the fix locally and confirmed it functions as expected.

ljm42 commented 3 months ago

Good catch!

Would you please switch this over to the _var() function from Wrappers.php? It saves having to check for empty array values, and allows setting a default:

<?php
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
require_once "$docroot/webGui/include/Wrappers.php";
?>

var batteryLevel = "<?= _var($cfg,'BATTERYLEVEL',0) ?>";
var batteryRuntime = "<?= _var($cfg,'MINUTES',0) ?>";
jbtwo commented 3 months ago

Good catch!

Would you please switch this over to the _var() function from Wrappers.php? It saves having to check for empty array values, and allows setting a default:

<?php
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
require_once "$docroot/webGui/include/Wrappers.php";
?>

var batteryLevel = "<?= _var($cfg,'BATTERYLEVEL',0) ?>";
var batteryRuntime = "<?= _var($cfg,'MINUTES',0) ?>";

Thanks @ljm42, changes made