Indent JSON on admin screen.
This commit is contained in:
parent
851d3137e5
commit
32c5c7a524
@ -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/>", " ")
|
||||
if err != nil {
|
||||
log.Errorf("Failed to indent JSON: %w", err)
|
||||
return template.HTML(input)
|
||||
}
|
||||
|
||||
return template.HTML(indented.String())
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user