feat: notification channels for chat, push and paging services
Channels of the new types store their settings with secrets sealed and bound to type and field, never return them, and keep them when an update leaves them empty. Messages are rendered in the channel's language with a link to the monitor. The channels page offers every service with its fields. Closes #92 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
a0a67ec5f8
commit
b01eefdbce
12 files changed
+1114
-134
No files matched your search
@@ -766,6 +766,7 @@ type ChannelsView struct {
|
||||
EmailAvailable bool
|
||||
CanWrite bool
|
||||
Languages []string
|
||||
Providers []ProviderOption
|
||||
}
|
||||
|
||||
templ ChannelsPage(p Page, me Me, v ChannelsView) {
|
||||
@@ -834,11 +835,98 @@ templ ChannelsPage(p Page, me Me, v ChannelsView) {
|
||||
<p class="text-sm text-muted">{ i18n.T(ctx, "error.email_not_configured") }</p>
|
||||
}
|
||||
</section>
|
||||
<section class="md:col-span-2">
|
||||
@sectionHeading("channels.new_service")
|
||||
<p class="mb-4 max-w-2xl text-sm text-muted">{ i18n.T(ctx, "channels.service_intro") }</p>
|
||||
<form data-api="/org/channels" data-next="/settings/channels" class="grid gap-x-8 md:grid-cols-2">
|
||||
<div>
|
||||
@formError()
|
||||
<label class="mb-4 block">
|
||||
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "channels.service") }</span>
|
||||
<select name="type" data-type-select class="w-full border border-rule bg-transparent px-2 py-1.5 text-sm">
|
||||
for _, pr := range v.Providers {
|
||||
<option value={ pr.Type }>{ i18n.T(ctx, "channels.type_"+pr.Type) }</option>
|
||||
}
|
||||
</select>
|
||||
</label>
|
||||
@valueField(i18n.T(ctx, "sso.field.name"), "name", "", "Ops", true)
|
||||
<label class="mb-4 block">
|
||||
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "channels.language") }</span>
|
||||
<select name="locale" class="w-40 border border-rule bg-transparent px-2 py-1.5 text-sm">
|
||||
for _, l := range v.Languages {
|
||||
<option value={ l } selected?={ l == i18n.Lang(ctx) }>{ i18n.T(ctx, "lang."+l) }</option>
|
||||
}
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
for i, pr := range v.Providers {
|
||||
<fieldset data-type={ pr.Type } disabled?={ i != 0 } hidden?={ i != 0 }>
|
||||
if pr.Help != "" {
|
||||
<p class="mb-3 text-xs text-muted">{ pr.Help }</p>
|
||||
}
|
||||
for _, f := range pr.Fields {
|
||||
@providerField(f)
|
||||
}
|
||||
</fieldset>
|
||||
}
|
||||
@submit(i18n.T(ctx, "channels.create"))
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ProviderOption is a notification service the form offers.
|
||||
type ProviderOption struct {
|
||||
Type string
|
||||
Help string
|
||||
Fields []ProviderField
|
||||
}
|
||||
|
||||
// ProviderField is a setting of a service.
|
||||
type ProviderField struct {
|
||||
Name string
|
||||
Label string
|
||||
Required bool
|
||||
Secret bool
|
||||
Kind string
|
||||
Options []string
|
||||
Default string
|
||||
}
|
||||
|
||||
templ providerField(f ProviderField) {
|
||||
<label class="mb-4 block">
|
||||
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">
|
||||
{ f.Label }
|
||||
if !f.Required {
|
||||
<span class="normal-case tracking-normal">{ " · " + i18n.T(ctx, "channels.optional") }</span>
|
||||
}
|
||||
</span>
|
||||
switch {
|
||||
case f.Kind == "select":
|
||||
<select name={ "settings." + f.Name } class="w-full border border-rule bg-transparent px-2 py-1.5 font-mono text-sm">
|
||||
for _, o := range f.Options {
|
||||
<option value={ o } selected?={ o == f.Default }>{ o }</option>
|
||||
}
|
||||
</select>
|
||||
case f.Secret:
|
||||
<input type="password" name={ "settings." + f.Name } required?={ f.Required } autocomplete="off" class="w-full border border-rule bg-transparent px-2.5 py-1.5 font-mono text-sm outline-none focus:border-ink"/>
|
||||
default:
|
||||
<input
|
||||
type={ map[bool]string{true: "number", false: "text"}[f.Kind == "number"] }
|
||||
name={ "settings." + f.Name }
|
||||
value={ f.Default }
|
||||
required?={ f.Required }
|
||||
placeholder={ map[bool]string{true: "https://", false: ""}[f.Kind == "url"] }
|
||||
class="w-full border border-rule bg-transparent px-2.5 py-1.5 font-mono text-sm outline-none focus:border-ink"
|
||||
/>
|
||||
}
|
||||
</label>
|
||||
}
|
||||
|
||||
templ groupSelect(name string, groups []GroupOption, selected string, allowNone bool) {
|
||||
<select name={ name } data-nullable class="w-full border border-rule bg-transparent px-2 py-1.5 text-sm">
|
||||
if allowNone {
|
||||
|
||||
Reference in new issue
Block a user