Harden core packages and add interactive CLI config builder (rud config/validate/test)
This commit is contained in:
parent
d37503c863
commit
99e24be6c9
29 changed files with 6763 additions and 165 deletions
651
internal/builder/editors_page.go
Normal file
651
internal/builder/editors_page.go
Normal file
|
|
@ -0,0 +1,651 @@
|
|||
package builder
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"git.gsdistance.org/tyuXX/RUD/internal/config"
|
||||
)
|
||||
|
||||
func editPage(ui *UI, cfg *config.Config) error {
|
||||
for {
|
||||
sub := fmt.Sprintf("Title: %q | Elements: %d | BG: %s | Up: %s",
|
||||
cfg.Page.Title, len(cfg.Page.Elements), cfg.Page.Theme.BgColor, cfg.Page.Theme.UpColor)
|
||||
opts := []Option{
|
||||
{Label: "Page HTML title", Description: cfg.Page.Title},
|
||||
{Label: "Apply theme preset", Description: "Dark Minimal, Clean Light, Terminal Green, Nord, High Contrast"},
|
||||
{Label: "Customize theme colors & typography", Description: "Edit all 14 CSS theme properties"},
|
||||
{Label: "Manage page elements", Description: fmt.Sprintf("%d element(s): %s", len(cfg.Page.Elements), summarizeElements(cfg.Page.Elements))},
|
||||
{Label: "Back to main hub"},
|
||||
}
|
||||
|
||||
idx, ok, err := ui.Select("Page & Theme", sub, opts, len(opts)-1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !ok || idx == len(opts)-1 {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch idx {
|
||||
case 0:
|
||||
t, err := ui.PromptString("Page HTML <title>", cfg.Page.Title, "", false, requireNonEmpty("title"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cfg.Page.Title = t
|
||||
case 1:
|
||||
if err := applyThemePresetFlow(ui, &cfg.Page); err != nil {
|
||||
return err
|
||||
}
|
||||
case 2:
|
||||
if err := editCustomTheme(ui, &cfg.Page.Theme); err != nil {
|
||||
return err
|
||||
}
|
||||
case 3:
|
||||
if err := editPageElements(ui, cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func applyThemePresetFlow(ui *UI, page *config.PageConfig) error {
|
||||
presets := ThemePresets()
|
||||
opts := make([]Option, len(presets)+1)
|
||||
for i, p := range presets {
|
||||
opts[i] = Option{Label: p.Name, Description: p.Description}
|
||||
}
|
||||
opts[len(presets)] = Option{Label: "Cancel"}
|
||||
|
||||
idx, ok, err := ui.Select("Choose Theme Preset", "", opts, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !ok || idx == len(presets) {
|
||||
return nil
|
||||
}
|
||||
customCSS := page.Theme.CustomCSS
|
||||
page.Theme = presets[idx].Theme
|
||||
if customCSS != "" && page.Theme.CustomCSS == "" {
|
||||
page.Theme.CustomCSS = customCSS
|
||||
}
|
||||
ui.Ok("Applied theme preset: " + presets[idx].Name)
|
||||
return nil
|
||||
}
|
||||
|
||||
func editCustomTheme(ui *UI, theme *config.ThemeConfig) error {
|
||||
for {
|
||||
opts := []Option{
|
||||
{Label: "Background & surface colors", Description: fmt.Sprintf("bg=%s card=%s border=%s", theme.BgColor, theme.CardBgColor, theme.BorderColor)},
|
||||
{Label: "Text & accent colors", Description: fmt.Sprintf("text=%s muted=%s accent=%s", theme.TextColor, theme.MutedTextColor, theme.AccentColor)},
|
||||
{Label: "Status state colors", Description: fmt.Sprintf("up=%s degraded=%s down=%s pending=%s", theme.UpColor, theme.DegradedColor, theme.DownColor, theme.PendingColor)},
|
||||
{Label: "Typography & layout", Description: fmt.Sprintf("font=%q max_width=%s radius=%s", truncateDesc(theme.FontFamily, 24), theme.MaxWidth, theme.BorderRadius)},
|
||||
{Label: "Custom CSS", Description: truncateDesc(theme.CustomCSS, 40)},
|
||||
{Label: "Done"},
|
||||
}
|
||||
idx, ok, err := ui.Select("Customize Theme", "", opts, len(opts)-1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !ok || idx == len(opts)-1 {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch idx {
|
||||
case 0:
|
||||
if theme.BgColor, err = ui.PromptString("bg_color", theme.BgColor, "CSS color", false, requireNonEmpty("bg_color")); err != nil {
|
||||
return err
|
||||
}
|
||||
if theme.CardBgColor, err = ui.PromptString("card_bg_color", theme.CardBgColor, "CSS color", false, requireNonEmpty("card_bg_color")); err != nil {
|
||||
return err
|
||||
}
|
||||
if theme.BorderColor, err = ui.PromptString("border_color", theme.BorderColor, "CSS color", false, requireNonEmpty("border_color")); err != nil {
|
||||
return err
|
||||
}
|
||||
case 1:
|
||||
if theme.TextColor, err = ui.PromptString("text_color", theme.TextColor, "CSS color", false, requireNonEmpty("text_color")); err != nil {
|
||||
return err
|
||||
}
|
||||
if theme.MutedTextColor, err = ui.PromptString("muted_text_color", theme.MutedTextColor, "CSS color", false, requireNonEmpty("muted_text_color")); err != nil {
|
||||
return err
|
||||
}
|
||||
if theme.AccentColor, err = ui.PromptString("accent_color", theme.AccentColor, "CSS color", false, requireNonEmpty("accent_color")); err != nil {
|
||||
return err
|
||||
}
|
||||
case 2:
|
||||
if theme.UpColor, err = ui.PromptString("up_color", theme.UpColor, "CSS color", false, requireNonEmpty("up_color")); err != nil {
|
||||
return err
|
||||
}
|
||||
if theme.DegradedColor, err = ui.PromptString("degraded_color", theme.DegradedColor, "CSS color", false, requireNonEmpty("degraded_color")); err != nil {
|
||||
return err
|
||||
}
|
||||
if theme.DownColor, err = ui.PromptString("down_color", theme.DownColor, "CSS color", false, requireNonEmpty("down_color")); err != nil {
|
||||
return err
|
||||
}
|
||||
if theme.PendingColor, err = ui.PromptString("pending_color", theme.PendingColor, "CSS color", false, requireNonEmpty("pending_color")); err != nil {
|
||||
return err
|
||||
}
|
||||
case 3:
|
||||
if theme.FontFamily, err = ui.PromptString("font_family", theme.FontFamily, "CSS font-family", false, requireNonEmpty("font_family")); err != nil {
|
||||
return err
|
||||
}
|
||||
if theme.MaxWidth, err = ui.PromptString("max_width", theme.MaxWidth, "e.g. 820px", false, requireNonEmpty("max_width")); err != nil {
|
||||
return err
|
||||
}
|
||||
if theme.BorderRadius, err = ui.PromptString("border_radius", theme.BorderRadius, "e.g. 2px, 6px", false, requireNonEmpty("border_radius")); err != nil {
|
||||
return err
|
||||
}
|
||||
case 4:
|
||||
if theme.CustomCSS, err = ui.PromptString("custom_css", theme.CustomCSS, "raw CSS appended to <style>", true, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func editPageElements(ui *UI, cfg *config.Config) error {
|
||||
for {
|
||||
sub := fmt.Sprintf("%d element(s): %s", len(cfg.Page.Elements), summarizeElements(cfg.Page.Elements))
|
||||
opts := []Option{
|
||||
{Label: "Add page element", Description: "header, status_banner, summary_cards, monitor_group, custom_block, divider"},
|
||||
}
|
||||
if len(cfg.Page.Elements) > 0 {
|
||||
opts = append(opts,
|
||||
Option{Label: "Edit page element"},
|
||||
Option{Label: "Duplicate page element"},
|
||||
Option{Label: "Reorder page elements", Description: "Move elements up or down"},
|
||||
Option{Label: "Delete page element"},
|
||||
)
|
||||
}
|
||||
opts = append(opts, Option{Label: "Back"})
|
||||
|
||||
idx, ok, err := ui.Select("Page Elements", sub, opts, len(opts)-1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !ok || opts[idx].Label == "Back" {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch opts[idx].Label {
|
||||
case "Add page element":
|
||||
if err := addPageElementFlow(ui, cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
case "Edit page element":
|
||||
eIdx, eOK, err := pickPageElement(ui, cfg.Page.Elements, "Select element to edit")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if eOK {
|
||||
if err := editSinglePageElement(ui, cfg, &cfg.Page.Elements[eIdx]); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
case "Duplicate page element":
|
||||
eIdx, eOK, err := pickPageElement(ui, cfg.Page.Elements, "Select element to duplicate")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if eOK {
|
||||
cp := clonePageElement(cfg.Page.Elements[eIdx])
|
||||
cfg.Page.Elements = append(cfg.Page.Elements, cp)
|
||||
ui.Ok("Duplicated page element.")
|
||||
}
|
||||
case "Reorder page elements":
|
||||
if err := reorderPageElements(ui, &cfg.Page); err != nil {
|
||||
return err
|
||||
}
|
||||
case "Delete page element":
|
||||
eIdx, eOK, err := pickPageElement(ui, cfg.Page.Elements, "Select element to delete")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if eOK {
|
||||
cfg.Page.Elements = append(cfg.Page.Elements[:eIdx], cfg.Page.Elements[eIdx+1:]...)
|
||||
ui.Ok("Deleted page element.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func pickPageElement(ui *UI, elems []config.PageElement, title string) (int, bool, error) {
|
||||
opts := make([]Option, len(elems))
|
||||
for i, el := range elems {
|
||||
opts[i] = Option{
|
||||
Label: fmt.Sprintf("[%d] %s", i+1, el.Type),
|
||||
Description: elementDescription(el),
|
||||
}
|
||||
}
|
||||
return ui.Select(title, "", opts, -1)
|
||||
}
|
||||
|
||||
func reorderPageElements(ui *UI, page *config.PageConfig) error {
|
||||
for {
|
||||
if len(page.Elements) < 2 {
|
||||
ui.Info("Need at least 2 elements to reorder.")
|
||||
return nil
|
||||
}
|
||||
eIdx, ok, err := pickPageElement(ui, page.Elements, "Pick element to move (Esc/0 when done)")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
dirOpts := []Option{{Label: "Move up"}, {Label: "Move down"}, {Label: "Cancel"}}
|
||||
dIdx, dOK, err := ui.Select("Move "+page.Elements[eIdx].Type, "", dirOpts, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !dOK || dIdx == 2 {
|
||||
continue
|
||||
}
|
||||
if dIdx == 0 && eIdx > 0 {
|
||||
page.Elements[eIdx-1], page.Elements[eIdx] = page.Elements[eIdx], page.Elements[eIdx-1]
|
||||
} else if dIdx == 1 && eIdx < len(page.Elements)-1 {
|
||||
page.Elements[eIdx+1], page.Elements[eIdx] = page.Elements[eIdx], page.Elements[eIdx+1]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func addPageElementFlow(ui *UI, cfg *config.Config) error {
|
||||
typeOpts := []Option{
|
||||
{Label: "header", Description: "Page heading, subtitle, live indicator & updated timestamp"},
|
||||
{Label: "status_banner", Description: "Overall status bar colored by system state"},
|
||||
{Label: "summary_cards", Description: "Compact metric grid (total, up, degraded, down, uptime, latency)"},
|
||||
{Label: "monitor_group", Description: "List or grid of monitors with history bars & toggles"},
|
||||
{Label: "custom_block", Description: "Static notice, maintenance note, or informational banner"},
|
||||
{Label: "divider", Description: "Horizontal separator rule"},
|
||||
{Label: "Cancel"},
|
||||
}
|
||||
idx, ok, err := ui.Select("Add Page Element", "", typeOpts, 3)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !ok || idx == len(typeOpts)-1 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var el config.PageElement
|
||||
switch typeOpts[idx].Label {
|
||||
case "header":
|
||||
el = config.PageElement{
|
||||
Type: "header",
|
||||
Title: cfg.Page.Title,
|
||||
Subtitle: "System status",
|
||||
Align: "split",
|
||||
ShowLastUpdated: true,
|
||||
ShowLiveIndicator: true,
|
||||
}
|
||||
case "status_banner":
|
||||
el = config.PageElement{
|
||||
Type: "status_banner",
|
||||
Messages: map[string]string{
|
||||
"up": "All systems operational",
|
||||
"degraded": "Some systems degraded",
|
||||
"down": "One or more systems down",
|
||||
"pending": "Checking systems...",
|
||||
},
|
||||
ShowOverallUptime: true,
|
||||
ShowCounts: true,
|
||||
}
|
||||
case "summary_cards":
|
||||
el = config.PageElement{
|
||||
Type: "summary_cards",
|
||||
Metrics: []string{"total", "up", "degraded", "down", "overall_uptime", "avg_latency"},
|
||||
}
|
||||
case "monitor_group":
|
||||
el = config.PageElement{
|
||||
Type: "monitor_group",
|
||||
Title: "Services",
|
||||
Monitors: []string{"*"},
|
||||
Layout: "list",
|
||||
Display: &config.MonitorDisplayConfig{
|
||||
ShowBar: config.BoolPtr(true),
|
||||
BarTicks: 40,
|
||||
ShowUptime: config.BoolPtr(true),
|
||||
ShowLatency: config.BoolPtr(true),
|
||||
ShowStatusBadge: config.BoolPtr(true),
|
||||
ShowMethod: config.BoolPtr(true),
|
||||
ShowDescription: config.BoolPtr(true),
|
||||
},
|
||||
}
|
||||
case "custom_block":
|
||||
el = config.PageElement{
|
||||
Type: "custom_block",
|
||||
Title: "Notice",
|
||||
Style: "info",
|
||||
}
|
||||
case "divider":
|
||||
cfg.Page.Elements = append(cfg.Page.Elements, config.PageElement{Type: "divider"})
|
||||
ui.Ok("Added divider element.")
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := editSinglePageElement(ui, cfg, &el); err != nil {
|
||||
return err
|
||||
}
|
||||
cfg.Page.Elements = append(cfg.Page.Elements, el)
|
||||
ui.Ok("Added " + el.Type + " element.")
|
||||
return nil
|
||||
}
|
||||
|
||||
func editSinglePageElement(ui *UI, cfg *config.Config, el *config.PageElement) error {
|
||||
switch strings.ToLower(strings.TrimSpace(el.Type)) {
|
||||
case "header":
|
||||
var err error
|
||||
if el.Title, err = ui.PromptString("Header title", el.Title, "", true, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
if el.Subtitle, err = ui.PromptString("Header subtitle", el.Subtitle, "", true, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
alignOpts := []Option{{Label: "split"}, {Label: "left"}, {Label: "center"}}
|
||||
defA := 0
|
||||
for i, o := range alignOpts {
|
||||
if strings.EqualFold(o.Label, el.Align) {
|
||||
defA = i
|
||||
break
|
||||
}
|
||||
}
|
||||
aIdx, aOK, err := ui.Select("Header Alignment", "", alignOpts, defA)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if aOK {
|
||||
el.Align = alignOpts[aIdx].Label
|
||||
}
|
||||
if el.ShowLastUpdated, err = ui.Confirm("Show last-updated timestamp?", el.ShowLastUpdated); err != nil {
|
||||
return err
|
||||
}
|
||||
if el.ShowLiveIndicator, err = ui.Confirm("Show live indicator dot?", el.ShowLiveIndicator); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
case "status_banner":
|
||||
if el.Messages == nil {
|
||||
el.Messages = map[string]string{}
|
||||
}
|
||||
for _, st := range []struct{ key, def string }{
|
||||
{"up", "All systems operational"},
|
||||
{"degraded", "Some systems are degraded"},
|
||||
{"down", "One or more systems are down"},
|
||||
{"pending", "Checking systems..."},
|
||||
} {
|
||||
cur := el.Messages[st.key]
|
||||
if cur == "" {
|
||||
cur = st.def
|
||||
}
|
||||
val, err := ui.PromptString("Banner message when "+st.key, cur, "", false, requireNonEmpty(st.key+" message"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
el.Messages[st.key] = val
|
||||
}
|
||||
var err error
|
||||
if el.ShowOverallUptime, err = ui.Confirm("Show overall uptime percentage?", el.ShowOverallUptime); err != nil {
|
||||
return err
|
||||
}
|
||||
if el.ShowCounts, err = ui.Confirm("Show up/total monitor counts?", el.ShowCounts); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
case "summary_cards", "summary":
|
||||
t, err := ui.PromptString("Section title (optional)", el.Title, "", true, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
el.Title = t
|
||||
|
||||
allMetrics := []Option{
|
||||
{Label: "total", Description: "Total monitor count"},
|
||||
{Label: "up", Description: "Healthy monitor count"},
|
||||
{Label: "degraded", Description: "Degraded monitor count"},
|
||||
{Label: "down", Description: "Down monitor count"},
|
||||
{Label: "overall_uptime", Description: "Average uptime percentage"},
|
||||
{Label: "avg_latency", Description: "Average check latency"},
|
||||
}
|
||||
curSet := make(map[string]bool)
|
||||
for _, m := range el.Metrics {
|
||||
curSet[strings.ToLower(strings.TrimSpace(m))] = true
|
||||
}
|
||||
pre := make(map[int]bool)
|
||||
for i, o := range allMetrics {
|
||||
if len(curSet) == 0 || curSet[o.Label] {
|
||||
pre[i] = true
|
||||
}
|
||||
}
|
||||
indices, mOK, err := ui.MultiSelect("Summary Card Metrics", "", allMetrics, pre)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if mOK && len(indices) > 0 {
|
||||
selected := make([]string, 0, len(indices))
|
||||
for _, idx := range indices {
|
||||
selected = append(selected, allMetrics[idx].Label)
|
||||
}
|
||||
el.Metrics = selected
|
||||
}
|
||||
|
||||
case "monitor_group", "monitors":
|
||||
var err error
|
||||
if el.Title, err = ui.PromptString("Group title", el.Title, "", true, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
if el.Description, err = ui.PromptString("Group description", el.Description, "", true, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Monitor multi-select
|
||||
mons, mOK, err := selectConditionMonitors(ui, cfg, el.Monitors)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if mOK {
|
||||
el.Monitors = mons
|
||||
}
|
||||
|
||||
layoutOpts := []Option{{Label: "list", Description: "Vertical stack"}, {Label: "grid", Description: "Responsive multi-column grid"}}
|
||||
defL := 0
|
||||
if strings.EqualFold(el.Layout, "grid") {
|
||||
defL = 1
|
||||
}
|
||||
lIdx, lOK, err := ui.Select("Monitor Group Layout", "", layoutOpts, defL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if lOK {
|
||||
el.Layout = layoutOpts[lIdx].Label
|
||||
}
|
||||
|
||||
if el.Display == nil {
|
||||
el.Display = &config.MonitorDisplayConfig{}
|
||||
}
|
||||
if err := editMonitorDisplayConfig(ui, el.Display); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
case "custom_block", "text":
|
||||
var err error
|
||||
if el.Title, err = ui.PromptString("Block title", el.Title, "", true, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
if el.Content, err = ui.PromptString("Block content", el.Content, "", false, requireNonEmpty("content")); err != nil {
|
||||
return err
|
||||
}
|
||||
styleOpts := []Option{{Label: "neutral"}, {Label: "info"}, {Label: "warning"}, {Label: "danger"}}
|
||||
defS := 0
|
||||
for i, o := range styleOpts {
|
||||
if strings.EqualFold(o.Label, el.Style) {
|
||||
defS = i
|
||||
break
|
||||
}
|
||||
}
|
||||
sIdx, sOK, err := ui.Select("Block Style", "", styleOpts, defS)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if sOK {
|
||||
el.Style = styleOpts[sIdx].Label
|
||||
}
|
||||
|
||||
case "divider":
|
||||
ui.Info("Divider elements have no configurable fields.")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func editMonitorDisplayConfig(ui *UI, d *config.MonitorDisplayConfig) error {
|
||||
toggleDefs := []struct {
|
||||
label string
|
||||
desc string
|
||||
ptr **bool
|
||||
def bool
|
||||
}{
|
||||
{"show_bar", "History status bar", &d.ShowBar, true},
|
||||
{"show_uptime", "Uptime percentage", &d.ShowUptime, true},
|
||||
{"show_latency", "Latest latency ms", &d.ShowLatency, true},
|
||||
{"show_status_badge", "Status badge pill", &d.ShowStatusBadge, true},
|
||||
{"show_method", "Check method tag (HTTP/TCP/etc.)", &d.ShowMethod, true},
|
||||
{"show_target", "Monitor target URL/host", &d.ShowTarget, false},
|
||||
{"show_description", "Monitor description line", &d.ShowDescription, true},
|
||||
{"show_message", "Latest check result/error message", &d.ShowMessage, false},
|
||||
{"show_last_checked", "Last checked UTC timestamp", &d.ShowLastChecked, false},
|
||||
}
|
||||
|
||||
opts := make([]Option, len(toggleDefs))
|
||||
pre := make(map[int]bool, len(toggleDefs))
|
||||
for i, td := range toggleDefs {
|
||||
opts[i] = Option{Label: td.label, Description: td.desc}
|
||||
val := td.def
|
||||
if *td.ptr != nil {
|
||||
val = **td.ptr
|
||||
}
|
||||
if val {
|
||||
pre[i] = true
|
||||
}
|
||||
}
|
||||
|
||||
indices, ok, err := ui.MultiSelect("Monitor Display Flags", "Toggle which data points are visible in this group", opts, pre)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if ok {
|
||||
selected := make(map[int]bool, len(indices))
|
||||
for _, idx := range indices {
|
||||
selected[idx] = true
|
||||
}
|
||||
for i, td := range toggleDefs {
|
||||
*td.ptr = config.BoolPtr(selected[i])
|
||||
}
|
||||
}
|
||||
|
||||
if d.ShowBar == nil || *d.ShowBar {
|
||||
curTicks := d.BarTicks
|
||||
if curTicks <= 0 {
|
||||
curTicks = 40
|
||||
}
|
||||
ticks, err := ui.PromptInt("History bar ticks", curTicks, 1, 200)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
d.BarTicks = ticks
|
||||
}
|
||||
|
||||
editLabels, err := ui.Confirm("Customize status badge labels (up/degraded/down/pending)?", len(d.CustomLabels) > 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if editLabels {
|
||||
lbls, err := ui.EditStringMap("Custom Status Labels", d.CustomLabels)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
d.CustomLabels = lbls
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func summarizeElements(elems []config.PageElement) string {
|
||||
if len(elems) == 0 {
|
||||
return "none"
|
||||
}
|
||||
parts := make([]string, len(elems))
|
||||
for i, el := range elems {
|
||||
parts[i] = el.Type
|
||||
}
|
||||
return strings.Join(parts, " -> ")
|
||||
}
|
||||
|
||||
func elementDescription(el config.PageElement) string {
|
||||
switch strings.ToLower(el.Type) {
|
||||
case "header":
|
||||
return fmt.Sprintf("title=%q align=%s", el.Title, el.Align)
|
||||
case "monitor_group", "monitors":
|
||||
return fmt.Sprintf("title=%q monitors=%v layout=%s", el.Title, el.Monitors, el.Layout)
|
||||
case "summary_cards", "summary":
|
||||
return strings.Join(el.Metrics, ", ")
|
||||
case "custom_block", "text":
|
||||
return fmt.Sprintf("title=%q style=%s", el.Title, el.Style)
|
||||
case "status_banner":
|
||||
return fmt.Sprintf("counts=%v uptime=%v", el.ShowCounts, el.ShowOverallUptime)
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func clonePageElement(el config.PageElement) config.PageElement {
|
||||
cp := el
|
||||
if el.Messages != nil {
|
||||
cp.Messages = make(map[string]string, len(el.Messages))
|
||||
for k, v := range el.Messages {
|
||||
cp.Messages[k] = v
|
||||
}
|
||||
}
|
||||
if el.Metrics != nil {
|
||||
cp.Metrics = append([]string(nil), el.Metrics...)
|
||||
}
|
||||
if el.Monitors != nil {
|
||||
cp.Monitors = append([]string(nil), el.Monitors...)
|
||||
}
|
||||
if el.Display != nil {
|
||||
d := *el.Display
|
||||
if d.ShowBar != nil {
|
||||
d.ShowBar = config.BoolPtr(*d.ShowBar)
|
||||
}
|
||||
if d.ShowUptime != nil {
|
||||
d.ShowUptime = config.BoolPtr(*d.ShowUptime)
|
||||
}
|
||||
if d.ShowLatency != nil {
|
||||
d.ShowLatency = config.BoolPtr(*d.ShowLatency)
|
||||
}
|
||||
if d.ShowStatusBadge != nil {
|
||||
d.ShowStatusBadge = config.BoolPtr(*d.ShowStatusBadge)
|
||||
}
|
||||
if d.ShowMethod != nil {
|
||||
d.ShowMethod = config.BoolPtr(*d.ShowMethod)
|
||||
}
|
||||
if d.ShowTarget != nil {
|
||||
d.ShowTarget = config.BoolPtr(*d.ShowTarget)
|
||||
}
|
||||
if d.ShowDescription != nil {
|
||||
d.ShowDescription = config.BoolPtr(*d.ShowDescription)
|
||||
}
|
||||
if d.ShowMessage != nil {
|
||||
d.ShowMessage = config.BoolPtr(*d.ShowMessage)
|
||||
}
|
||||
if d.ShowLastChecked != nil {
|
||||
d.ShowLastChecked = config.BoolPtr(*d.ShowLastChecked)
|
||||
}
|
||||
if el.Display.CustomLabels != nil {
|
||||
d.CustomLabels = make(map[string]string, len(el.Display.CustomLabels))
|
||||
for k, v := range el.Display.CustomLabels {
|
||||
d.CustomLabels[k] = v
|
||||
}
|
||||
}
|
||||
cp.Display = &d
|
||||
}
|
||||
return cp
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue