Skip to content

Commit

Permalink
Merge pull request #8 from Peuuuur-Noel/master
Browse files Browse the repository at this point in the history
Fix dashboard info
  • Loading branch information
SimonFair authored Jul 24, 2023
2 parents d664eb8 + 3f4199d commit d59bede
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
10 changes: 5 additions & 5 deletions source/nut/usr/local/emhttp/plugins/nut/include/nut_footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ function format_time($seconds) {

if ($battery !== false) {
$battery_runtime = array_key_exists($nut_runtime, $ups_status) ? format_time($ups_status[$nut_runtime]) : "n/a";
if ($online && $battery < 100) $icon = "<span id='".($config['FOOTER_STYLE'] == 1 ? "copyright" : "nut_battery")."' class='tooltip-nut ".($config['FOOTER_STYLE'] == 1 ? "$black" : "$green")."' data='{$nut_name}: online - battery is charging'><i class='fa fa-battery-charging'></i>&thinsp;{$battery}&thinsp;%</span>";
else if ($online && $battery == 100) $icon = "<span id='".($config['FOOTER_STYLE'] == 1 ? "copyright" : "nut_battery")."' class='tooltip-nut ".($config['FOOTER_STYLE'] == 1 ? "$black" : "$green")."' data='{$nut_name}: online - battery is full'><i class='fa fa-battery-full'></i>&thinsp;{$battery}&thinsp;%</span>";
else if (!$online) $icon = "<span id='".($config['FOOTER_STYLE'] == 1 ? "copyright" : "nut_battery")."' class='tooltip-nut $red' data='{$nut_name}: offline - battery is discharging - est. $battery_runtime left'><i class='fa fa-battery-discharging'></i>&thinsp;{$battery}&thinsp;%</span>";
else $icon = "<span id='".($config['FOOTER_STYLE'] == 1 ? "copyright" : "nut_battery")."' class='tooltip-nut ".($config['FOOTER_STYLE'] == 1 ? "$black" : "$green")."' data='{$nut_name}: battery status unknown'><i class='fa fa-battery-discharging'></i>n/a</span>";
if ($online && $battery < 100) $icon = "<span id='".($config['FOOTER_STYLE'] == 1 ? "copyright" : "nut_battery")."' class='tooltip-nut ".($config['FOOTER_STYLE'] == 1 ? "$black" : "$green")."' data='[{$nut_name}] Online - Battery is charging'><i class='fa fa-battery-charging'></i>&thinsp;{$battery}&thinsp;%</span>";
else if ($online && $battery == 100) $icon = "<span id='".($config['FOOTER_STYLE'] == 1 ? "copyright" : "nut_battery")."' class='tooltip-nut ".($config['FOOTER_STYLE'] == 1 ? "$black" : "$green")."' data='[{$nut_name}] Online - Battery is full'><i class='fa fa-battery-full'></i>&thinsp;{$battery}&thinsp;%</span>";
else if (!$online) $icon = "<span id='".($config['FOOTER_STYLE'] == 1 ? "copyright" : "nut_battery")."' class='tooltip-nut $red' data='[{$nut_name}] Offline - Battery is discharging - Est. $battery_runtime left'><i class='fa fa-battery-discharging'></i>&thinsp;{$battery}&thinsp;%</span>";
else $icon = "<span id='".($config['FOOTER_STYLE'] == 1 ? "copyright" : "nut_battery")."' class='tooltip-nut ".($config['FOOTER_STYLE'] == 1 ? "$black" : "$green")."' data='[{$nut_name}] Battery status unknown'><i class='fa fa-battery-discharging'></i>n/a</span>";

$status[0] = $icon;
} else {
$status[0] = "<span id='nut_battery'class='tooltip-nut' style='margin:0 6px 0 12px' data='$nut_name: battery info not available'><i class='fa fa-battery-empty'></i>&thinsp;n/a</span>";
$status[0] = "<span id='nut_battery'class='tooltip-nut' style='margin:0 6px 0 12px' data='[$nut_name] Battery info not available'><i class='fa fa-battery-empty'></i>&thinsp;n/a</span>";
}

# ups.power.nominal (in VA) or compute from load and ups.power.nominal
Expand Down
11 changes: 5 additions & 6 deletions source/nut/usr/local/emhttp/plugins/nut/nutFooter.page
Original file line number Diff line number Diff line change
Expand Up @@ -150,24 +150,23 @@ EOT;
<script type="text/javascript">
function UPSNUTArray() {
$.get('/plugins/nut/include/nut_status.php',{all:'false'},function(d) {
var data = d.replace(/<\/?tr>/g,'').replace(/<td/g,'<span').replace(/td>/g,'span>;').split(';')

$('#tblUPSNUTDash').find('tr.updated').remove();
var data = d.replace(/<\/?tr>/g,'').replace(/<td/g,'<span').replace(/td>/g,'span>').split('</span>');
$('#tblUPSNUTDash').find('tr.updated').remove();

$('#tblUPSNUTDash').append('<tr class="updated"><td>'+
"<tr class='updated'><td><span class='w36 ups'>UPS status:</span><span class='nut_status'>"+data[0]+"</span></td></tr>" +
"<tr class='updated'><td><span class='w36 ups'>Battery charge:</span><span class='nut_bcharge'>"+data[1]+"</span></td></tr>" +
"<tr class='updated'><td><span class='w36 ups'>Runtime left:</span><span class='nut_timeleft'>"+data[2]+"</span></td></tr>" +
"<tr class='updated'><td><span class='w36 ups'>Nominal power:</span>"+data[3]+"</td></tr>");
$("#tblUPSNUTDash").find('.nut_loadpct').html(data[5]+' - '+data[4]);
$("#tblUPSNUTDash").find('.nut_loadpct').html(data[5]+' - '+data[4]);
setTimeout(UPSNUTArray, <?=($nut_interval * 1000)?>);
}) ;
};

$(function(){
UPSNUTArray();
});
</script>
</script>
<?endif;?>


Expand All @@ -177,7 +176,7 @@ $(function(){
<script type="text/javascript">
function getNUTDashboard() {
$.get('/plugins/nut/include/nut_status.php',{all:'false'},function(d) {
var data = d.replace(/<\/?tr>/g,'').replace(/<td/g,'<span').replace(/td>/g,'span>;').split(';');
var data = d.replace(/<\/?tr>/g,'').replace(/<td/g,'<span').replace(/td>/g,'span>').split('</span>');
$("#db-box1").find('.nut_status').html(data[0]);
$("#db-box1").find('.nut_bcharge').html(data[1]);
$("#db-box1").find('.nut_timeleft').html(data[2]);
Expand Down

0 comments on commit d59bede

Please sign in to comment.