mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2025-07-23 04:51:39 +02:00
Fix bug in SearchBar Handler
Introduce Message boxes Incomplete and needs cleanup
This commit is contained in:
21
web/templates/message.tmpl
Normal file
21
web/templates/message.tmpl
Normal file
@@ -0,0 +1,21 @@
|
||||
{{define "navigation"}}
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-lg navbar-light fixed-top bg-light">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="/">
|
||||
<img style="height: 30px;" alt="ClusterCockpit Logo" src="/img/logo.png" class="d-inline-block align-top">
|
||||
</a>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
{{end}}
|
||||
|
||||
{{define "content"}}
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="alert alert-info" role="alert">
|
||||
{{.Info}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
45
web/web.go
45
web/web.go
@@ -96,8 +96,7 @@ type Page struct {
|
||||
func RenderTemplate(rw http.ResponseWriter, r *http.Request, file string, page *Page) {
|
||||
t, ok := templates[file]
|
||||
if !ok {
|
||||
log.Fatalf("WEB/WEB > template '%s' not found", file)
|
||||
panic("template not found")
|
||||
log.Errorf("WEB/WEB > template '%s' not found", file)
|
||||
}
|
||||
|
||||
if page.Clusters == nil {
|
||||
@@ -106,7 +105,47 @@ func RenderTemplate(rw http.ResponseWriter, r *http.Request, file string, page *
|
||||
}
|
||||
}
|
||||
|
||||
log.Infof("Page config : %v\n", page.Config)
|
||||
log.Debugf("Page config : %v\n", page.Config)
|
||||
if err := t.Execute(rw, page); err != nil {
|
||||
log.Errorf("Template error: %s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
type Message struct {
|
||||
Title string
|
||||
Type string
|
||||
Message string
|
||||
Icon string
|
||||
}
|
||||
|
||||
func RenderMessage(rw http.ResponseWriter, msgType string, msg string) {
|
||||
var page Message
|
||||
log.Info("render message template")
|
||||
|
||||
switch msgType {
|
||||
case "success":
|
||||
page.Title = "Success"
|
||||
page.Type = "alert-success"
|
||||
case "info":
|
||||
page.Title = "Info"
|
||||
page.Type = "alert-info"
|
||||
case "warn":
|
||||
page.Title = "Warning"
|
||||
page.Type = "alert-warning"
|
||||
case "error":
|
||||
page.Title = "Error"
|
||||
page.Type = "alert-danger"
|
||||
default:
|
||||
page.Title = "Message"
|
||||
page.Type = "alert-secondary"
|
||||
}
|
||||
t, ok := templates["message.tmpl"]
|
||||
if !ok {
|
||||
log.Error("WEB/WEB > template message.tmpl not found")
|
||||
}
|
||||
page.Message = msg
|
||||
rw.Header().Add("Content-Type", "text/html; charset=utf-8")
|
||||
|
||||
if err := t.Execute(rw, page); err != nil {
|
||||
log.Errorf("Template error: %s", err.Error())
|
||||
}
|
||||
|
Reference in New Issue
Block a user