Update status_ui.go and status.html

This commit is contained in:
Paolo Asperti 2021-01-05 12:06:27 +01:00
parent 1edac26c50
commit 44de3e8694
2 changed files with 12 additions and 9 deletions

View File

@ -1,7 +1,6 @@
package main
import (
"fmt"
"net/http"
"strconv"
@ -15,12 +14,16 @@ func statusPage(ctx *macaron.Context) {
func jsonStatus(ctx *macaron.Context) {
// MQTTpublish("openpdu/status", "asdss")
var data = [][]string{}
var data = make([]Dictionary, 0)
var o *Outlet
for i := range outlets {
o = outlets[i]
d := []string{fmt.Sprintf("%d", o.Num), o.Channel.Name, fmt.Sprintf("%v", o.Channel.Value)}
data = append(data, d)
// d := []string{fmt.Sprintf("%d", o.Num), o.Channel.Name, fmt.Sprintf("%v", o.Channel.Value)}
data = append(data, Dictionary{
"Num": o.Num,
"Description": o.Description,
"Status": o.Channel.Value,
})
}
ctx.JSON(http.StatusOK, Dictionary{

View File

@ -33,7 +33,7 @@
<thead>
<tr>
<th style="width: 15px">#</th>
<th>Plug name</th>
<th>Description</th>
<th style="width: 30px">Status</th>
<th style="width: 300px">Power load</th>
<th style="width: 150px">Command</th>
@ -78,9 +78,9 @@
var table = $('#example2').DataTable({
'ajax': '/json/status',
"columns" : [
{ "data" : 0 },
{ "data" : 1 },
{ "data" : 2 },
{ "data" : "Num" },
{ "data" : "Description" },
{ "data" : "Status" },
{ "data" : null, "defaultContent": "<div class='progress progress-xs'><div class='progress-bar progress-bar-danger' style='width: 55%'></div></div>"},
{ "data" : null, "defaultContent":btnhtml }
],
@ -90,7 +90,7 @@
'ordering' : true,
'info' : true,
'rowCallback': function( row, data ) {
if ( data[2] == "true" ) {
if ( data.Status ) {
$('td:eq(2)', row).html( '<i class="fa fa-toggle-on"></i>' );
} else {
$('td:eq(2)', row).html( '<i class="fa fa-toggle-off"></i>' );