Compare commits
No commits in common. "c01ed135a94824ef4de960845caa8523119dcc5e" and "c7ad2aa1b644ba53ee782dd5d2fccd4b8cb53cfc" have entirely different histories.
c01ed135a9
...
c7ad2aa1b6
22
main.go
22
main.go
@ -29,7 +29,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const VERSION = "v23"
|
||||
const VERSION = "v22"
|
||||
|
||||
var (
|
||||
logger *slog.Logger
|
||||
@ -155,7 +155,6 @@ func main() { // {{{
|
||||
service.Register("/configuration/timezone", false, false, actionConfigurationTimezone)
|
||||
service.Register("/configuration/notification", false, false, pageConfigurationNotification)
|
||||
service.Register("/configuration/notification/update/{prio}", false, false, actionConfigurationNotificationUpdate)
|
||||
service.Register("/configuration/notification/delete/{prio}", false, false, actionConfigurationNotificationDelete)
|
||||
service.Register("/entry/{datapoint}", false, false, actionEntryDatapoint)
|
||||
|
||||
go nodataLoop()
|
||||
@ -1086,8 +1085,7 @@ func pageConfigurationNotification(w http.ResponseWriter, r *http.Request, _ *se
|
||||
var service notification.Service
|
||||
if notificationType != "" {
|
||||
// Create a new instance of the selected notification type.
|
||||
service = notification.NewInstance(notificationType)
|
||||
logger.Info("FOO", "service", fmt.Sprintf("%p %#v\n", service, service))
|
||||
service = notification.GetInstance(notificationType)
|
||||
} else {
|
||||
// Find the existing service for editing.
|
||||
prio, err := strconv.Atoi(prioStr)
|
||||
@ -1140,7 +1138,7 @@ func actionConfigurationNotificationUpdate(w http.ResponseWriter, r *http.Reques
|
||||
// prio -1 means a new service, not existing in database.
|
||||
var svc *notification.Service
|
||||
if prio == -1 {
|
||||
emptyService := notification.NewInstance(r.PostFormValue("type"))
|
||||
emptyService := notification.GetInstance(r.PostFormValue("type"))
|
||||
svc = &emptyService
|
||||
} else {
|
||||
svc = notificationManager.GetService(prio)
|
||||
@ -1180,17 +1178,3 @@ func actionConfigurationNotificationUpdate(w http.ResponseWriter, r *http.Reques
|
||||
w.Header().Add("Location", "/configuration")
|
||||
w.WriteHeader(302)
|
||||
} // }}}
|
||||
func actionConfigurationNotificationDelete(w http.ResponseWriter, r *http.Request, _ *session.T) { // {{{
|
||||
prioStr := r.PathValue("prio")
|
||||
prio, err := strconv.Atoi(prioStr)
|
||||
if err != nil {
|
||||
pageError(w, "/configuration", werr.Wrap(err).Log())
|
||||
return
|
||||
}
|
||||
|
||||
DeleteNotificationService(prio)
|
||||
notificationManager.RemoveService(prio)
|
||||
|
||||
w.Header().Add("Location", "/configuration")
|
||||
w.WriteHeader(302)
|
||||
} // }}}
|
||||
|
@ -37,16 +37,6 @@ func ServiceFactory(t string, config []byte, prio int, ackURL string, logger *sl
|
||||
return nil, werr.New("Unknown notification service, '%s'", t).WithCode("002-0000")
|
||||
}
|
||||
|
||||
func NewInstance(typ string) Service {
|
||||
switch typ {
|
||||
case "NTFY":
|
||||
return new(NTFY)
|
||||
case "SCRIPT":
|
||||
return new(Script)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetInstance(typ string) Service {
|
||||
for _, svc := range allServices {
|
||||
if strings.ToLower(svc.GetType()) == strings.ToLower(typ) {
|
||||
|
@ -60,12 +60,6 @@ func (nm *Manager) GetService(prio int) *Service {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nm *Manager) RemoveService(prioToRemove int) {
|
||||
nm.services = slices.DeleteFunc(nm.services, func(svc Service) bool {
|
||||
return svc.GetPrio() == prioToRemove
|
||||
})
|
||||
}
|
||||
|
||||
func (nm *Manager) Send(problemID int, msg []byte, fn func(*Service, error)) (err error) {
|
||||
for i, service := range nm.services {
|
||||
nm.logger.Info("notification", "service", service.GetType(), "prio", service.GetPrio())
|
||||
|
@ -95,8 +95,6 @@ func (script Script) Send(problemID int, msg []byte) (err error) {
|
||||
|
||||
func (script *Script) Update(values url.Values) (err error) {
|
||||
updated := Script{}
|
||||
script.updated = &updated
|
||||
|
||||
updated.Prio, err = strconv.Atoi(values.Get("prio"))
|
||||
if err != nil {
|
||||
return werr.Wrap(err)
|
||||
@ -107,6 +105,8 @@ func (script *Script) Update(values url.Values) (err error) {
|
||||
return werr.New("Filename cannot be empty")
|
||||
}
|
||||
updated.Filename = strings.TrimSpace(givenFilename)
|
||||
|
||||
script.updated = &updated
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -116,22 +116,6 @@ func UpdateNotificationService(svc notification.Service) (created bool, err erro
|
||||
}
|
||||
return
|
||||
} // }}}
|
||||
func DeleteNotificationService(prio int) (err error) { // {{{
|
||||
_, err = service.Db.Conn.Exec(
|
||||
`
|
||||
DELETE FROM public.notification
|
||||
WHERE
|
||||
prio = $1
|
||||
|
||||
`,
|
||||
prio,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return werr.Wrap(err).WithData(struct{ Prio int }{prio})
|
||||
}
|
||||
return
|
||||
} // }}}
|
||||
|
||||
func AcknowledgeNotification(uuid string) (err error) { // {{{
|
||||
/*
|
||||
|
@ -26,7 +26,7 @@
|
||||
}
|
||||
#services {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, min-content);
|
||||
grid-template-columns: repeat(3, min-content);
|
||||
gap: 10px 24px;
|
||||
background-color: #2979b8;
|
||||
width: min-content;
|
||||
@ -41,6 +41,3 @@
|
||||
#services div {
|
||||
white-space: nowrap;
|
||||
}
|
||||
#services img.delete {
|
||||
height: 16px;
|
||||
}
|
||||
|
@ -26,7 +26,7 @@
|
||||
}
|
||||
#services {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, min-content);
|
||||
grid-template-columns: repeat(3, min-content);
|
||||
gap: 10px 24px;
|
||||
background-color: #333;
|
||||
width: min-content;
|
||||
@ -41,6 +41,3 @@
|
||||
#services div {
|
||||
white-space: nowrap;
|
||||
}
|
||||
#services img.delete {
|
||||
height: 16px;
|
||||
}
|
||||
|
@ -39,7 +39,7 @@
|
||||
|
||||
#services {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, min-content);
|
||||
grid-template-columns: repeat(3, min-content);
|
||||
gap: 10px 24px;
|
||||
background-color: @bg3;
|
||||
width: min-content;
|
||||
@ -55,8 +55,4 @@
|
||||
div {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
img.delete {
|
||||
height: 16px;
|
||||
}
|
||||
}
|
||||
|
@ -68,11 +68,6 @@
|
||||
const nType = select.value
|
||||
location.href = `/configuration/notification?type=${nType}`
|
||||
}
|
||||
function deleteNotification(prio) {
|
||||
if (!confirm(`Are you sure you want to delete notification with prio ${prio}?`))
|
||||
return
|
||||
location.href = `/configuration/notification/delete/${prio}`;
|
||||
}
|
||||
</script>
|
||||
|
||||
{{ block "page_label" . }}{{end}}
|
||||
@ -131,13 +126,11 @@
|
||||
<div class="header">Prio</div>
|
||||
<div class="header">Type</div>
|
||||
<div class="header">Target</div>
|
||||
<div></div>
|
||||
<div class="line"></div>
|
||||
{{ range .Data.NotificationServices }}
|
||||
<div><a href="/configuration/notification?prio={{ .GetPrio }}">{{ .GetPrio }}</a></div>
|
||||
<div><a href="/configuration/notification?prio={{ .GetPrio }}">{{ .GetType }}</a></div>
|
||||
<div><a href="/configuration/notification?prio={{ .GetPrio }}">{{ .String }}</a></div>
|
||||
<div><img onclick="deleteNotification({{ .GetPrio }})" class="delete" src="/images/{{ $version }}/{{ $theme }}/delete.svg"></div>
|
||||
{{ end }}
|
||||
</div>
|
||||
|
||||
|
@ -19,8 +19,8 @@ button {
|
||||
}
|
||||
</style>
|
||||
|
||||
<form action="/configuration/notification/update/{{ if .Data.Service.Exists }}{{ .Data.Service.GetPrio }}{{ else }}-1{{ end }}" method="post">
|
||||
<input type="hidden" name="type" value="SCRIPT">
|
||||
<form action="/configuration/notification/update/{{ .Data.Service.GetPrio }}" method="post">
|
||||
<input type="hidden" name="type" value="Script">
|
||||
<div class="grid">
|
||||
<div>Prio:</div>
|
||||
<input type="number" min=0 name="prio" value="{{ .Data.Service.GetPrio }}">
|
||||
|
Loading…
Reference in New Issue
Block a user