mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2025-07-23 04:51:39 +02:00
Unify and cleanup message template
This commit is contained in:
@@ -17,15 +17,9 @@
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-4 mx-auto">
|
||||
{{if .Error}}
|
||||
<div class="alert alert-warning" role="alert">
|
||||
{{.Error}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{if .Info}}
|
||||
<div class="alert alert-success" role="alert">
|
||||
{{.Info}}
|
||||
{{if .MsgType}}
|
||||
<div class="alert {{.MsgType}}" role="alert">
|
||||
{{.Message}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
|
@@ -13,8 +13,8 @@
|
||||
{{define "content"}}
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="alert alert-info" role="alert">
|
||||
{{.Info}}
|
||||
<div class="alert {{.MsgType}}" role="alert">
|
||||
{{.Message}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
44
web/web.go
44
web/web.go
@@ -82,8 +82,8 @@ type Build struct {
|
||||
|
||||
type Page struct {
|
||||
Title string // Page title
|
||||
Error string // For generic use (e.g. the exact error message on /login)
|
||||
Info string // For generic use (e.g. "Logout successfull" on /login)
|
||||
MsgType string // For generic use in message boxes
|
||||
Message string // For generic use in message boxes
|
||||
User auth.User // Information about the currently logged in user (Full User Info)
|
||||
Roles map[string]auth.Role // Available roles for frontend render checks
|
||||
Build Build // Latest information about the application
|
||||
@@ -110,43 +110,3 @@ func RenderTemplate(rw http.ResponseWriter, r *http.Request, file string, page *
|
||||
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