check / check (push) Successful in 3m11s
A database target's archive expiry was typed by hand as never or a raw duration such as 720h, and the target list showed it back raw. Adding or editing a database target now offers the new-webhook page's list of choices (never, 1h, 12h, 24h, 30d, 90d, 365d), defined once and shared by all three forms. The edit form starts on the stored expiry, or on the submitted one after a refused save; a stored value outside the choices is listed under its own value, so saving unchanged keeps it. The target list shows the expiry in plain units: "30 days", "12 hours", "never". Model: opus-5-5
59 lines
1.7 KiB
Go
59 lines
1.7 KiB
Go
package handlers
|
|
|
|
const (
|
|
// archiveExpiryNever is the archive expiry that keeps archived
|
|
// events forever. A stored empty expiry means the same.
|
|
archiveExpiryNever = "never"
|
|
|
|
// tmplKeyArchiveExpiryChoices is the template data key for the
|
|
// entries of a page's archive expiry select.
|
|
tmplKeyArchiveExpiryChoices = "ArchiveExpiryChoices"
|
|
)
|
|
|
|
// archiveExpiryChoice is one entry of a database target's archive
|
|
// expiry select: the expiry stored, the label shown, and whether the
|
|
// select starts on it.
|
|
type archiveExpiryChoice struct {
|
|
Value string
|
|
Label string
|
|
Selected bool
|
|
}
|
|
|
|
// archiveExpiryChoices lists the archive expiries offered by the new
|
|
// webhook page, the add target form and the target edit form.
|
|
func archiveExpiryChoices() []archiveExpiryChoice {
|
|
return []archiveExpiryChoice{
|
|
{Value: archiveExpiryNever, Label: archiveExpiryNever},
|
|
{Value: "1h", Label: "1h"},
|
|
{Value: "12h", Label: "12h"},
|
|
{Value: "24h", Label: "24h"},
|
|
{Value: "720h", Label: "30d"},
|
|
{Value: "2160h", Label: "90d"},
|
|
{Value: "8760h", Label: "365d"},
|
|
}
|
|
}
|
|
|
|
// archiveExpiryOptions returns the choices with expiry selected; an
|
|
// empty expiry selects never. An expiry that is not one of the
|
|
// choices comes first as its own selected entry, so saving the form
|
|
// unchanged keeps it.
|
|
func archiveExpiryOptions(expiry string) []archiveExpiryChoice {
|
|
if expiry == "" {
|
|
expiry = archiveExpiryNever
|
|
}
|
|
|
|
options := archiveExpiryChoices()
|
|
|
|
for i := range options {
|
|
if options[i].Value == expiry {
|
|
options[i].Selected = true
|
|
|
|
return options
|
|
}
|
|
}
|
|
|
|
own := archiveExpiryChoice{Value: expiry, Label: expiry, Selected: true}
|
|
|
|
return append([]archiveExpiryChoice{own}, options...)
|
|
}
|