Organizations build pages from their monitors, grouped into sections with public names, choose an accent color, logo and CSS, verify custom domains with a TXT record and export a page as one self-contained HTML file. Assignments scoped to a single status page are honored. Closes #21 Closes #23 Closes #24 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
183 lines
7.4 KiB
Templ
183 lines
7.4 KiB
Templ
package web
|
|
|
|
import "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
|
|
|
|
// PageRow is a status page in the list.
|
|
type PageRow struct {
|
|
ID string
|
|
Title string
|
|
Slug string
|
|
Published bool
|
|
URL string
|
|
Domain string
|
|
}
|
|
|
|
// PagesView is the data of the status page list.
|
|
type PagesView struct {
|
|
Pages []PageRow
|
|
CanWrite bool
|
|
}
|
|
|
|
templ StatusPagesPage(p Page, me Me, v PagesView) {
|
|
@consoleShell(p, me) {
|
|
@settingsHeading("pages.title", "pages.intro")
|
|
if len(v.Pages) > 0 {
|
|
<ul class="mb-12 divide-y divide-rule border-y border-rule text-sm">
|
|
for _, pg := range v.Pages {
|
|
<li class="flex flex-wrap items-center gap-x-4 gap-y-1 py-2.5">
|
|
if pg.Published {
|
|
@statusDot(StatusUp)
|
|
} else {
|
|
@statusDot(StatusPaused)
|
|
}
|
|
<a href={ templ.SafeURL("/statuspages/" + pg.ID) } class="hover:underline">{ pg.Title }</a>
|
|
<span class="font-mono text-xs text-muted">{ pg.Slug }</span>
|
|
if pg.Domain != "" {
|
|
<span class="font-mono text-xs text-muted">{ pg.Domain }</span>
|
|
}
|
|
if pg.Published {
|
|
<a href={ templ.SafeURL(pg.URL) } class="ml-auto text-muted hover:text-ink" target="_blank" rel="noopener">{ i18n.T(ctx, "pages.open") } ↗</a>
|
|
} else {
|
|
<span class="ml-auto text-xs text-muted">{ i18n.T(ctx, "pages.draft") }</span>
|
|
}
|
|
</li>
|
|
}
|
|
</ul>
|
|
}
|
|
if v.CanWrite {
|
|
<section class="max-w-md">
|
|
@sectionHeading("pages.create")
|
|
<form data-api="/org/statuspages" data-next-from="id" data-next="/statuspages/">
|
|
@formError()
|
|
@valueField(i18n.T(ctx, "pages.page_title"), "title", "", "Acme status", true)
|
|
@valueField(i18n.T(ctx, "pages.slug"), "slug", "", "acme", true)
|
|
@submit(i18n.T(ctx, "pages.create"))
|
|
</form>
|
|
</section>
|
|
}
|
|
}
|
|
}
|
|
|
|
// PageMonitorOption is a monitor in the page editor.
|
|
type PageMonitorOption struct {
|
|
ID string
|
|
Name string
|
|
Included bool
|
|
Section string
|
|
Label string
|
|
}
|
|
|
|
// PageEditor is the data of the status page editor.
|
|
type PageEditor struct {
|
|
ID string
|
|
Title string
|
|
Slug string
|
|
Description string
|
|
Published bool
|
|
Accent string
|
|
LogoURL string
|
|
CSS string
|
|
URL string
|
|
Domain string
|
|
DomainVerified bool
|
|
RecordName string
|
|
RecordValue string
|
|
Monitors []PageMonitorOption
|
|
}
|
|
|
|
templ StatusPageEditor(p Page, me Me, e PageEditor) {
|
|
@consoleShell(p, me) {
|
|
<p class="mb-4 text-sm"><a href="/statuspages" class="text-muted hover:text-ink">← { i18n.T(ctx, "pages.title") }</a></p>
|
|
<div class="mb-8 flex flex-wrap items-baseline justify-between gap-4">
|
|
<h1 class="text-lg font-semibold">{ e.Title }</h1>
|
|
<span class="flex gap-5 text-sm">
|
|
if e.Published {
|
|
<a href={ templ.SafeURL(e.URL) } target="_blank" rel="noopener" class="text-muted hover:text-ink">{ i18n.T(ctx, "pages.open") } ↗</a>
|
|
}
|
|
<a href={ templ.SafeURL("/api/v1/org/statuspages/" + e.ID + "/export") } class="text-muted hover:text-ink">{ i18n.T(ctx, "pages.export") }</a>
|
|
</span>
|
|
</div>
|
|
<div class="grid gap-12 md:grid-cols-2">
|
|
<section>
|
|
@sectionHeading("pages.settings")
|
|
<form data-api={ "/org/statuspages/" + e.ID } data-method="put" data-next={ "/statuspages/" + e.ID }>
|
|
@formError()
|
|
@valueField(i18n.T(ctx, "pages.page_title"), "title", e.Title, "", true)
|
|
@valueField(i18n.T(ctx, "pages.slug"), "slug", e.Slug, "", true)
|
|
<label class="mb-4 block">
|
|
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "pages.description") }</span>
|
|
<textarea name="description" rows="3" class="w-full border border-rule bg-transparent px-2.5 py-1.5 outline-none focus:border-ink">{ e.Description }</textarea>
|
|
</label>
|
|
@checkbox(i18n.T(ctx, "pages.published"), "published", e.Published)
|
|
<h3 class="mt-6 mb-3 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "pages.theme") }</h3>
|
|
@valueField(i18n.T(ctx, "pages.accent"), "theme.accent", e.Accent, "#1f6feb", false)
|
|
@valueField(i18n.T(ctx, "pages.logo"), "theme.logo_url", e.LogoURL, "https://example.com/logo.svg", false)
|
|
<label class="mb-4 block">
|
|
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "pages.css") }</span>
|
|
<textarea name="theme.css" rows="4" class="w-full border border-rule bg-transparent px-2.5 py-1.5 font-mono text-xs outline-none focus:border-ink">{ e.CSS }</textarea>
|
|
</label>
|
|
@submit(i18n.T(ctx, "common.save"))
|
|
</form>
|
|
<button
|
|
type="button"
|
|
data-delete={ "/org/statuspages/" + e.ID }
|
|
data-confirm={ i18n.T(ctx, "pages.delete_confirm") }
|
|
data-next="/statuspages"
|
|
class="mt-6 text-sm text-down hover:underline"
|
|
>{ i18n.T(ctx, "pages.delete") }</button>
|
|
</section>
|
|
<div>
|
|
<section class="mb-12">
|
|
@sectionHeading("pages.components")
|
|
<form data-api={ "/org/statuspages/" + e.ID + "/monitors" } data-method="put" data-rows="monitors" data-next={ "/statuspages/" + e.ID }>
|
|
@formError()
|
|
if len(e.Monitors) == 0 {
|
|
<p class="mb-4 text-sm text-muted">{ i18n.T(ctx, "console.monitors.empty") }</p>
|
|
}
|
|
<ul class="mb-4 divide-y divide-rule border-y border-rule text-sm">
|
|
for _, m := range e.Monitors {
|
|
<li data-row class="grid grid-cols-[auto_1fr] items-center gap-x-3 gap-y-1.5 py-2">
|
|
<input type="checkbox" data-field="include" checked?={ m.Included } class="accent-ink" aria-label={ m.Name }/>
|
|
<span>{ m.Name }</span>
|
|
<input type="hidden" data-field="monitor_id" value={ m.ID }/>
|
|
<span></span>
|
|
<span class="flex gap-2">
|
|
<input data-field="section" value={ m.Section } placeholder={ i18n.T(ctx, "pages.section") } class="w-1/2 border border-rule bg-transparent px-2 py-1 text-xs outline-none focus:border-ink"/>
|
|
<input data-field="label" value={ m.Label } placeholder={ i18n.T(ctx, "pages.label") } class="w-1/2 border border-rule bg-transparent px-2 py-1 text-xs outline-none focus:border-ink"/>
|
|
</span>
|
|
</li>
|
|
}
|
|
</ul>
|
|
@submit(i18n.T(ctx, "common.save"))
|
|
</form>
|
|
</section>
|
|
<section>
|
|
@sectionHeading("pages.domain")
|
|
<form data-api={ "/org/statuspages/" + e.ID + "/domain" } data-method="put" data-next={ "/statuspages/" + e.ID }>
|
|
@formError()
|
|
@valueField(i18n.T(ctx, "pages.domain_name"), "domain", e.Domain, "status.example.com", false)
|
|
@submit(i18n.T(ctx, "common.save"))
|
|
</form>
|
|
if e.Domain != "" {
|
|
<div class="mt-6 border border-rule p-4 text-sm">
|
|
if e.DomainVerified {
|
|
<p><span class="text-up">●</span> { i18n.T(ctx, "pages.domain_verified") }</p>
|
|
<p class="mt-2 text-xs text-muted">{ i18n.T(ctx, "pages.domain_cname") }</p>
|
|
} else {
|
|
<p class="mb-3">{ i18n.T(ctx, "pages.domain_instructions") }</p>
|
|
<dl class="mb-4 grid grid-cols-[max-content_1fr] gap-x-4 gap-y-1 font-mono text-xs">
|
|
<dt class="text-muted">TXT</dt>
|
|
<dd class="break-all">{ e.RecordName }</dd>
|
|
<dt class="text-muted">{ i18n.T(ctx, "pages.value") }</dt>
|
|
<dd class="break-all">{ e.RecordValue }</dd>
|
|
</dl>
|
|
<button type="button" data-post={ "/org/statuspages/" + e.ID + "/domain/verify" } data-ok={ i18n.T(ctx, "pages.domain_verified") } data-reload class="border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper">{ i18n.T(ctx, "pages.verify") }</button>
|
|
}
|
|
</div>
|
|
}
|
|
</section>
|
|
</div>
|
|
</div>
|
|
}
|
|
}
|