Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
282ab27f81 |
No files matched your search
@@ -1266,6 +1266,8 @@
|
|||||||
"page.search_submit": "Suchen",
|
"page.search_submit": "Suchen",
|
||||||
"page.search_clear": "Alle anzeigen",
|
"page.search_clear": "Alle anzeigen",
|
||||||
"page.search_none": "Keine Komponente passt zur Suche.",
|
"page.search_none": "Keine Komponente passt zur Suche.",
|
||||||
|
"page.filter_problems": "Nur Ausfälle ({{.Count}})",
|
||||||
|
"page.filter_no_problems": "Keine Komponente hat einen Ausfall.",
|
||||||
"page.updated": "Aktualisiert {{.Time}}",
|
"page.updated": "Aktualisiert {{.Time}}",
|
||||||
"pager.earlier": "Frühere",
|
"pager.earlier": "Frühere",
|
||||||
"pager.first": "Zum Anfang",
|
"pager.first": "Zum Anfang",
|
||||||
|
|||||||
@@ -1266,6 +1266,8 @@
|
|||||||
"page.search_submit": "Search",
|
"page.search_submit": "Search",
|
||||||
"page.search_clear": "Show all",
|
"page.search_clear": "Show all",
|
||||||
"page.search_none": "No component matches the search.",
|
"page.search_none": "No component matches the search.",
|
||||||
|
"page.filter_problems": "Outages only ({{.Count}})",
|
||||||
|
"page.filter_no_problems": "No component has an outage.",
|
||||||
"page.updated": "Updated {{.Time}}",
|
"page.updated": "Updated {{.Time}}",
|
||||||
"pager.earlier": "Earlier",
|
"pager.earlier": "Earlier",
|
||||||
"pager.first": "To the start",
|
"pager.first": "To the start",
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -333,22 +334,40 @@ func (s *Server) serve(c *gin.Context) {
|
|||||||
s.localizeRequest(c)
|
s.localizeRequest(c)
|
||||||
c.Header("Cache-Control", "public, max-age=30")
|
c.Header("Cache-Control", "public, max-age=30")
|
||||||
assets.PageSize = componentsPerPage
|
assets.PageSize = componentsPerPage
|
||||||
if n, err := strconv.Atoi(c.Query("page")); err == nil && n > 1 {
|
assets.Pages = sectionPages(c.Request.URL.Query())
|
||||||
assets.Page = n - 1
|
|
||||||
}
|
|
||||||
if q := c.Query("q"); len(q) <= maxComponentQuery {
|
if q := c.Query("q"); len(q) <= maxComponentQuery {
|
||||||
assets.Query = q
|
assets.Query = q
|
||||||
}
|
}
|
||||||
|
assets.OnlyProblems = c.Query("problems") == "1"
|
||||||
web.Render(c, http.StatusOK, web.PublicStatusPage(e.Snap.WithMaintenance(s.now()), assets))
|
web.Render(c, http.StatusOK, web.PublicStatusPage(e.Snap.WithMaintenance(s.now()), assets))
|
||||||
}
|
}
|
||||||
|
|
||||||
// componentsPerPage is how many components a status page lists at a time;
|
// componentsPerPage is how many of its own components a section of a
|
||||||
// organizations put thousands on one.
|
// status page lists at a time; organizations put thousands on one.
|
||||||
const componentsPerPage = 50
|
const componentsPerPage = 25
|
||||||
|
|
||||||
// maxComponentQuery bounds the search for components.
|
// maxComponentQuery bounds the search for components.
|
||||||
const maxComponentQuery = 100
|
const maxComponentQuery = 100
|
||||||
|
|
||||||
|
// maxPagedSections bounds the sections a request pages.
|
||||||
|
const maxPagedSections = 100
|
||||||
|
|
||||||
|
// sectionPages reads the pages of sections a request asks for, as
|
||||||
|
// "p.<key>=<page from 1>".
|
||||||
|
func sectionPages(q url.Values) map[string]int {
|
||||||
|
pages := map[string]int{}
|
||||||
|
for k, vs := range q {
|
||||||
|
key, ok := strings.CutPrefix(k, "p.")
|
||||||
|
if !ok || key == "" || len(vs) == 0 || len(pages) >= maxPagedSections {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if n, err := strconv.Atoi(vs[0]); err == nil && n > 1 {
|
||||||
|
pages[key] = n - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pages
|
||||||
|
}
|
||||||
|
|
||||||
// serveComponent renders one component's public detail page from the cached
|
// serveComponent renders one component's public detail page from the cached
|
||||||
// snapshot when the status page has enabled ShowDetails.
|
// snapshot when the status page has enabled ShowDetails.
|
||||||
func (s *Server) serveComponent(c *gin.Context, e entry, compID string, assets web.PublicAssets) {
|
func (s *Server) serveComponent(c *gin.Context, e entry, compID string, assets web.PublicAssets) {
|
||||||
|
|||||||
@@ -610,34 +610,61 @@ func TestEventsRefreshPagesAtOnce(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pages with many components list them a page at a time and let visitors
|
// Every group of a page with many components lists them a page at a time,
|
||||||
// search them.
|
// and visitors can search them or show those with an outage only.
|
||||||
func TestComponentPagingAndSearch(t *testing.T) {
|
func TestComponentPagingAndSearch(t *testing.T) {
|
||||||
|
comp := func(id, name, status string) agentapi.Component {
|
||||||
|
return agentapi.Component{ID: id, Name: name, Status: status, Days: []agentapi.Day{{Date: "2026-11-26", Uptime: 1}}}
|
||||||
|
}
|
||||||
core := agentapi.Section{Name: "Core"}
|
core := agentapi.Section{Name: "Core"}
|
||||||
for i := 0; i < 120; i++ {
|
for i := 0; i < 120; i++ {
|
||||||
core.Components = append(core.Components, agentapi.Component{ID: fmt.Sprintf("c%03d", i), Name: fmt.Sprintf("web-%03d", i), Status: agentapi.PageOperational, Days: []agentapi.Day{{Date: "2026-11-26", Uptime: 1}}})
|
st := agentapi.PageOperational
|
||||||
|
if i == 7 {
|
||||||
|
st = agentapi.PageDegraded
|
||||||
|
}
|
||||||
|
core.Components = append(core.Components, comp(fmt.Sprintf("c%03d", i), fmt.Sprintf("web-%03d", i), st))
|
||||||
}
|
}
|
||||||
edge := agentapi.Section{Name: "Edge"}
|
edge := agentapi.Section{Name: "Edge"}
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
edge.Components = append(edge.Components, agentapi.Component{ID: fmt.Sprintf("e%d", i), Name: fmt.Sprintf("edge-%d", i), Status: agentapi.PageOperational})
|
st := agentapi.PageOperational
|
||||||
|
if i == 3 {
|
||||||
|
st = agentapi.PageOutage
|
||||||
|
}
|
||||||
|
edge.Components = append(edge.Components, comp(fmt.Sprintf("e%d", i), fmt.Sprintf("edge-%d", i), st))
|
||||||
}
|
}
|
||||||
core.Children = []agentapi.Section{edge}
|
core.Children = []agentapi.Section{edge}
|
||||||
|
other := agentapi.Section{Name: "Other"}
|
||||||
|
for i := 0; i < 30; i++ {
|
||||||
|
other.Components = append(other.Components, comp(fmt.Sprintf("o%02d", i), fmt.Sprintf("other-%02d", i), agentapi.PageOperational))
|
||||||
|
}
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
h := newHarness(t, &fakeSource{pages: map[string]agentapi.PageSnapshot{
|
h := newHarness(t, &fakeSource{pages: map[string]agentapi.PageSnapshot{
|
||||||
"|acme": {Title: "Acme status", Status: agentapi.PageOperational, ShowDetails: true, Sections: []agentapi.Section{core}},
|
"|acme": {Title: "Acme status", Status: agentapi.PageOperational, ShowDetails: true, Sections: []agentapi.Section{core, other}},
|
||||||
|
"|calm": {Title: "Calm", Status: agentapi.PageOperational, Sections: []agentapi.Section{other}},
|
||||||
}}, t.TempDir(), &now)
|
}}, t.TempDir(), &now)
|
||||||
|
if _, body := h.get("status.example.test", "/calm?problems=1"); !strings.Contains(body, "Keine Komponente hat einen Ausfall.") || strings.Contains(body, "other-00") {
|
||||||
|
t.Errorf("outages only without any lacks the notice")
|
||||||
|
}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
path string
|
path string
|
||||||
has, hasNot []string
|
has, hasNot []string
|
||||||
}{
|
}{
|
||||||
{"/acme", []string{"web-000", "web-049", "Seite 1 von 3", `href="/acme?page=2"`, `<path d="M0 0h3v22h-3z"`}, []string{"web-050", "edge-0", `rel="prev"`, "<rect"}},
|
// Every group shows its first page.
|
||||||
{"/acme?page=2", []string{"web-050", "web-099", "Seite 2 von 3", `href="/acme?page=3"`, `href="/acme"`}, []string{"web-049", "web-100"}},
|
{"/acme", []string{"web-000", "web-024", "Seite 1 von 5", "edge-0", "edge-9", "other-00", "other-24", "Seite 1 von 2",
|
||||||
{"/acme?page=3", []string{"web-119", "edge-9", ">Core<", ">Edge<", ">130<", "Seite 3 von 3"}, []string{"web-099", `rel="next"`}},
|
`id="g-0"`, `id="g-0.0"`, `id="g-1"`, `href="/acme?p.0=2#g-0"`, `href="/acme?p.1=2#g-1"`, `<path d="M0 0h3v22h-3z"`, "Nur Ausfälle (2)"},
|
||||||
{"/acme?page=99", []string{"Seite 3 von 3", "edge-9"}, nil},
|
[]string{"web-025", "other-25", `rel="prev"`, "<rect", "Alle anzeigen"}},
|
||||||
{"/acme?page=x", []string{"Seite 1 von 3"}, nil},
|
// Groups page on their own and keep the others' pages.
|
||||||
{"/acme?q=EDGE-", []string{"edge-0", "edge-9", `value="EDGE-"`, "Alle anzeigen"}, []string{"web-", "Seite 1"}},
|
{"/acme?p.0=2", []string{"web-025", "web-049", "Seite 2 von 5", `href="/acme#g-0"`, "edge-0", "other-00"}, []string{"web-024", "web-050"}},
|
||||||
{"/acme?q=edge", []string{"edge-0", "edge-9"}, []string{"web-"}},
|
{"/acme?p.0=2&p.1=2", []string{"web-025", "other-29", `href="/acme?p.0=3&p.1=2#g-0"`, `href="/acme?p.0=2#g-1"`}, []string{"other-00"}},
|
||||||
|
{"/acme?p.0=99", []string{"Seite 5 von 5", "web-119", "edge-9"}, nil},
|
||||||
|
{"/acme?p.0=x", []string{"Seite 1 von 5"}, nil},
|
||||||
|
// Outages only: degraded and down components, groups without any left out.
|
||||||
|
{"/acme?problems=1", []string{"web-007", "edge-3", ">Core<", ">Edge<", ">130<", "checked", "Alle anzeigen"},
|
||||||
|
[]string{"web-000", "edge-0", ">Other<", "Seite 1 von"}},
|
||||||
|
{"/acme?problems=1&q=edge", []string{"edge-3"}, []string{"web-007", "edge-0"}},
|
||||||
|
{"/acme?q=EDGE-", []string{"edge-0", "edge-9", `value="EDGE-"`, "Alle anzeigen"}, []string{"web-", "other-"}},
|
||||||
|
{"/acme?q=edge", []string{"edge-0", "edge-9", ">Core<"}, []string{"web-", ">Other<"}},
|
||||||
{"/acme?q=web-11", []string{"web-110", "web-119"}, []string{"web-109", "edge-"}},
|
{"/acme?q=web-11", []string{"web-110", "web-119"}, []string{"web-109", "edge-"}},
|
||||||
{"/acme?q=nothing", []string{"Keine Komponente passt zur Suche."}, []string{"web-", "edge-"}},
|
{"/acme?q=nothing", []string{"Keine Komponente passt zur Suche."}, []string{"web-", "edge-"}},
|
||||||
}
|
}
|
||||||
|
|||||||
+117
-90
@@ -31,33 +31,104 @@ type PublicAssets struct {
|
|||||||
Now time.Time
|
Now time.Time
|
||||||
// NoRefresh leaves out the periodic reload, on pages with a form.
|
// NoRefresh leaves out the periodic reload, on pages with a form.
|
||||||
NoRefresh bool
|
NoRefresh bool
|
||||||
// PageSize is how many components the page lists at a time; 0 lists
|
// PageSize is how many of a section's own components the page lists
|
||||||
// all, as in a single-file export.
|
// at a time; 0 lists all, as in a single-file export.
|
||||||
PageSize int
|
PageSize int
|
||||||
// Page is the zero-based page of components to show and Query what the
|
// Pages holds the zero-based page shown of the sections paged, by
|
||||||
// visitor searched them for.
|
// their PublicSection.Key.
|
||||||
Page int
|
Pages map[string]int
|
||||||
Query string
|
// Query is what the visitor searched the components for; OnlyProblems
|
||||||
|
// keeps those with an outage or degraded.
|
||||||
|
Query string
|
||||||
|
OnlyProblems bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// ComponentPage is the part of a status page's components one page of it
|
// PublicSection is a section of a status page as a request for it shows
|
||||||
// lists: the sections holding them, keeping the status and count of the
|
// it: the components of one page of the section's own, its status and
|
||||||
// whole section.
|
// count those of the whole section.
|
||||||
type ComponentPage struct {
|
type PublicSection struct {
|
||||||
Sections []agentapi.Section
|
Name string
|
||||||
// Page is the zero-based page shown, of Pages; Matches counts the
|
Status string
|
||||||
// components the query found, of all of them.
|
Total int
|
||||||
|
// Key identifies the section in the URLs paging it, e.g. "0.2".
|
||||||
|
Key string
|
||||||
|
Components []agentapi.Component
|
||||||
|
Children []PublicSection
|
||||||
|
// Page is the zero-based page of the section's own components shown,
|
||||||
|
// of Pages.
|
||||||
Page, Pages int
|
Page, Pages int
|
||||||
Matches int
|
|
||||||
Query string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PageComponents picks the components of page from sections, of those whose
|
// ComponentView is what a request for a status page shows of its
|
||||||
// name or section contains query. size 0 shows all of them.
|
// components: every section paged on its own, filtered by a search and to
|
||||||
func PageComponents(sections []agentapi.Section, page, size int, query string) ComponentPage {
|
// those with problems if the visitor asked.
|
||||||
query = strings.TrimSpace(query)
|
type ComponentView struct {
|
||||||
needle := strings.ToLower(query)
|
Sections []PublicSection
|
||||||
|
// Total counts all components, Matches those the filters leave and
|
||||||
|
// Problems those with an outage or degraded.
|
||||||
|
Total, Matches, Problems int
|
||||||
|
Query string
|
||||||
|
OnlyProblems bool
|
||||||
|
|
||||||
|
base string
|
||||||
|
size int
|
||||||
|
pages map[string]int
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filterable reports whether the page lists enough components to offer the
|
||||||
|
// search and filter, or uses them.
|
||||||
|
func (v ComponentView) Filterable() bool {
|
||||||
|
return v.size > 0 && v.Total > v.size || v.Query != "" || v.OnlyProblems
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filtered reports whether a search or filter is in use.
|
||||||
|
func (v ComponentView) Filtered() bool { return v.Query != "" || v.OnlyProblems }
|
||||||
|
|
||||||
|
// PageHref links page of the section key, keeping the other sections' pages
|
||||||
|
// and the filters.
|
||||||
|
func (v ComponentView) PageHref(key string, page int) string {
|
||||||
|
q := url.Values{}
|
||||||
|
if v.Query != "" {
|
||||||
|
q.Set("q", v.Query)
|
||||||
|
}
|
||||||
|
if v.OnlyProblems {
|
||||||
|
q.Set("problems", "1")
|
||||||
|
}
|
||||||
|
for k, p := range v.pages {
|
||||||
|
if k != key && p > 0 {
|
||||||
|
q.Set("p."+k, strconv.Itoa(p+1))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if page > 0 {
|
||||||
|
q.Set("p."+key, strconv.Itoa(page+1))
|
||||||
|
}
|
||||||
|
href := BackHref(v.base)
|
||||||
|
if len(q) > 0 {
|
||||||
|
href += "?" + q.Encode()
|
||||||
|
}
|
||||||
|
return href + "#g-" + key
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetHref links the page without search, filter and paging.
|
||||||
|
func (v ComponentView) ResetHref() string { return BackHref(v.base) }
|
||||||
|
|
||||||
|
// Problem reports whether a component counts as an outage for the filter.
|
||||||
|
func Problem(c agentapi.Component) bool {
|
||||||
|
return c.Status == agentapi.PageOutage || c.Status == agentapi.PageDegraded
|
||||||
|
}
|
||||||
|
|
||||||
|
// PublicComponents decides which components of sections a request for the
|
||||||
|
// page shows, as a.Query, a.OnlyProblems and a.Pages ask.
|
||||||
|
func PublicComponents(sections []agentapi.Section, a PublicAssets) ComponentView {
|
||||||
|
v := ComponentView{
|
||||||
|
Query: strings.TrimSpace(a.Query), OnlyProblems: a.OnlyProblems,
|
||||||
|
base: a.ComponentBase, size: a.PageSize, pages: a.Pages,
|
||||||
|
}
|
||||||
|
needle := strings.ToLower(v.Query)
|
||||||
match := func(path []string, c agentapi.Component) bool {
|
match := func(path []string, c agentapi.Component) bool {
|
||||||
|
if v.OnlyProblems && !Problem(c) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
if needle == "" || strings.Contains(strings.ToLower(c.Name), needle) {
|
if needle == "" || strings.Contains(strings.ToLower(c.Name), needle) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -68,90 +139,46 @@ func PageComponents(sections []agentapi.Section, page, size int, query string) C
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
// Components are counted in the order the page renders them: a
|
filtered := v.Filtered()
|
||||||
// section's own, then its children's. Unnamed sections are top-level
|
var walk func(sec agentapi.Section, key string, path []string) (PublicSection, bool)
|
||||||
// lists without children.
|
walk = func(sec agentapi.Section, key string, path []string) (PublicSection, bool) {
|
||||||
var count func(sec agentapi.Section, path []string) int
|
ps := PublicSection{Name: sec.Name, Status: secStatusName(sec), Total: SectionTotal(sec), Key: key, Pages: 1}
|
||||||
count = func(sec agentapi.Section, path []string) int {
|
|
||||||
if sec.Name != "" {
|
if sec.Name != "" {
|
||||||
path = append(path, sec.Name)
|
path = append(path, sec.Name)
|
||||||
}
|
}
|
||||||
n := 0
|
var own []agentapi.Component
|
||||||
for _, c := range sec.Components {
|
for _, c := range sec.Components {
|
||||||
|
v.Total++
|
||||||
|
if Problem(c) {
|
||||||
|
v.Problems++
|
||||||
|
}
|
||||||
if match(path, c) {
|
if match(path, c) {
|
||||||
n++
|
own = append(own, c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
v.Matches += len(own)
|
||||||
|
if v.size > 0 && len(own) > v.size {
|
||||||
|
ps.Pages = (len(own) + v.size - 1) / v.size
|
||||||
|
ps.Page = min(max(v.pages[key], 0), ps.Pages-1)
|
||||||
|
own = own[ps.Page*v.size : min((ps.Page+1)*v.size, len(own))]
|
||||||
|
}
|
||||||
|
ps.Components = own
|
||||||
|
// Unnamed sections are top-level lists without children.
|
||||||
if sec.Name != "" {
|
if sec.Name != "" {
|
||||||
for _, child := range sec.Children {
|
for i, child := range sec.Children {
|
||||||
n += count(child, path)
|
if c, ok := walk(child, key+"."+strconv.Itoa(i), path); ok {
|
||||||
}
|
ps.Children = append(ps.Children, c)
|
||||||
}
|
|
||||||
return n
|
|
||||||
}
|
|
||||||
total := 0
|
|
||||||
for _, sec := range sections {
|
|
||||||
total += count(sec, nil)
|
|
||||||
}
|
|
||||||
out := ComponentPage{Pages: 1, Matches: total, Query: query}
|
|
||||||
if needle == "" && (size <= 0 || total <= size) {
|
|
||||||
out.Sections = sections
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
from, to := 0, total
|
|
||||||
if size > 0 && total > size {
|
|
||||||
out.Pages = (total + size - 1) / size
|
|
||||||
out.Page = min(max(page, 0), out.Pages-1)
|
|
||||||
from, to = out.Page*size, min((out.Page+1)*size, total)
|
|
||||||
}
|
|
||||||
idx := 0
|
|
||||||
var cut func(sec agentapi.Section, path []string) (agentapi.Section, bool)
|
|
||||||
cut = func(sec agentapi.Section, path []string) (agentapi.Section, bool) {
|
|
||||||
part := agentapi.Section{Name: sec.Name, Status: secStatusName(sec), Total: SectionTotal(sec)}
|
|
||||||
if sec.Name != "" {
|
|
||||||
path = append(path, sec.Name)
|
|
||||||
}
|
|
||||||
for _, c := range sec.Components {
|
|
||||||
if !match(path, c) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if idx >= from && idx < to {
|
|
||||||
part.Components = append(part.Components, c)
|
|
||||||
}
|
|
||||||
idx++
|
|
||||||
}
|
|
||||||
if sec.Name != "" {
|
|
||||||
for _, child := range sec.Children {
|
|
||||||
if p, ok := cut(child, path); ok {
|
|
||||||
part.Children = append(part.Children, p)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return part, len(part.Components) > 0 || len(part.Children) > 0
|
return ps, !filtered || len(ps.Components) > 0 || len(ps.Children) > 0
|
||||||
}
|
}
|
||||||
for _, sec := range sections {
|
for i, sec := range sections {
|
||||||
if p, ok := cut(sec, nil); ok {
|
if ps, ok := walk(sec, strconv.Itoa(i), nil); ok {
|
||||||
out.Sections = append(out.Sections, p)
|
v.Sections = append(v.Sections, ps)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return out
|
return v
|
||||||
}
|
|
||||||
|
|
||||||
// ComponentPageHref links page of the components of the status page at
|
|
||||||
// base, keeping the search for query.
|
|
||||||
func ComponentPageHref(base string, page int, query string) string {
|
|
||||||
v := url.Values{}
|
|
||||||
if page > 0 {
|
|
||||||
v.Set("page", strconv.Itoa(page+1))
|
|
||||||
}
|
|
||||||
if query != "" {
|
|
||||||
v.Set("q", query)
|
|
||||||
}
|
|
||||||
href := BackHref(base)
|
|
||||||
if len(v) > 0 {
|
|
||||||
href += "?" + v.Encode()
|
|
||||||
}
|
|
||||||
return href
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// BarPath draws the bars of one status of a chart.
|
// BarPath draws the bars of one status of a chart.
|
||||||
|
|||||||
+42
-31
@@ -94,18 +94,21 @@ templ PublicStatusPage(s agentapi.PageSnapshot, a PublicAssets) {
|
|||||||
<p class="text-lg font-medium">{ i18n.T(ctx, "page.status."+s.Status) }</p>
|
<p class="text-lg font-medium">{ i18n.T(ctx, "page.status."+s.Status) }</p>
|
||||||
</section>
|
</section>
|
||||||
@pageMaintenance(i18n.T(ctx, "page.maintenance_ongoing"), s.Ongoing(a.Now))
|
@pageMaintenance(i18n.T(ctx, "page.maintenance_ongoing"), s.Ongoing(a.Now))
|
||||||
if cp := PageComponents(s.Sections, a.Page, a.PageSize, a.Query); len(s.Sections) > 0 {
|
if v := PublicComponents(s.Sections, a); len(s.Sections) > 0 {
|
||||||
if cp.Pages > 1 || cp.Query != "" {
|
if v.Filterable() {
|
||||||
@publicComponentSearch(cp, a)
|
@publicComponentFilter(v, a)
|
||||||
}
|
}
|
||||||
<section class="mb-12 border-t border-rule">
|
<section class="mb-12 border-t border-rule">
|
||||||
for _, sec := range cp.Sections {
|
for _, sec := range v.Sections {
|
||||||
@publicSection(sec, s, a)
|
@publicSection(sec, v, s, a)
|
||||||
}
|
}
|
||||||
if cp.Matches == 0 {
|
if v.Filtered() && v.Matches == 0 {
|
||||||
<p class="py-6 text-sm text-muted">{ i18n.T(ctx, "page.search_none") }</p>
|
if v.OnlyProblems && v.Query == "" {
|
||||||
|
<p class="py-6 text-sm text-muted">{ i18n.T(ctx, "page.filter_no_problems") }</p>
|
||||||
|
} else {
|
||||||
|
<p class="py-6 text-sm text-muted">{ i18n.T(ctx, "page.search_none") }</p>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@publicComponentPager(cp, a)
|
|
||||||
</section>
|
</section>
|
||||||
}
|
}
|
||||||
@publicIncidents(s.Incidents)
|
@publicIncidents(s.Incidents)
|
||||||
@@ -165,29 +168,33 @@ templ PublicNoticePage(s agentapi.PageSnapshot, a PublicAssets, title, message s
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// publicComponentSearch finds components on pages listing too many to scan.
|
// publicComponentFilter searches the components of pages listing too many
|
||||||
templ publicComponentSearch(cp ComponentPage, a PublicAssets) {
|
// to scan, or narrows them to those with an outage.
|
||||||
<form method="get" action={ templ.SafeURL(BackHref(a.ComponentBase)) } role="search" class="mb-4 flex flex-wrap items-center gap-2 text-sm">
|
templ publicComponentFilter(v ComponentView, a PublicAssets) {
|
||||||
|
<form method="get" action={ templ.SafeURL(BackHref(a.ComponentBase)) } role="search" class="mb-4 flex flex-wrap items-center gap-x-4 gap-y-2 text-sm">
|
||||||
<label class="sr-only" for="component-search">{ i18n.T(ctx, "page.search") }</label>
|
<label class="sr-only" for="component-search">{ i18n.T(ctx, "page.search") }</label>
|
||||||
<input id="component-search" type="search" name="q" value={ cp.Query } maxlength="100" placeholder={ i18n.T(ctx, "page.search") } class="min-w-0 flex-1 border border-rule bg-transparent px-2 py-1.5"/>
|
<input id="component-search" type="search" name="q" value={ v.Query } maxlength="100" placeholder={ i18n.T(ctx, "page.search") } class="min-w-0 flex-1 border border-rule bg-transparent px-2 py-1.5"/>
|
||||||
|
<label class="flex items-center gap-2">
|
||||||
|
<input type="checkbox" name="problems" value="1" checked?={ v.OnlyProblems }/>
|
||||||
|
<span>{ i18n.T(ctx, "page.filter_problems", "Count", v.Problems) }</span>
|
||||||
|
</label>
|
||||||
<button type="submit" class="border border-ink px-3 py-1.5 hover:bg-ink hover:text-paper">{ i18n.T(ctx, "page.search_submit") }</button>
|
<button type="submit" class="border border-ink px-3 py-1.5 hover:bg-ink hover:text-paper">{ i18n.T(ctx, "page.search_submit") }</button>
|
||||||
if cp.Query != "" {
|
if v.Filtered() {
|
||||||
<a href={ templ.SafeURL(BackHref(a.ComponentBase)) } class="text-muted hover:text-ink">{ i18n.T(ctx, "page.search_clear") }</a>
|
<a href={ templ.SafeURL(v.ResetHref()) } class="text-muted hover:text-ink">{ i18n.T(ctx, "page.search_clear") }</a>
|
||||||
}
|
}
|
||||||
</form>
|
</form>
|
||||||
}
|
}
|
||||||
|
|
||||||
// publicComponentPager turns the pages of components.
|
// publicSectionPager turns the pages of a section's own components.
|
||||||
templ publicComponentPager(cp ComponentPage, a PublicAssets) {
|
templ publicSectionPager(sec PublicSection, v ComponentView) {
|
||||||
if cp.Pages > 1 {
|
if sec.Pages > 1 {
|
||||||
<nav class="flex flex-wrap items-center gap-x-5 gap-y-2 py-4 text-sm" aria-label={ i18n.T(ctx, "pager.label") }>
|
<nav class="flex flex-wrap items-center gap-x-5 gap-y-2 border-b border-rule py-2 text-sm" aria-label={ i18n.T(ctx, "pager.label") }>
|
||||||
if cp.Page > 0 {
|
if sec.Page > 0 {
|
||||||
<a href={ templ.SafeURL(ComponentPageHref(a.ComponentBase, 0, cp.Query)) } class="text-muted hover:text-ink">{ i18n.T(ctx, "pager.first") }</a>
|
<a href={ templ.SafeURL(v.PageHref(sec.Key, sec.Page-1)) } rel="prev" class="text-muted hover:text-ink">← { i18n.T(ctx, "pager.previous") }</a>
|
||||||
<a href={ templ.SafeURL(ComponentPageHref(a.ComponentBase, cp.Page-1, cp.Query)) } rel="prev" class="text-muted hover:text-ink">← { i18n.T(ctx, "pager.previous") }</a>
|
|
||||||
}
|
}
|
||||||
<span class="font-mono text-xs text-muted">{ i18n.T(ctx, "page.pages", "Page", cp.Page+1, "Pages", cp.Pages) }</span>
|
<span class="font-mono text-xs text-muted">{ i18n.T(ctx, "page.pages", "Page", sec.Page+1, "Pages", sec.Pages) }</span>
|
||||||
if cp.Page < cp.Pages-1 {
|
if sec.Page < sec.Pages-1 {
|
||||||
<a href={ templ.SafeURL(ComponentPageHref(a.ComponentBase, cp.Page+1, cp.Query)) } rel="next" class="ml-auto text-muted hover:text-ink">{ i18n.T(ctx, "pager.next") } →</a>
|
<a href={ templ.SafeURL(v.PageHref(sec.Key, sec.Page+1)) } rel="next" class="ml-auto text-muted hover:text-ink">{ i18n.T(ctx, "pager.next") } →</a>
|
||||||
}
|
}
|
||||||
</nav>
|
</nav>
|
||||||
}
|
}
|
||||||
@@ -195,21 +202,25 @@ templ publicComponentPager(cp ComponentPage, a PublicAssets) {
|
|||||||
|
|
||||||
// publicSection renders an unnamed root component list or a collapsible nested
|
// publicSection renders an unnamed root component list or a collapsible nested
|
||||||
// group matching the monitor dashboard hierarchy.
|
// group matching the monitor dashboard hierarchy.
|
||||||
templ publicSection(sec agentapi.Section, s agentapi.PageSnapshot, a PublicAssets) {
|
templ publicSection(sec PublicSection, v ComponentView, s agentapi.PageSnapshot, a PublicAssets) {
|
||||||
if sec.Name == "" {
|
if sec.Name == "" {
|
||||||
@publicComponentList(sec.Components, s, a)
|
<div id={ "g-" + sec.Key }>
|
||||||
|
@publicComponentList(sec.Components, s, a)
|
||||||
|
@publicSectionPager(sec, v)
|
||||||
|
</div>
|
||||||
} else {
|
} else {
|
||||||
<details open class="border-b border-rule">
|
<details open id={ "g-" + sec.Key } class="border-b border-rule">
|
||||||
<summary class="flex cursor-pointer items-center gap-2.5 py-3 text-sm font-medium select-none hover:bg-rule/30">
|
<summary class="flex cursor-pointer items-center gap-2.5 py-3 text-sm font-medium select-none hover:bg-rule/30">
|
||||||
@statusDot(SectionStatus(sec))
|
@statusDot(PageStatus(sec.Status))
|
||||||
<span>{ sec.Name }</span>
|
<span>{ sec.Name }</span>
|
||||||
<span class="font-mono text-xs font-normal text-muted">{ strconv.Itoa(SectionTotal(sec)) }</span>
|
<span class="font-mono text-xs font-normal text-muted">{ strconv.Itoa(sec.Total) }</span>
|
||||||
<span class="ml-auto text-xs font-normal text-muted">{ i18n.T(ctx, "page.component."+string(secStatusName(sec))) }</span>
|
<span class="ml-auto text-xs font-normal text-muted">{ i18n.T(ctx, "page.component."+sec.Status) }</span>
|
||||||
</summary>
|
</summary>
|
||||||
<div class="ml-4 border-l border-rule pl-4">
|
<div class="ml-4 border-l border-rule pl-4">
|
||||||
@publicComponentList(sec.Components, s, a)
|
@publicComponentList(sec.Components, s, a)
|
||||||
|
@publicSectionPager(sec, v)
|
||||||
for _, child := range sec.Children {
|
for _, child := range sec.Children {
|
||||||
@publicSection(child, s, a)
|
@publicSection(child, v, s, a)
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</details>
|
</details>
|
||||||
|
|||||||
+830
-774
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user