From 725d0da15d7ee596ec35c0eebcd24b06fc23fb85 Mon Sep 17 00:00:00 2001 From: Svilen Markov <7613769+svilenmarkov@users.noreply.github.com> Date: Thu, 29 Aug 2024 21:14:50 +0100 Subject: [PATCH 1/7] Add show-failing-only property to the monitor widget --- docs/configuration.md | 12 ++++++++---- internal/assets/static/main.css | 1 + internal/assets/templates/monitor.html | 11 +++++++++++ internal/widget/monitor.go | 11 +++++++++-- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 1b02af4..fed6fa4 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1043,14 +1043,18 @@ You can hover over the "ERROR" text to view more information. #### Properties -| Name | Type | Required | -| ---- | ---- | -------- | -| sites | array | yes | -| style | string | no | +| Name | Type | Required | Default | +| ---- | ---- | -------- | ------- | +| sites | array | yes | | +| show-failing-only | boolean | no | false | +| style | string | no | | ##### `style` To make the widget scale appropriately in a `full` size column, set the style to the experimental `dynamic-columns-experimental` option. +##### `show-failing-only` +Shows only a list of failing sites when set to `true`. + ##### `sites` Properties for each site: diff --git a/internal/assets/static/main.css b/internal/assets/static/main.css index ddad6e0..37db60c 100644 --- a/internal/assets/static/main.css +++ b/internal/assets/static/main.css @@ -1509,4 +1509,5 @@ kbd:active { .margin-bottom-10 { margin-bottom: 1rem; } .margin-bottom-15 { margin-bottom: 1.5rem; } .margin-bottom-auto { margin-bottom: auto; } +.padding-block-5 { padding-block: 0.5rem; } .scale-half { transform: scale(0.5); } diff --git a/internal/assets/templates/monitor.html b/internal/assets/templates/monitor.html index 0333741..bfb2ca9 100644 --- a/internal/assets/templates/monitor.html +++ b/internal/assets/templates/monitor.html @@ -10,13 +10,24 @@ {{ end }} {{ else }} + +{{ if not (and .ShowFailingOnly (not .HasFailing)) }} +{{ else }} +
+

All sites are online

