Skip to content

Commit

Permalink
webui: show maintenance mode warning if site is readonly
Browse files Browse the repository at this point in the history
  • Loading branch information
RaghavSood committed Jun 18, 2024
1 parent ffc31e9 commit 7afd3b2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/btcsupply/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ func main() {
log.Info().Msg("Running in read-only mode, not indexing the blockchain")
}

webuiServer := webui.NewWebUI(db)
webuiServer := webui.NewWebUI(db, noindex)
webuiServer.Serve()
}
6 changes: 6 additions & 0 deletions templates/header.tmpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{{ define "header" }}
<!-- Show maintenance banner if site is in read only mode -->
{{ if .Readonly }}
<div class="bg-red-500 text-white text-center p-2">
<p class="text-sm">Maintenance ongoing. Block data may not be up to date.</p>
</div>
{{ end }}
<header class="bg-gray-800 text-white">
<nav class="flex items-center justify-between">
<div class="pt-4 pb-4 pl-4 flex items-center space-x-3">
Expand Down
9 changes: 6 additions & 3 deletions webui/webui.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ import (
)

type WebUI struct {
db storage.Storage
db storage.Storage
readonly bool
}

func NewWebUI(db storage.Storage) *WebUI {
func NewWebUI(db storage.Storage, noindex bool) *WebUI {
return &WebUI{
db: db,
db: db,
readonly: noindex,
}
}

Expand Down Expand Up @@ -132,6 +134,7 @@ func (w *WebUI) Methodology(c *gin.Context) {

func (w *WebUI) renderTemplate(c *gin.Context, template string, params map[string]interface{}) {
tmpl := templates.New()
params["Readonly"] = w.readonly
err := tmpl.Render(c.Writer, template, params)
if err != nil {
log.Error().Err(err).Msg("Failed to render template")
Expand Down

0 comments on commit 7afd3b2

Please sign in to comment.