From 44de3e86945a3e7d24cc435c9b5fe88201c2f147 Mon Sep 17 00:00:00 2001 From: Paolo Asperti Date: Tue, 5 Jan 2021 12:06:27 +0100 Subject: [PATCH] Update status_ui.go and status.html --- src/status_ui.go | 11 +++++++---- templates/status.html | 10 +++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/status_ui.go b/src/status_ui.go index 888c490..c497c11 100644 --- a/src/status_ui.go +++ b/src/status_ui.go @@ -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{ diff --git a/templates/status.html b/templates/status.html index f47ea92..4825b4b 100644 --- a/templates/status.html +++ b/templates/status.html @@ -33,7 +33,7 @@ # - Plug name + Description Status Power load Command @@ -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": "
"}, { "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( '' ); } else { $('td:eq(2)', row).html( '' );