package web import ( "strconv" "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n" ) // SupportTicket is a ticket as the support pages show it; User and Org // are filled for admins. type SupportTicket struct { ID, Subject, Status string User, Org string Updated string References []SupportReference Messages []SupportMessage } // SupportReference is something a ticket points at; Kind is org, monitor, // channel, alert_group, status_page or incident. type SupportReference struct { Kind, Name string } // SupportMessage is one message of a ticket, rendered from Markdown. type SupportMessage struct { FromStaff bool // Author is the admin who answered, for admins only. Author string HTML string At string } // SupportOptions are what of the active organization a new ticket can // point at; Org is empty without one. type SupportOptions struct { Org string Monitors, Channels, AlertGroups, StatusPages, Incidents []SupportOption } // SupportOption is one choice of SupportOptions. type SupportOption struct { ID, Name string } // SupportSettings are how the platform runs support, for its admins. type SupportSettings struct { Enabled bool MaxOpen int } // SupportAccount is what admins see about the account behind a ticket. type SupportAccount struct { ID, Email, Name, Created, Locale string Verified, TOTP, Password, Admin bool Suspended bool SuspendedReason string OrgsOwned, OrgLimit int OpenTickets int64 Orgs []SupportOrg } // SupportOrg is an organization of the account with its limits; Current // marks the one the ticket names. Limits of 0 are unlimited. type SupportOrg struct { Name, Slug string Owner, Current, Suspended bool SuspendedReason string Monitors, MonitorLimit int StatusPages, StatusPageLimit int RegionsPerMonitor int } // SupportStatuses are the states of a ticket, in the order admins filter // them. var SupportStatuses = []string{"open", "answered", "closed"} var supportFilters = append(append([]string{}, SupportStatuses...), "all") // supportBase is where the support pages live for staff or the account. func supportBase(staff bool) string { if staff { return "/admin/support" } return "/support" } func supportAPI(t SupportTicket, staff bool) string { return supportBase(staff) + "/tickets/" + t.ID } // usageText shows used of limit, ∞ for no limit. func usageText(used, limit int) string { if limit <= 0 { return strconv.Itoa(used) + " / ∞" } return strconv.Itoa(used) + " / " + strconv.Itoa(limit) } templ supportStatusLabel(status string) { { i18n.T(ctx, "support.status."+status) } } templ supportList(tickets []SupportTicket, base string, staff bool) { } templ supportSelect(labelID, name string, opts []SupportOption) { if len(opts) > 0 { } } templ SupportPage(p Page, me Me, tickets []SupportTicket, opts SupportOptions) { @consoleShell(p, me) { @settingsHeading("support.title", "support.intro")
@sectionHeading("support.mine") if len(tickets) == 0 {

{ i18n.T(ctx, "support.none") }

} else { @supportList(tickets, "/support/", false) }
} } templ SupportDisabledPage(p Page, me Me) { @consoleShell(p, me) { @settingsHeading("support.title", "")

{ i18n.T(ctx, "support.disabled") }

} } templ supportReferences(refs []SupportReference) { if len(refs) > 0 {
for _, r := range refs {
{ i18n.T(ctx, "support.ref."+r.Kind) }
{ r.Name }
}
} } templ supportFlag(on bool, yesID, noID string) { if on { { i18n.T(ctx, yesID) } } else { { i18n.T(ctx, noID) } } } // supportAccountBox gives admins the account behind a ticket at a glance. templ supportAccountBox(a SupportAccount) { } // SupportTicketPage shows a ticket's conversation to its account or, with // the account's details, to the admins. templ SupportTicketPage(p Page, me Me, t SupportTicket, account *SupportAccount) { @consoleShell(p, me) {

{ "← " + i18n.T(ctx, "support.all") }

{ t.Subject }

@supportStatusLabel(t.Status) if account != nil { { t.User } }
@supportReferences(t.References)
    for _, m := range t.Messages {
  1. switch { case m.FromStaff && m.Author != "": { i18n.T(ctx, "support.from_staff") + " · " + m.Author } case m.FromStaff: { i18n.T(ctx, "support.from_staff") } case account != nil: { t.User } default: { i18n.T(ctx, "support.from_you") } } { m.At }

  2. }
@sectionHeading("support.reply") if t.Status == "closed" && account == nil {

{ i18n.T(ctx, "support.closed_hint") }

}
@formError()
@MarkdownEditor("message", "", 6, 10000, MarkdownInline)
@submit(i18n.T(ctx, "support.send"))
@formError() if t.Status == "closed" { } else { }
if account != nil { @supportAccountBox(*account) }
} } templ AdminSupportPage(p Page, me Me, tickets []SupportTicket, filter string, settings SupportSettings) { @consoleShell(p, me) { @settingsHeading("support.admin_title", "support.admin_intro") @adminLinks()
{ i18n.T(ctx, "support.settings") } if settings.Enabled { { i18n.T(ctx, "support.settings.on") } } else { { i18n.T(ctx, "support.settings.off") } }
@formError() @checkbox(i18n.T(ctx, "support.settings.enabled"), "enabled", settings.Enabled)

{ i18n.T(ctx, "support.settings.enabled_hint") }

@submit(i18n.T(ctx, "support.settings.save"))
if len(tickets) == 0 {

{ i18n.T(ctx, "support.none_admin") }

} else { @supportList(tickets, "/admin/support/", true) } } }