+ + + +
+{{ end }} {{ end }} {{ end }} diff --git a/internal/widget/monitor.go b/internal/widget/monitor.go index 7216e9c..b5a279e 100644 --- a/internal/widget/monitor.go +++ b/internal/widget/monitor.go @@ -53,7 +53,9 @@ type Monitor struct { StatusText string `yaml:"-"` StatusStyle string `yaml:"-"` } `yaml:"sites"` - Style string `yaml:"style"` + Style string `yaml:"style"` + ShowFailingOnly bool `yaml:"show-failing-only"` + HasFailing bool `yaml:"-"` } func (widget *Monitor) Initialize() error { @@ -79,12 +81,17 @@ func (widget *Monitor) Update(ctx context.Context) { return } + widget.HasFailing = false + for i := range widget.Sites { site := &widget.Sites[i] status := &statuses[i] - site.Status = status + if status.Code >= 400 || status.TimedOut || status.Error != nil { + widget.HasFailing = true + } + if !status.TimedOut { site.StatusText = statusCodeToText(status.Code) site.StatusStyle = statusCodeToStyle(status.Code) From b9bf8c6c96df2572898db61d0b37c39cffe04c39 Mon Sep 17 00:00:00 2001 From: Svilen Markov <7613769+svilenmarkov@users.noreply.github.com> Date: Fri, 30 Aug 2024 16:19:20 +0100 Subject: [PATCH 2/7] Fix version formatting in releases widget --- internal/feed/github.go | 8 +------- internal/feed/gitlab.go | 8 +------- internal/feed/utils.go | 10 ++++++++++ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/internal/feed/github.go b/internal/feed/github.go index 782d612..18487f0 100644 --- a/internal/feed/github.go +++ b/internal/feed/github.go @@ -38,16 +38,10 @@ func fetchLatestGithubRelease(request *ReleaseRequest) (*AppRelease, error) { return nil, err } - version := response.TagName - - if len(version) > 0 && version[0] != 'v' { - version = "v" + version - } - return &AppRelease{ Source: ReleaseSourceGithub, Name: request.Repository, - Version: version, + Version: normalizeVersionFormat(response.TagName), NotesUrl: response.HtmlUrl, TimeReleased: parseRFC3339Time(response.PublishedAt), Downvotes: response.Reactions.Downvotes, diff --git a/internal/feed/gitlab.go b/internal/feed/gitlab.go index 4e0c1e8..3ff0f00 100644 --- a/internal/feed/gitlab.go +++ b/internal/feed/gitlab.go @@ -38,16 +38,10 @@ func fetchLatestGitLabRelease(request *ReleaseRequest) (*AppRelease, error) { return nil, err } - version := response.TagName - - if len(version) > 0 && version[0] != 'v' { - version = "v" + version - } - return &AppRelease{ Source: ReleaseSourceGitlab, Name: request.Repository, - Version: version, + Version: normalizeVersionFormat(response.TagName), NotesUrl: response.Links.Self, TimeReleased: parseRFC3339Time(response.ReleasedAt), }, nil diff --git a/internal/feed/utils.go b/internal/feed/utils.go index f86b497..a6e3f8d 100644 --- a/internal/feed/utils.go +++ b/internal/feed/utils.go @@ -105,3 +105,13 @@ func parseRFC3339Time(t string) time.Time { return parsed } + +func normalizeVersionFormat(version string) string { + version = strings.ToLower(strings.TrimSpace(version)) + + if len(version) > 0 && version[0] != 'v' { + return "v" + version + } + + return version +} From cf0dd07c213118857276540482223e3d490428aa Mon Sep 17 00:00:00 2001 From: Svilen Markov <7613769+svilenmarkov@users.noreply.github.com> Date: Sat, 31 Aug 2024 17:35:38 +0100 Subject: [PATCH 3/7] Add center-vertically property --- internal/assets/static/main.css | 6 ++++++ internal/assets/templates/page.html | 2 +- internal/glance/glance.go | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/assets/static/main.css b/internal/assets/static/main.css index 37db60c..a8da75c 100644 --- a/internal/assets/static/main.css +++ b/internal/assets/static/main.css @@ -451,6 +451,12 @@ kbd:active { max-width: 1100px; } +.page-center-vertically .page { + display: flex; + justify-content: center; + flex-direction: column; +} + .dynamic-columns { gap: calc(var(--widget-content-vertical-padding) / 2); display: grid; diff --git a/internal/assets/templates/page.html b/internal/assets/templates/page.html index 4d08e61..d2cee76 100644 --- a/internal/assets/templates/page.html +++ b/internal/assets/templates/page.html @@ -11,7 +11,7 @@ {{ end }} -{{ define "document-root-attrs" }}class="{{ if .App.Config.Theme.Light }}light-scheme {{ end }}{{ if ne "" .Page.Width }}page-width-{{ .Page.Width }}{{ end }}"{{ end }} +{{ define "document-root-attrs" }}class="{{ if .App.Config.Theme.Light }}light-scheme {{ end }}{{ if ne "" .Page.Width }}page-width-{{ .Page.Width }} {{ end }}{{ if .Page.CenterVertically }}page-center-vertically{{ end }}"{{ end }} {{ define "document-head-after" }} {{ template "page-style-overrides.gotmpl" . }} diff --git a/internal/glance/glance.go b/internal/glance/glance.go index a8485f2..d26745f 100644 --- a/internal/glance/glance.go +++ b/internal/glance/glance.go @@ -73,6 +73,7 @@ type Page struct { Width string `yaml:"width"` ShowMobileHeader bool `yaml:"show-mobile-header"` HideDesktopNavigation bool `yaml:"hide-desktop-navigation"` + CenterVertically bool `yaml:"center-vertically"` Columns []Column `yaml:"columns"` mu sync.Mutex } From 99866507f54677169e17feaeb2136d1373192bfb Mon Sep 17 00:00:00 2001 From: Svilen Markov <7613769+svilenmarkov@users.noreply.github.com> Date: Sat, 31 Aug 2024 17:35:53 +0100 Subject: [PATCH 4/7] Fix overflowing text in monitor widget --- internal/assets/templates/monitor.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/assets/templates/monitor.html b/internal/assets/templates/monitor.html index bfb2ca9..ecec09f 100644 --- a/internal/assets/templates/monitor.html +++ b/internal/assets/templates/monitor.html @@ -35,8 +35,8 @@ {{ if .IconUrl }} {{ end }} -
- {{ .Title }} +
+ {{ .Title }}