check / check (push) Successful in 3m25s
Adding or editing a database target now offers the archive expiry choices of the new webhook page (never, 1h, 12h, 24h, 30d, 90d, 365d) in place of a text field. The list is defined once, in internal/handlers/archive_expiry.go, and all three forms render it. The edit form starts on the stored expiry; one that is not among the choices is listed first as its own entry, so saving unchanged keeps it. The target list shows the expiry in plain units, such as "30 days" or "12 hours", or "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...)
|
|
}
|