Files
uptimesebi/internal/web/alert_groups.templ
Sebastian Unterschütz ef7e12a52d
ci / image (pull_request) Successful in 4m27s
ci / test (pull_request) Successful in 8m36s
ci / build (pull_request) Successful in 12m29s
ci / lint (pull_request) Successful in 12m51s
fix(alerting): refresh channel groups after webhook creation
2026-11-22 18:30:46 +01:00

78 lines
2.7 KiB
Templ

package web
import "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
// AlertGroupOption is a selectable group or channel in an alert routing form.
type AlertGroupOption struct {
ID string
Name string
Default bool
Checked bool
}
// AlertGroupRow describes a group and its available notification channels.
type AlertGroupRow struct {
ID string
Name string
Default bool
Channels []AlertGroupOption
}
templ alertGroupOptions(name string, options []AlertGroupOption) {
<input type="hidden" name={ name } data-multi/>
for _, opt := range options {
<label class="mb-2 flex items-center gap-2 text-sm">
<input type="checkbox" name={ name } value={ opt.ID } data-multi checked?={ opt.Checked }/>
<span>{ opt.Name }</span>
if opt.Default {
<span class="text-xs text-muted">{ i18n.T(ctx, "alert_groups.default") }</span>
}
</label>
}
}
templ alertGroupsSettings(v ChannelsView) {
<section id="alert-groups" class="mb-12">
@sectionHeading("alert_groups.title")
<p class="mb-6 max-w-2xl text-sm text-muted">{ i18n.T(ctx, "alert_groups.intro") }</p>
<div class="grid gap-6 md:grid-cols-2">
for _, g := range v.AlertGroups {
<form data-api={ "/org/alert-groups/" + g.ID } data-method="put" data-next="/settings/channels" class="border border-rule p-4">
@formError()
if g.Default {
<p class="mb-3 text-xs text-muted">{ i18n.T(ctx, "alert_groups.default") }</p>
}
<fieldset disabled?={ !v.CanWrite }>
@valueField(i18n.T(ctx, "sso.field.name"), "name", g.Name, "", true)
@alertGroupOptions("channel_ids", g.Channels)
if len(g.Channels) == 0 {
<p class="mb-4 text-sm text-muted">{ i18n.T(ctx, "alert_groups.no_channels") }</p>
}
if v.CanWrite {
@submit(i18n.T(ctx, "alert_groups.save"))
}
</fieldset>
if v.CanWrite && !g.Default {
<button type="button" data-delete={ "/org/alert-groups/" + g.ID } data-confirm={ i18n.T(ctx, "alert_groups.delete_confirm") } class="mt-3 text-sm text-muted hover:text-down">{ i18n.T(ctx, "regions.delete") }</button>
}
</form>
}
if v.CanWrite {
<form data-api="/org/alert-groups" data-next="/settings/channels" class="border border-rule p-4">
@sectionHeading("alert_groups.new")
@formError()
@valueField(i18n.T(ctx, "sso.field.name"), "name", "", "", true)
<input type="hidden" name="channel_ids" data-multi/>
for _, ch := range v.Channels {
<label class="mb-2 flex items-center gap-2 text-sm">
<input type="checkbox" name="channel_ids" value={ ch.ID } data-multi/>
<span>{ ch.Name }</span>
</label>
}
@submit(i18n.T(ctx, "alert_groups.create"))
</form>
}
</div>
</section>
}