Added description to Pushover notification service.

This commit is contained in:
Magnus Åhall 2024-07-04 19:37:18 +02:00
parent 414ca0a95c
commit 06f88f697c
2 changed files with 27 additions and 9 deletions

View File

@ -17,6 +17,7 @@ import (
) )
type Pushover struct { type Pushover struct {
Description string
UserKey string `json:"user_key"` UserKey string `json:"user_key"`
APIKey string `json:"api_key"` APIKey string `json:"api_key"`
DeviceName string `json:"device_name"` DeviceName string `json:"device_name"`
@ -70,6 +71,10 @@ func (po Pushover) Exists() bool {
} }
func (po *Pushover) String() string { func (po *Pushover) String() string {
if po.Description != "" {
return po.Description
}
return fmt.Sprintf("%s, %s", po.UserKey, po.APIKey) return fmt.Sprintf("%s, %s", po.UserKey, po.APIKey)
} }
@ -135,23 +140,30 @@ func (po *Pushover) Update(values url.Values) (err error) {
updated := Pushover{} updated := Pushover{}
po.updated = &updated po.updated = &updated
// Prio
updated.Prio, err = strconv.Atoi(values.Get("prio")) updated.Prio, err = strconv.Atoi(values.Get("prio"))
if err != nil { if err != nil {
return werr.Wrap(err) return werr.Wrap(err)
} }
// Description
updated.Description = strings.TrimSpace(values.Get("description"))
// API (application) key
givenAPIKey := values.Get("api_key") givenAPIKey := values.Get("api_key")
if strings.TrimSpace(givenAPIKey) == "" { if strings.TrimSpace(givenAPIKey) == "" {
return werr.New("API key cannot be empty") return werr.New("API key cannot be empty")
} }
updated.APIKey = strings.TrimSpace(givenAPIKey) updated.APIKey = strings.TrimSpace(givenAPIKey)
// User key
givenUserKey := values.Get("user_key") givenUserKey := values.Get("user_key")
if strings.TrimSpace(givenUserKey) == "" { if strings.TrimSpace(givenUserKey) == "" {
return werr.New("User key cannot be empty") return werr.New("User key cannot be empty")
} }
updated.UserKey = strings.TrimSpace(givenUserKey) updated.UserKey = strings.TrimSpace(givenUserKey)
// Device name
updated.DeviceName = strings.TrimSpace(values.Get("device_name")) updated.DeviceName = strings.TrimSpace(values.Get("device_name"))
return return
} }
@ -163,6 +175,7 @@ func (po *Pushover) Updated() Service {
func (po *Pushover) Commit() { func (po *Pushover) Commit() {
updatedPushover := po.updated.(*Pushover) updatedPushover := po.updated.(*Pushover)
po.Prio = updatedPushover.Prio po.Prio = updatedPushover.Prio
po.Description = updatedPushover.Description
po.APIKey = updatedPushover.APIKey po.APIKey = updatedPushover.APIKey
po.UserKey = updatedPushover.UserKey po.UserKey = updatedPushover.UserKey
po.DeviceName = updatedPushover.DeviceName po.DeviceName = updatedPushover.DeviceName
@ -170,10 +183,12 @@ func (po *Pushover) Commit() {
func (po Pushover) JSON() []byte { func (po Pushover) JSON() []byte {
data := struct { data := struct {
Description string
APIKey string `json:"api_key"` APIKey string `json:"api_key"`
UserKey string `json:"user_key"` UserKey string `json:"user_key"`
DeviceName string `json:"device_name"` DeviceName string `json:"device_name"`
}{ }{
po.Description,
po.APIKey, po.APIKey,
po.UserKey, po.UserKey,
po.DeviceName, po.DeviceName,

View File

@ -29,13 +29,16 @@ div.grid > div {
<div>Prio:</div> <div>Prio:</div>
<input type="number" min=0 name="prio" value="{{ .Data.Service.GetPrio }}"> <input type="number" min=0 name="prio" value="{{ .Data.Service.GetPrio }}">
<div>User key:</div> <div>Description</div>
<input type="text" name="description" value="{{ .Data.Service.Description }}" style="width: 100%">
<div>User key: <span class="error">*</span></div>
<input type="text" name="user_key" value="{{ .Data.Service.UserKey }}" style="width: 100%"> <input type="text" name="user_key" value="{{ .Data.Service.UserKey }}" style="width: 100%">
<div>API (application) key:</div> <div>API (application) key: <span class="error">*</span></div>
<input type="text" name="api_key" value="{{ .Data.Service.APIKey }}" style="width: 100%"> <input type="text" name="api_key" value="{{ .Data.Service.APIKey }}" style="width: 100%">
<div>Device name (optional):</div> <div>Device name:</div>
<input type="text" name="device_name" value="{{ .Data.Service.DeviceName }}" style="width: 100%"> <input type="text" name="device_name" value="{{ .Data.Service.DeviceName }}" style="width: 100%">
<button style="grid-column: 1 / -1; width: min-content;">OK</button> <button style="grid-column: 1 / -1; width: min-content;">OK</button>