webapi: Remove duplicate code to render admin.html
This commit is contained in:
parent
363fdcb224
commit
b6ffde116a
@ -144,6 +144,11 @@ func (w *WebAPI) statusJSON(c *gin.Context) {
|
|||||||
|
|
||||||
// adminPage is the handler for "GET /admin".
|
// adminPage is the handler for "GET /admin".
|
||||||
func (w *WebAPI) adminPage(c *gin.Context) {
|
func (w *WebAPI) adminPage(c *gin.Context) {
|
||||||
|
// Render the admin template with no search result.
|
||||||
|
w.renderAdmin(c, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *WebAPI) renderAdmin(c *gin.Context, searchResult *searchResult) {
|
||||||
cacheData := c.MustGet(cacheKey).(cacheData)
|
cacheData := c.MustGet(cacheKey).(cacheData)
|
||||||
|
|
||||||
missed, err := w.db.GetMissedTickets()
|
missed, err := w.db.GetMissedTickets()
|
||||||
@ -163,6 +168,7 @@ func (w *WebAPI) adminPage(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
c.HTML(http.StatusOK, "admin.html", gin.H{
|
c.HTML(http.StatusOK, "admin.html", gin.H{
|
||||||
|
"SearchResult": searchResult,
|
||||||
"WebApiCache": cacheData,
|
"WebApiCache": cacheData,
|
||||||
"WebApiCfg": w.cfg,
|
"WebApiCfg": w.cfg,
|
||||||
"WalletStatus": w.walletStatus(c),
|
"WalletStatus": w.walletStatus(c),
|
||||||
@ -175,8 +181,6 @@ func (w *WebAPI) adminPage(c *gin.Context) {
|
|||||||
// ticketSearch is the handler for "POST /admin/ticket". The hash param will be
|
// ticketSearch is the handler for "POST /admin/ticket". The hash param will be
|
||||||
// used to retrieve a ticket from the database.
|
// used to retrieve a ticket from the database.
|
||||||
func (w *WebAPI) ticketSearch(c *gin.Context) {
|
func (w *WebAPI) ticketSearch(c *gin.Context) {
|
||||||
cacheData := c.MustGet(cacheKey).(cacheData)
|
|
||||||
|
|
||||||
hash := c.PostForm("hash")
|
hash := c.PostForm("hash")
|
||||||
|
|
||||||
ticket, found, err := w.db.GetTicketByHash(hash)
|
ticket, found, err := w.db.GetTicketByHash(hash)
|
||||||
@ -230,24 +234,7 @@ func (w *WebAPI) ticketSearch(c *gin.Context) {
|
|||||||
feeTxDecoded = string(decoded)
|
feeTxDecoded = string(decoded)
|
||||||
}
|
}
|
||||||
|
|
||||||
missed, err := w.db.GetMissedTickets()
|
w.renderAdmin(c, &searchResult{
|
||||||
if err != nil {
|
|
||||||
w.log.Errorf("db.GetMissedTickets error: %v", err)
|
|
||||||
c.String(http.StatusInternalServerError, "Error getting missed tickets from db")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
missed.SortByPurchaseHeight()
|
|
||||||
|
|
||||||
xpubs, err := w.db.AllXPubs()
|
|
||||||
if err != nil {
|
|
||||||
w.log.Errorf("db.AllXPubs error: %v", err)
|
|
||||||
c.String(http.StatusInternalServerError, "Error getting xpubs from db")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
c.HTML(http.StatusOK, "admin.html", gin.H{
|
|
||||||
"SearchResult": searchResult{
|
|
||||||
Hash: hash,
|
Hash: hash,
|
||||||
Found: found,
|
Found: found,
|
||||||
Ticket: ticket,
|
Ticket: ticket,
|
||||||
@ -255,13 +242,6 @@ func (w *WebAPI) ticketSearch(c *gin.Context) {
|
|||||||
AltSignAddrData: altSignAddrData,
|
AltSignAddrData: altSignAddrData,
|
||||||
VoteChanges: voteChanges,
|
VoteChanges: voteChanges,
|
||||||
MaxVoteChanges: w.cfg.MaxVoteChangeRecords,
|
MaxVoteChanges: w.cfg.MaxVoteChangeRecords,
|
||||||
},
|
|
||||||
"WebApiCache": cacheData,
|
|
||||||
"WebApiCfg": w.cfg,
|
|
||||||
"WalletStatus": w.walletStatus(c),
|
|
||||||
"DcrdStatus": w.dcrdStatus(c),
|
|
||||||
"MissedTickets": missed,
|
|
||||||
"XPubs": xpubs,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user