Indent JSON on admin screen.

This commit is contained in:
Jamie Holdstock 2021-05-25 17:47:26 +08:00 committed by Jamie Holdstock
parent 851d3137e5
commit 32c5c7a524
4 changed files with 19 additions and 4 deletions

View File

@ -1,7 +1,10 @@
package webapi
import (
"bytes"
"encoding/json"
"fmt"
"html/template"
"strings"
"time"
)
@ -33,3 +36,14 @@ func stripWss(input string) string {
input = strings.ReplaceAll(input, "/ws", "")
return input
}
func indentJSON(input string) template.HTML {
var indented bytes.Buffer
err := json.Indent(&indented, []byte(input), "<br/>", "&nbsp;&nbsp;&nbsp;&nbsp;")
if err != nil {
log.Errorf("Failed to indent JSON: %w", err)
return template.HTML(input)
}
return template.HTML(indented.String())
}

View File

@ -117,7 +117,6 @@ footer .code {
}
.block__content table th {
vertical-align: top;
white-space: nowrap;
}
@ -128,6 +127,7 @@ footer .code {
.ticket-table td {
font-size: 14px;
text-align: left;
padding-right: 0;
}
@ -160,4 +160,4 @@ footer .code {
#status-table .with-text {
padding-left: 40px;
}
}

View File

@ -193,7 +193,7 @@
<table class="table ticket-table my-2">
<tr>
<th>Request</th>
<td>{{ $value.Request }}</td>
<td>{{ indentJSON $value.Request }}</td>
</tr>
<tr>
<th>Request<br />Signature</th>
@ -201,7 +201,7 @@
</tr>
<tr>
<th>Response</th>
<td>{{ $value.Response }}</td>
<td>{{ indentJSON $value.Response }}</td>
</tr>
<tr>
<th>Response<br />Signature</th>

View File

@ -182,6 +182,7 @@ func router(debugMode bool, cookieSecret []byte, dcrd rpc.DcrdConnect, wallets r
"blockURL": blockURL(cfg.BlockExplorerURL),
"dateTime": dateTime,
"stripWss": stripWss,
"indentJSON": indentJSON,
})
router.LoadHTMLGlob("webapi/templates/*.html")