This repository has been archived by the owner on May 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
alert.go
85 lines (72 loc) · 1.61 KB
/
alert.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package web
import (
"encoding/gob"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
)
const AlertsKey string = "alerts"
// Here some generic alerts
var AlertCatalogNotFound = func() Alert {
return Alert{
Type: "danger",
Title: "Error loading the checks catalog",
Text: "Checks catalog couldn't be retrieved",
}
}
var AlertConnectionDataNotFound = func() Alert {
return Alert{
Type: "danger",
Title: "Error loading the connection data",
Text: "Connection data couldn't be retrieved.",
}
}
var CheckResultsNotFound = func() Alert {
return Alert{
Type: "danger",
Title: "Error loading the checks result",
Text: "Checks result couldn't be retrieved. Check if the Trento runner is running",
}
}
var NoCheckSelected = func() Alert {
return Alert{
Type: "info",
Title: "There is not any check selected",
Text: "Select the desired checks in the settings modal in order to validate the cluster configuration",
}
}
type Alert struct {
Type string
Title string
Text string
}
func (a *Alert) GetIcon() string {
switch a.Type {
case "success":
return "check_circle"
case "warning":
return "warning"
case "danger":
return "error"
default:
return "info"
}
}
func InitAlerts() {
gob.Register(Alert{})
}
func StoreAlert(c *gin.Context, a Alert) {
session := sessions.Default(c)
session.AddFlash(a, AlertsKey)
session.Save()
}
func GetAlerts(c *gin.Context) []Alert {
session := sessions.Default(c)
f := session.Flashes(AlertsKey)
var alerts []Alert
for _, alertI := range f {
alert, _ := alertI.(Alert)
alerts = append(alerts, alert)
}
session.Save()
return alerts
}