feat(statuspage): add nested status page groups and optional component details
This commit is contained in:
1 parent
1c31003baf
commit
9b26b4150e
26 files changed
+4566
-760
No files matched your search
@@ -1,6 +1,10 @@
|
||||
package web
|
||||
|
||||
import "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
|
||||
)
|
||||
|
||||
// PageRow is a status page in the list.
|
||||
type PageRow struct {
|
||||
@@ -58,15 +62,26 @@ templ StatusPagesPage(p Page, me Me, v PagesView) {
|
||||
}
|
||||
}
|
||||
|
||||
// PageMonitorOption is a monitor in the page editor.
|
||||
type PageMonitorOption struct {
|
||||
// PageGroupRow is one nested group of a status page in tree order.
|
||||
type PageGroupRow struct {
|
||||
ID string
|
||||
Name string
|
||||
Included bool
|
||||
Section string
|
||||
ParentID string
|
||||
Position int
|
||||
Depth int
|
||||
Label string
|
||||
}
|
||||
|
||||
// PageMonitorOption is a monitor in the page editor.
|
||||
type PageMonitorOption struct {
|
||||
ID string
|
||||
Name string
|
||||
MonitorGroupPath string
|
||||
Included bool
|
||||
GroupID string
|
||||
Label string
|
||||
}
|
||||
|
||||
// PageEditor is the data of the status page editor.
|
||||
type PageEditor struct {
|
||||
ID string
|
||||
@@ -74,6 +89,7 @@ type PageEditor struct {
|
||||
Slug string
|
||||
Description string
|
||||
Published bool
|
||||
ShowDetails bool
|
||||
Accent string
|
||||
LogoURL string
|
||||
CSS string
|
||||
@@ -82,6 +98,8 @@ type PageEditor struct {
|
||||
DomainVerified bool
|
||||
RecordName string
|
||||
RecordValue string
|
||||
Groups []PageGroupRow
|
||||
HasOrgGroups bool
|
||||
Monitors []PageMonitorOption
|
||||
}
|
||||
|
||||
@@ -109,6 +127,8 @@ templ StatusPageEditor(p Page, me Me, e PageEditor) {
|
||||
@MarkdownEditor("description", e.Description, 5, 10000, MarkdownInline)
|
||||
</div>
|
||||
@checkbox(i18n.T(ctx, "pages.published"), "published", e.Published)
|
||||
@checkbox(i18n.T(ctx, "pages.show_details"), "show_component_details", e.ShowDetails)
|
||||
<p class="-mt-2 mb-4 text-xs text-muted">{ i18n.T(ctx, "pages.show_details_hint") }</p>
|
||||
<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)
|
||||
@@ -127,6 +147,90 @@ templ StatusPageEditor(p Page, me Me, e PageEditor) {
|
||||
>{ i18n.T(ctx, "pages.delete") }</button>
|
||||
</section>
|
||||
<div>
|
||||
<section class="mb-12">
|
||||
<div class="mb-3 flex flex-wrap items-baseline justify-between gap-2">
|
||||
@sectionHeading("pages.groups")
|
||||
if e.HasOrgGroups {
|
||||
<button
|
||||
type="button"
|
||||
data-post={ "/org/statuspages/" + e.ID + "/groups/import" }
|
||||
data-confirm={ i18n.T(ctx, "pages.groups_import_confirm") }
|
||||
data-ok={ i18n.T(ctx, "pages.groups_imported") }
|
||||
data-reload
|
||||
class="border border-rule px-2.5 py-1 text-xs hover:border-ink"
|
||||
>{ i18n.T(ctx, "pages.groups_import") }</button>
|
||||
}
|
||||
</div>
|
||||
<p class="mb-4 text-xs text-muted">{ i18n.T(ctx, "pages.groups_intro") }</p>
|
||||
if len(e.Groups) > 0 {
|
||||
<ul class="mb-4 divide-y divide-rule border-y border-rule text-sm">
|
||||
for _, g := range e.Groups {
|
||||
<li class="py-2" style={ indent(g.Depth) }>
|
||||
<details>
|
||||
<summary class="flex cursor-pointer items-center justify-between gap-2 select-none hover:text-ink">
|
||||
<span>{ g.Name }</span>
|
||||
<span class="text-xs text-muted">{ i18n.T(ctx, "common.edit") }</span>
|
||||
</summary>
|
||||
<form data-api={ "/org/statuspages/" + e.ID + "/groups/" + g.ID } data-method="put" data-next={ "/statuspages/" + e.ID } class="mt-3 max-w-sm">
|
||||
@formError()
|
||||
@valueField(i18n.T(ctx, "sso.field.name"), "name", g.Name, "", true)
|
||||
<label class="mb-3 block">
|
||||
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "groups.parent") }</span>
|
||||
<select name="parent_id" data-nullable class={ inputClass }>
|
||||
<option value="">{ i18n.T(ctx, "groups.none") }</option>
|
||||
for _, opt := range e.Groups {
|
||||
if opt.ID != g.ID {
|
||||
<option value={ opt.ID } selected?={ opt.ID == g.ParentID }>{ opt.Label }</option>
|
||||
}
|
||||
}
|
||||
</select>
|
||||
</label>
|
||||
<label class="mb-3 block">
|
||||
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "pages.group_position") }</span>
|
||||
<input type="number" name="position" data-number value={ strconv.Itoa(g.Position) } class={ inputClass }/>
|
||||
</label>
|
||||
<div class="flex items-center gap-4">
|
||||
@submit(i18n.T(ctx, "common.save"))
|
||||
<button
|
||||
type="button"
|
||||
data-delete={ "/org/statuspages/" + e.ID + "/groups/" + g.ID }
|
||||
data-confirm={ i18n.T(ctx, "groups.delete_confirm") }
|
||||
data-next={ "/statuspages/" + e.ID }
|
||||
class="text-sm text-down hover:underline"
|
||||
>{ i18n.T(ctx, "common.delete") }</button>
|
||||
</div>
|
||||
</form>
|
||||
</details>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
<form data-api={ "/org/statuspages/" + e.ID + "/groups" } data-next={ "/statuspages/" + e.ID } class="border border-rule p-3">
|
||||
@formError()
|
||||
<div class="grid gap-3 sm:grid-cols-[1fr_1fr_5rem]">
|
||||
<label class="block">
|
||||
<span class="mb-1 block text-xs text-muted">{ i18n.T(ctx, "groups.create") }</span>
|
||||
<input name="name" required maxlength="100" placeholder={ i18n.T(ctx, "sso.field.name") } class={ inputClass }/>
|
||||
</label>
|
||||
<label class="block">
|
||||
<span class="mb-1 block text-xs text-muted">{ i18n.T(ctx, "groups.parent") }</span>
|
||||
<select name="parent_id" data-nullable class={ inputClass }>
|
||||
<option value="">{ i18n.T(ctx, "groups.none") }</option>
|
||||
for _, opt := range e.Groups {
|
||||
<option value={ opt.ID }>{ opt.Label }</option>
|
||||
}
|
||||
</select>
|
||||
</label>
|
||||
<label class="block">
|
||||
<span class="mb-1 block text-xs text-muted">{ i18n.T(ctx, "pages.group_position") }</span>
|
||||
<input type="number" name="position" data-number value={ strconv.Itoa(len(e.Groups)) } class={ inputClass }/>
|
||||
</label>
|
||||
</div>
|
||||
<div class="mt-3">
|
||||
@submit(i18n.T(ctx, "groups.create"))
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
<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 }>
|
||||
@@ -138,11 +242,21 @@ templ StatusPageEditor(p Page, me Me, e PageEditor) {
|
||||
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>
|
||||
<span class="flex flex-wrap items-baseline gap-x-2">
|
||||
<span>{ m.Name }</span>
|
||||
if m.MonitorGroupPath != "" {
|
||||
<span class="font-mono text-xs text-muted">{ m.MonitorGroupPath }</span>
|
||||
}
|
||||
</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"/>
|
||||
<select data-field="group_id" data-nullable aria-label={ i18n.T(ctx, "pages.group") } class="w-1/2 border border-rule bg-transparent px-2 py-1 text-xs outline-none focus:border-ink">
|
||||
<option value="">{ i18n.T(ctx, "pages.no_group") }</option>
|
||||
for _, opt := range e.Groups {
|
||||
<option value={ opt.ID } selected?={ opt.ID == m.GroupID }>{ opt.Label }</option>
|
||||
}
|
||||
</select>
|
||||
<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>
|
||||
|
||||
Reference in new issue
Block a user