feat(tui): expose HTTP method and accepted status codes in monitor form
DB fields existed but were never surfaced in the TUI. Adds an HTTP Settings form group with method select (7 methods) and accepted codes input, visible only for HTTP monitors.
This commit is contained in:
+47
-21
@@ -21,20 +21,22 @@ var siteGroupStyle = lipgloss.NewStyle().
|
|||||||
Foreground(lipgloss.Color("#7D56F4"))
|
Foreground(lipgloss.Color("#7D56F4"))
|
||||||
|
|
||||||
type siteFormData struct {
|
type siteFormData struct {
|
||||||
Name string
|
Name string
|
||||||
SiteType string
|
SiteType string
|
||||||
URL string
|
URL string
|
||||||
Interval string
|
Method string
|
||||||
AlertID string
|
AcceptedCodes string
|
||||||
CheckSSL bool
|
Interval string
|
||||||
Threshold string
|
AlertID string
|
||||||
Retries string
|
CheckSSL bool
|
||||||
Hostname string
|
Threshold string
|
||||||
Port string
|
Retries string
|
||||||
Timeout string
|
Hostname string
|
||||||
Description string
|
Port string
|
||||||
IgnoreTLS bool
|
Timeout string
|
||||||
GroupID string
|
Description string
|
||||||
|
IgnoreTLS bool
|
||||||
|
GroupID string
|
||||||
}
|
}
|
||||||
|
|
||||||
func latencySparkline(latencies []time.Duration, width int) string {
|
func latencySparkline(latencies []time.Duration, width int) string {
|
||||||
@@ -277,13 +279,15 @@ func (m Model) viewSitesTab() string {
|
|||||||
|
|
||||||
func (m *Model) initSiteHuhForm() tea.Cmd {
|
func (m *Model) initSiteHuhForm() tea.Cmd {
|
||||||
m.siteFormData = &siteFormData{
|
m.siteFormData = &siteFormData{
|
||||||
SiteType: "http",
|
SiteType: "http",
|
||||||
Interval: "60",
|
Method: "GET",
|
||||||
Threshold: "7",
|
AcceptedCodes: "200-299",
|
||||||
Retries: "0",
|
Interval: "60",
|
||||||
Timeout: "5",
|
Threshold: "7",
|
||||||
Port: "0",
|
Retries: "0",
|
||||||
GroupID: "0",
|
Timeout: "5",
|
||||||
|
Port: "0",
|
||||||
|
GroupID: "0",
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.editID > 0 {
|
if m.editID > 0 {
|
||||||
@@ -303,6 +307,8 @@ func (m *Model) initSiteHuhForm() tea.Cmd {
|
|||||||
m.siteFormData.Description = site.Description
|
m.siteFormData.Description = site.Description
|
||||||
m.siteFormData.IgnoreTLS = site.IgnoreTLS
|
m.siteFormData.IgnoreTLS = site.IgnoreTLS
|
||||||
m.siteFormData.GroupID = strconv.Itoa(site.ParentID)
|
m.siteFormData.GroupID = strconv.Itoa(site.ParentID)
|
||||||
|
m.siteFormData.Method = site.Method
|
||||||
|
m.siteFormData.AcceptedCodes = site.AcceptedCodes
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -432,6 +438,24 @@ func (m *Model) initSiteHuhForm() tea.Cmd {
|
|||||||
).Title("Connection").WithHideFunc(func() bool {
|
).Title("Connection").WithHideFunc(func() bool {
|
||||||
return m.siteFormData.SiteType == "group"
|
return m.siteFormData.SiteType == "group"
|
||||||
}),
|
}),
|
||||||
|
huh.NewGroup(
|
||||||
|
huh.NewSelect[string]().Title("HTTP Method").
|
||||||
|
Options(
|
||||||
|
huh.NewOption("GET", "GET"),
|
||||||
|
huh.NewOption("POST", "POST"),
|
||||||
|
huh.NewOption("PUT", "PUT"),
|
||||||
|
huh.NewOption("PATCH", "PATCH"),
|
||||||
|
huh.NewOption("DELETE", "DELETE"),
|
||||||
|
huh.NewOption("HEAD", "HEAD"),
|
||||||
|
huh.NewOption("OPTIONS", "OPTIONS"),
|
||||||
|
).Value(&m.siteFormData.Method),
|
||||||
|
huh.NewInput().Title("Accepted Status Codes").
|
||||||
|
Placeholder("200-299").
|
||||||
|
Description("Ranges (200-299) and singles (301) separated by commas").
|
||||||
|
Value(&m.siteFormData.AcceptedCodes),
|
||||||
|
).Title("HTTP Settings").WithHideFunc(func() bool {
|
||||||
|
return m.siteFormData.SiteType != "http"
|
||||||
|
}),
|
||||||
huh.NewGroup(
|
huh.NewGroup(
|
||||||
huh.NewConfirm().Title("Monitor SSL Certificate?").
|
huh.NewConfirm().Title("Monitor SSL Certificate?").
|
||||||
Value(&m.siteFormData.CheckSSL),
|
Value(&m.siteFormData.CheckSSL),
|
||||||
@@ -503,6 +527,8 @@ func (m *Model) submitSiteForm() {
|
|||||||
Description: d.Description,
|
Description: d.Description,
|
||||||
IgnoreTLS: d.IgnoreTLS,
|
IgnoreTLS: d.IgnoreTLS,
|
||||||
ParentID: groupID,
|
ParentID: groupID,
|
||||||
|
Method: d.Method,
|
||||||
|
AcceptedCodes: d.AcceptedCodes,
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.editID > 0 {
|
if m.editID > 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user