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 package webapi
import ( import (
"bytes"
"encoding/json"
"fmt" "fmt"
"html/template"
"strings" "strings"
"time" "time"
) )
@ -33,3 +36,14 @@ func stripWss(input string) string {
input = strings.ReplaceAll(input, "/ws", "") input = strings.ReplaceAll(input, "/ws", "")
return input 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 { .block__content table th {
vertical-align: top;
white-space: nowrap; white-space: nowrap;
} }
@ -128,6 +127,7 @@ footer .code {
.ticket-table td { .ticket-table td {
font-size: 14px; font-size: 14px;
text-align: left; text-align: left;
padding-right: 0;
} }

View File

@ -193,7 +193,7 @@
<table class="table ticket-table my-2"> <table class="table ticket-table my-2">
<tr> <tr>
<th>Request</th> <th>Request</th>
<td>{{ $value.Request }}</td> <td>{{ indentJSON $value.Request }}</td>
</tr> </tr>
<tr> <tr>
<th>Request<br />Signature</th> <th>Request<br />Signature</th>
@ -201,7 +201,7 @@
</tr> </tr>
<tr> <tr>
<th>Response</th> <th>Response</th>
<td>{{ $value.Response }}</td> <td>{{ indentJSON $value.Response }}</td>
</tr> </tr>
<tr> <tr>
<th>Response<br />Signature</th> <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), "blockURL": blockURL(cfg.BlockExplorerURL),
"dateTime": dateTime, "dateTime": dateTime,
"stripWss": stripWss, "stripWss": stripWss,
"indentJSON": indentJSON,
}) })
router.LoadHTMLGlob("webapi/templates/*.html") router.LoadHTMLGlob("webapi/templates/*.html")