diff --git a/docs/configuration.md b/docs/configuration.md index f8221b8..832d035 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1149,11 +1149,19 @@ You can hover over the "ERROR" text to view more information. | Name | Type | Required | Default | | ---- | ---- | -------- | ------- | | sites | array | yes | | +| style | string | no | | | show-failing-only | boolean | no | false | ##### `show-failing-only` Shows only a list of failing sites when set to `true`. +##### `style` +Used to change the appearance of the widget. Possible values are `compact`. + +Preview of `compact`: + +![](images/monitor-widget-compact-preview.png) + ##### `sites` Properties for each site: diff --git a/docs/images/monitor-widget-compact-preview.png b/docs/images/monitor-widget-compact-preview.png new file mode 100644 index 0000000..3e81fce Binary files /dev/null and b/docs/images/monitor-widget-compact-preview.png differ diff --git a/internal/assets/static/main.css b/internal/assets/static/main.css index 3c342a0..3268a48 100644 --- a/internal/assets/static/main.css +++ b/internal/assets/static/main.css @@ -1830,6 +1830,7 @@ details[open] .summary::after { .list { --list-half-gap: 0rem; } .list-gap-2 { --list-half-gap: 0.1rem; } .list-gap-4 { --list-half-gap: 0.2rem; } +.list-gap-8 { --list-half-gap: 0.4rem; } .list-gap-10 { --list-half-gap: 0.5rem; } .list-gap-14 { --list-half-gap: 0.7rem; } .list-gap-20 { --list-half-gap: 1rem; } diff --git a/internal/assets/templates.go b/internal/assets/templates.go index 324f8ca..4834078 100644 --- a/internal/assets/templates.go +++ b/internal/assets/templates.go @@ -32,6 +32,7 @@ var ( RSSHorizontalCardsTemplate = compileTemplate("rss-horizontal-cards.html", "widget-base.html") RSSHorizontalCards2Template = compileTemplate("rss-horizontal-cards-2.html", "widget-base.html") MonitorTemplate = compileTemplate("monitor.html", "widget-base.html") + MonitorCompactTemplate = compileTemplate("monitor-compact.html", "widget-base.html") TwitchGamesListTemplate = compileTemplate("twitch-games-list.html", "widget-base.html") TwitchChannelsTemplate = compileTemplate("twitch-channels.html", "widget-base.html") RepositoryTemplate = compileTemplate("repository.html", "widget-base.html") diff --git a/internal/assets/templates/monitor-compact.html b/internal/assets/templates/monitor-compact.html new file mode 100644 index 0000000..327c978 --- /dev/null +++ b/internal/assets/templates/monitor-compact.html @@ -0,0 +1,39 @@ +{{ template "widget-base.html" . }} + +{{ define "widget-content" }} +{{ if not (and .ShowFailingOnly (not .HasFailing)) }} + +{{ else }} +
+

All sites are online

+ + + +
+{{ end }} +{{ end }} + +{{ define "site" }} +{{ .Title }} +{{ if not .Status.TimedOut }}
{{ .Status.ResponseTime.Milliseconds | formatNumber }}ms
{{ end }} +{{ if eq .StatusStyle "ok" }} +
+ + + +
+{{ else }} +
+ + + +
+{{ end }} +{{ end }} diff --git a/internal/widget/monitor.go b/internal/widget/monitor.go index 14b1d70..f769a4e 100644 --- a/internal/widget/monitor.go +++ b/internal/widget/monitor.go @@ -11,37 +11,6 @@ import ( "github.com/glanceapp/glance/internal/feed" ) -func statusCodeToText(status int, altStatusCodes []int) string { - if status == 200 || slices.Contains(altStatusCodes, status) { - return "OK" - } - if status == 404 { - return "Not Found" - } - if status == 403 { - return "Forbidden" - } - if status == 401 { - return "Unauthorized" - } - if status >= 400 { - return "Client Error" - } - if status >= 500 { - return "Server Error" - } - - return strconv.Itoa(status) -} - -func statusCodeToStyle(status int, altStatusCodes []int) string { - if status == 200 || slices.Contains(altStatusCodes, status) { - return "ok" - } - - return "error" -} - type Monitor struct { widgetBase `yaml:",inline"` Sites []struct { @@ -54,8 +23,9 @@ type Monitor struct { StatusStyle string `yaml:"-"` AltStatusCodes []int `yaml:"alt-status-codes"` } `yaml:"sites"` - ShowFailingOnly bool `yaml:"show-failing-only"` - HasFailing bool `yaml:"-"` + Style string `yaml:"style"` + ShowFailingOnly bool `yaml:"show-failing-only"` + HasFailing bool `yaml:"-"` } func (widget *Monitor) Initialize() error { @@ -96,5 +66,40 @@ func (widget *Monitor) Update(ctx context.Context) { } func (widget *Monitor) Render() template.HTML { + if widget.Style == "compact" { + return widget.render(widget, assets.MonitorCompactTemplate) + } + return widget.render(widget, assets.MonitorTemplate) } + +func statusCodeToText(status int, altStatusCodes []int) string { + if status == 200 || slices.Contains(altStatusCodes, status) { + return "OK" + } + if status == 404 { + return "Not Found" + } + if status == 403 { + return "Forbidden" + } + if status == 401 { + return "Unauthorized" + } + if status >= 400 { + return "Client Error" + } + if status >= 500 { + return "Server Error" + } + + return strconv.Itoa(status) +} + +func statusCodeToStyle(status int, altStatusCodes []int) string { + if status == 200 || slices.Contains(altStatusCodes, status) { + return "ok" + } + + return "error" +}