Skip to content

Commit

Permalink
Merge pull request #147 from synyx/better-title
Browse files Browse the repository at this point in the history
Add dashboard to title
  • Loading branch information
BuJo authored Nov 13, 2023
2 parents 18a2be1 + 299f032 commit bce81a7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pkg/web/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ func (h *webHandler) alerts(w http.ResponseWriter, req *http.Request) {
aggregate := h.aggregator.Alerts(dashboardName)

if req.Header.Get("Accept") == "text/vnd.turbo-stream.html" {
renderer := h.partialRenderer(req, "alerts.gohtml")
renderer := h.partialRenderer(req, dashboardName, "alerts.gohtml")
renderer(w, 200, webContent{Content: aggregate})
} else {
renderer := h.baseRenderer(req, "alerts.gohtml")
renderer := h.baseRenderer(req, dashboardName, "alerts.gohtml")
renderer(w, 200, webContent{Content: aggregate})
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/web/templates/_base.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<head>
<meta charset="utf-8">
<title>
Nagios et al. Dashboard
Tuwat{{with .Dashboard}} - {{.}}{{end}}
</title>

<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
Expand Down
7 changes: 5 additions & 2 deletions pkg/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type webContent struct {
Environment string
Content any
Dashboards map[string]*config.Dashboard
Dashboard string
}

func WebHandler(cfg *config.Config, aggregator *aggregation.Aggregator) http.Handler {
Expand Down Expand Up @@ -123,7 +124,7 @@ func (h *webHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {

type renderFunc func(w http.ResponseWriter, statusCode int, data webContent)

func (h *webHandler) baseRenderer(req *http.Request, patterns ...string) renderFunc {
func (h *webHandler) baseRenderer(req *http.Request, dashboardName string, patterns ...string) renderFunc {
var templateFiles []string
var templateDefinition string

Expand All @@ -148,6 +149,7 @@ func (h *webHandler) baseRenderer(req *http.Request, patterns ...string) renderF
data.Version = version.Info.Version
data.Environment = h.environment
data.Dashboards = h.dashboards
data.Dashboard = dashboardName

err := tmpl.ExecuteTemplate(w, templateDefinition, data)
if err != nil {
Expand All @@ -157,7 +159,7 @@ func (h *webHandler) baseRenderer(req *http.Request, patterns ...string) renderF
}
}

func (h *webHandler) partialRenderer(req *http.Request, patterns ...string) renderFunc {
func (h *webHandler) partialRenderer(req *http.Request, dashboardName string, patterns ...string) renderFunc {
var templateFiles []string
var templateDefinition string

Expand All @@ -181,6 +183,7 @@ func (h *webHandler) partialRenderer(req *http.Request, patterns ...string) rend

data.Version = version.Info.Version
data.Environment = h.environment
data.Dashboard = dashboardName

err := tmpl.ExecuteTemplate(w, templateDefinition, data)
if err != nil {
Expand Down

0 comments on commit bce81a7

Please sign in to comment.