package web import ( "strconv" "strings" "time" "git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi" "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n" ) templ publicShell(s agentapi.PageSnapshot, a PublicAssets, docTitle string) { { docTitle } if a.InlineCSS == "" { @faviconLinks() } if a.InlineCSS != "" { @templ.Raw("") } else { } if s.Theme.Accent != "" { @templ.Raw("") } if s.Theme.CSS != "" { @templ.Raw("") }
{ children... }
} templ publicStaleNotice(a PublicAssets) { if !a.StaleSince.IsZero() {

{ i18n.T(ctx, "page.stale", "Time", a.StaleSince.UTC().Format("2006-01-02 15:04")+" UTC") }

} } templ PublicStatusPage(s agentapi.PageSnapshot, a PublicAssets) { @publicShell(s, a, s.Title) {
if s.Theme.LogoURL != "" { { }

{ s.Title }

if s.Description != "" { }
@publicStaleNotice(a)

{ i18n.T(ctx, "page.status."+s.Status) }

@pageMaintenance(i18n.T(ctx, "page.maintenance_ongoing"), s.Ongoing(a.Now)) if len(s.Sections) > 0 {
for _, sec := range s.Sections { @publicSection(sec, s, a) }
} @pageMaintenance(i18n.T(ctx, "page.maintenance_upcoming"), s.Upcoming(a.Now)) @publicIncidents(s.Incidents) } } // publicSection renders an unnamed root component list or a collapsible nested // group matching the monitor dashboard hierarchy. templ publicSection(sec agentapi.Section, s agentapi.PageSnapshot, a PublicAssets) { if sec.Name == "" { @publicComponentList(sec.Components, s, a) } else {
@statusDot(SectionStatus(sec)) { sec.Name } { strconv.Itoa(SectionTotal(sec)) } { i18n.T(ctx, "page.component."+string(secStatusName(sec))) }
@publicComponentList(sec.Components, s, a) for _, child := range sec.Children { @publicSection(child, s, a) }
} } func secStatusName(sec agentapi.Section) string { if sec.Status != "" { return sec.Status } states := make([]string, len(sec.Components)) for i, c := range sec.Components { states[i] = c.Status } return agentapi.Summarize(states) } templ publicComponentList(comps []agentapi.Component, s agentapi.PageSnapshot, a PublicAssets) { if len(comps) > 0 { } } templ publicComponentBody(comp agentapi.Component, clickable bool) {
@statusDot(PageStatus(comp.Status)) { comp.Name } { i18n.T(ctx, "page.component."+comp.Status) } if clickable { }
@bars(DayBars(comp.Days), 22)
{ i18n.T(ctx, "page.days_ago", "Count", len(comp.Days)) } { UptimeText(comp.Uptime) } { i18n.T(ctx, "page.today") }
} templ PublicComponentPage(s agentapi.PageSnapshot, comp agentapi.Component, a PublicAssets) { @publicShell(s, a, comp.Name+" · "+s.Title) {

← { s.Title }

@statusDot(PageStatus(comp.Status)) { comp.Name }

@publicStaleNotice(a)

{ i18n.T(ctx, "page.component."+comp.Status) }

{{ ongoing, upcoming := s.MaintenanceForComponent(comp.Name, a.Now) }} @pageMaintenance(i18n.T(ctx, "page.maintenance_ongoing"), ongoing) if comp.Details != nil {

{ i18n.T(ctx, "page.details_last_24h") }

{ UptimeText(comp.Details.SLA24h) }
@bars(HourBars(comp.Details.Hours), 24) {{ lat := HourLatency(comp.Details.Hours, 600, 96) }} if lat.Points != "" {
{ i18n.T(ctx, "monitors.latency") } { i18n.T(ctx, "page.details_latency_summary", "Avg", AvgLatencyText(comp.Details.Hours), "Max", strconv.Itoa(lat.MaxMS)+" ms") }
}

{ i18n.T(ctx, "monitors.sla_table") }

@publicSLAGrid(comp.Details)
if len(comp.Details.Regions) > 0 {

{ i18n.T(ctx, "monitors.regions") }

@publicRegionsList(comp.Details.Regions)
} }

{ i18n.T(ctx, "monitors.last_90d") }

{ UptimeText(comp.Uptime) }
@bars(DayBars(comp.Days), 24)
{ i18n.T(ctx, "page.days_ago", "Count", len(comp.Days)) } { UptimeText(comp.Uptime) } { i18n.T(ctx, "page.today") }
@pageMaintenance(i18n.T(ctx, "page.maintenance_upcoming"), upcoming) @publicIncidents(s.IncidentsForComponent(comp.Name)) } } templ publicSLAGrid(d *agentapi.ComponentDetails) {
for _, item := range []struct { label string value float64 }{ {"24h", d.SLA24h}, {"7d", d.SLA7d}, {"30d", d.SLA30d}, {"90d", d.SLA90d}, } {
{ item.label }
{ UptimeText(item.value) }
}
} templ publicRegionsList(regions []agentapi.ComponentRegion) { } templ publicIncidents(incidents []agentapi.PageIncident) {

{ i18n.T(ctx, "page.incidents") }

if len(incidents) == 0 {

{ i18n.T(ctx, "page.no_incidents") }

} else { }
} // incidentStatusLabel names an incident's status: what the organization // said, or ongoing or resolved when it said nothing. templ incidentStatusLabel(status string, open bool) { switch { case status != "": { i18n.T(ctx, "incident.status."+status) } case open: { i18n.T(ctx, "incidents.ongoing") } default: { i18n.T(ctx, "incidents.resolved") } } } templ pageMaintenance(heading string, items []agentapi.PageMaintenance) { if len(items) > 0 {

{ heading }

} }