diff --git a/main.go b/main.go index 8094e2d..6e368a1 100644 --- a/main.go +++ b/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) -} // }}} diff --git a/notification/factory.go b/notification/factory.go index 16c35d4..4c7e25f 100644 --- a/notification/factory.go +++ b/notification/factory.go @@ -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) { diff --git a/notification/pkg.go b/notification/pkg.go index efa6712..dba9747 100644 --- a/notification/pkg.go +++ b/notification/pkg.go @@ -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()) diff --git a/notification/script.go b/notification/script.go index 7eb4d5b..ab6492f 100644 --- a/notification/script.go +++ b/notification/script.go @@ -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 } diff --git a/notification_manager.go b/notification_manager.go index 1690d8e..74b2691 100644 --- a/notification_manager.go +++ b/notification_manager.go @@ -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) { // {{{ /* diff --git a/static/css/default_light/configuration.css b/static/css/default_light/configuration.css index 8de027f..715f085 100644 --- a/static/css/default_light/configuration.css +++ b/static/css/default_light/configuration.css @@ -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; -} diff --git a/static/css/gruvbox/configuration.css b/static/css/gruvbox/configuration.css index 2392238..063f37d 100644 --- a/static/css/gruvbox/configuration.css +++ b/static/css/gruvbox/configuration.css @@ -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; -} diff --git a/static/less/configuration.less b/static/less/configuration.less index 153ec3d..b1c41fd 100644 --- a/static/less/configuration.less +++ b/static/less/configuration.less @@ -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; - } } diff --git a/views/pages/configuration.gotmpl b/views/pages/configuration.gotmpl index 0561322..aab74c3 100644 --- a/views/pages/configuration.gotmpl +++ b/views/pages/configuration.gotmpl @@ -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}`; - } {{ block "page_label" . }}{{end}} @@ -131,13 +126,11 @@