High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.
JavaScript campaigncampaign-managementemail-marketingemail-subscriptionlistmonkmailing-listnewsletternewsletter-managementnewsletter-softwareself-hostedsms-gatewaysmtptransactional-emails
Standardise enum filtering on entity list pages (lists, subscribers etc.) and add filtering to 'Users' page also.
Kailash Nadha7604c79133e
diff --git a/cmd/bounce.go b/cmd/bounce.goindex 0cdeef1d..86482107 100644--- a/cmd/bounce.go+++ b/cmd/bounce.go@@ -12,6 +12,16 @@ import ("github.com/labstack/echo/v4")+// bouncesQueryDefaults is the allowlist of filter query params.+var bouncesQueryDefaults = map[string]string{+ "page": "",+ "order_by": "",+ "order": "",+ "source": "",+ "type": "",+ "campaign_id": "",+}+// bouncesView is the admin page view for the bounces list page.type bouncesView struct {adminView@@ -22,14 +32,7 @@ type bouncesView struct {// ViewBounces renders the HTML view for bounces.func (a *App) ViewBounces(c echo.Context) error {- q := makeQuery(c.Request().URL.Query(), map[string]string{- "page": "",- "order_by": "",- "order": "",- "source": "",- "type": "",- "campaign_id": "",- })+ q := makeQuery(c.Request().URL.Query(), bouncesQueryDefaults)campID, _ := strconv.Atoi(q.Get("campaign_id"))diff --git a/cmd/campaigns.go b/cmd/campaigns.goindex 05324a17..a790038f 100644--- a/cmd/campaigns.go+++ b/cmd/campaigns.go@@ -49,6 +49,17 @@ type campContentReq struct {var (reFromAddress = regexp.MustCompile(`((.+?)\s)?<(.+?)@(.+?)>`)reSlug = regexp.MustCompile(`[^\p{L}\p{M}\p{N}]`)++ // campaignsQueryDefaults is the allow list of filter query params.+ campaignsQueryDefaults = map[string]string{+ "page": "",+ "query": "",+ "order_by": "",+ "order": "",+ "status": "",+ "type": "",+ "tag": "",+ })// campaignsView is the admin page view for the campaigns list page.@@ -193,14 +204,7 @@ func (a *App) ViewCampaigns(c echo.Context) error {// getViewCampaigns queries paginated campaigns for the HTML list view.func (a *App) getViewCampaigns(c echo.Context) ([]models.Campaign, models.PageProps, error) {- q := makeQuery(c.Request().URL.Query(), map[string]string{- "page": "",- "query": "",- "order_by": "",- "order": "",- "status": "",- "tag": "",- })+ q := makeQuery(c.Request().URL.Query(), campaignsQueryDefaults)// Get the authenticated user.user := auth.GetUser(c)@@ -215,7 +219,7 @@ func (a *App) getViewCampaigns(c echo.Context) ([]models.Campaign, models.PagePr// Run the DB query.pg := a.pg.NewFromURL(q)- res, total, err := a.core.QueryCampaigns(q.Get("query"), q["status"], q["tag"],+ res, total, err := a.core.QueryCampaigns(q.Get("query"), q["status"], q["tag"], q.Get("type"),q.Get("order_by"), q.Get("order"), hasAllPerm, permittedLists, pg.Offset, pg.Limit)if err != nil {return nil, models.PageProps{}, err@@ -251,6 +255,7 @@ func (a *App) GetCampaigns(c echo.Context) error {status = c.QueryParams()["status"]tags = c.QueryParams()["tag"]+ typ = c.QueryParam("type")query = strings.TrimSpace(c.FormValue("query"))orderBy = c.FormValue("order_by")order = c.FormValue("order")@@ -258,7 +263,7 @@ func (a *App) GetCampaigns(c echo.Context) error {)// Query and retrieve campaigns from the DB.- res, total, err := a.core.QueryCampaigns(query, status, tags, orderBy, order, hasAllPerm, permittedLists, pg.Offset, pg.Limit)+ res, total, err := a.core.QueryCampaigns(query, status, tags, typ, orderBy, order, hasAllPerm, permittedLists, pg.Offset, pg.Limit)if err != nil {return err}diff --git a/cmd/dashboard.go b/cmd/dashboard.goindex b5152f63..cac11b4a 100644--- a/cmd/dashboard.go+++ b/cmd/dashboard.go@@ -133,7 +133,7 @@ func (a *App) getDashboardCampaigns(c echo.Context) (models.Campaigns, error) {}// Get scheduled campaigns to show on top of the dashboard.- camps, _, err := a.core.QueryCampaigns("", []string{models.CampaignStatusScheduled}, nil, "created_at", "desc", hasAllPerm, permittedLists, 0, dashboardCampaignCount)+ camps, _, err := a.core.QueryCampaigns("", []string{models.CampaignStatusScheduled}, nil, "", "created_at", "desc", hasAllPerm, permittedLists, 0, dashboardCampaignCount)if err != nil {return nil, err}@@ -146,7 +146,7 @@ func (a *App) getDashboardCampaigns(c echo.Context) (models.Campaigns, error) {models.CampaignStatusPaused,models.CampaignStatusFinished,models.CampaignStatusCancelled,- }, nil, "created_at", "desc", hasAllPerm, permittedLists, 0, rem)+ }, nil, "", "created_at", "desc", hasAllPerm, permittedLists, 0, rem)if err != nil {return nil, err}diff --git a/cmd/lists.go b/cmd/lists.goindex 5175eb36..3d03526b 100644--- a/cmd/lists.go+++ b/cmd/lists.go@@ -9,6 +9,19 @@ import ("github.com/labstack/echo/v4")+// listsQueryDefaults is the allow list of filter query params.+var listsQueryDefaults = map[string]string{+ "page": "",+ "minimal": "",+ "query": "",+ "order_by": "",+ "order": "",+ "tag": "",+ "type": "",+ "optin": "",+ "status": models.ListStatusActive,+}+// listsView is the admin page view.type listsView struct {adminView@@ -270,15 +283,7 @@ func (a *App) DeleteLists(c echo.Context) error {}func (a *App) getLists(c echo.Context) ([]models.List, models.PageProps, error) {- q := makeQuery(c.Request().URL.Query(), map[string]string{- "page": "",- "minimal": "",- "query": "",- "order_by": "",- "order": "",- "tag": "",- "status": models.ListStatusActive,- })+ q := makeQuery(c.Request().URL.Query(), listsQueryDefaults)// Get the authenticated user.user := auth.GetUser(c)diff --git a/cmd/media.go b/cmd/media.goindex 8c3e1a70..cbb06ddf 100644--- a/cmd/media.go+++ b/cmd/media.go@@ -66,12 +66,15 @@ func (a *App) ViewMediaFragment(c echo.Context) error {return c.Render(http.StatusOK, "admin-media-fragment", data)}+// mediaQueryDefaults is the allow list of filter query params.+var mediaQueryDefaults = map[string]string{+ "page": "",+ "query": "",+}+// getMedia queries paginated media items from the DB.func (a *App) getMedia(c echo.Context) ([]media.Media, models.PageProps, error) {- q := makeQuery(c.Request().URL.Query(), map[string]string{- "page": "",- "query": "",- })+ q := makeQuery(c.Request().URL.Query(), mediaQueryDefaults)pg := a.pg.NewFromURL(q)pg.Limit = 100diff --git a/cmd/subscribers.go b/cmd/subscribers.goindex e124fd90..2c9a44f4 100644--- a/cmd/subscribers.go+++ b/cmd/subscribers.go@@ -24,6 +24,16 @@ const (dummyUUID = "00000000-0000-0000-0000-000000000000")+// subscribersQueryDefaults is the allow list of filter query params.+var subscribersQueryDefaults = map[string]string{+ "page": "",+ "search": "",+ "query": "",+ "order_by": "",+ "order": "",+ "subscription_status": "",+}+// subQueryReq is a "catch all" struct for reading various// subscriber related requests.type subQueryReq struct {@@ -249,14 +259,7 @@ func (a *App) getSubscribers(c echo.Context, listID int) ([]models.Subscriber, mreturn nil, models.PageProps{}, err}- q := makeQuery(params, map[string]string{- "page": "",- "search": "",- "query": "",- "order_by": "",- "order": "",- "subscription_status": "",- })+ q := makeQuery(params, subscribersQueryDefaults)// Get the authenticated user.user := auth.GetUser(c)diff --git a/cmd/templates.go b/cmd/templates.goindex 206a6131..a7dd8158 100644--- a/cmd/templates.go+++ b/cmd/templates.go@@ -36,6 +36,7 @@ type templatesView struct {adminViewTemplates []models.Template+ Type string}// templateView is the admin page view for creating/editing a single template.@@ -48,7 +49,9 @@ type templateView struct {// ViewTemplates renders the HTML list view for templates.func (a *App) ViewTemplates(c echo.Context) error {- out, err := a.core.GetTemplates("", true)+ typ := c.QueryParam("type")++ out, err := a.core.GetTemplates(typ, true)if err != nil {return err}@@ -56,6 +59,7 @@ func (a *App) ViewTemplates(c echo.Context) error {data := templatesView{adminView: newAdminView(c, a.i18n.T("globals.terms.templates"), "", "campaigns.templates"),Templates: out,+ Type: typ,}return c.Render(http.StatusOK, "admin-templates", data)diff --git a/cmd/users.go b/cmd/users.goindex e255aab1..4afd8975 100644--- a/cmd/users.go+++ b/cmd/users.go@@ -3,6 +3,7 @@ package mainimport ("net/http""regexp"+ "strconv""strings""github.com/knadh/listmonk/internal/auth"@@ -16,6 +17,14 @@ import (var (reUsername = regexp.MustCompile(`^[a-zA-Z0-9_\-\.@]+$`)++ // usersQueryDefaults is the allow list of filter query params.+ usersQueryDefaults = map[string]string{+ "type": "",+ "status": "",+ "user_role_id": "",+ "list_role_id": "",+ })// usersView is the admin page view for the users list page.@@ -23,6 +32,15 @@ type usersView struct {adminViewUsers []auth.User+ Page models.PageProps++ // Filters.+ Type string+ Status string+ UserRoleID int+ UserRoleName string+ ListRoleID int+ ListRoleName string}// userView is the admin page view for a single user's add/edit form.@@ -41,21 +59,45 @@ func (a *App) ViewUsers(c echo.Context) error {return auth.ErrPermDenied}- users, err := a.core.GetUsers()+ // Whitelisted filter params.+ q := makeQuery(c.Request().URL.Query(), usersQueryDefaults)+ var (+ fType = q.Get("type")+ fStatus = q.Get("status")+ fUserRole, _ = strconv.Atoi(q.Get("user_role_id"))+ fListRole, _ = strconv.Atoi(q.Get("list_role_id"))+ )++ // Filtering is done in SQL.+ users, err := a.core.GetUsers(fType, fStatus, fUserRole, fListRole)if err != nil {return err}- // Blank out the password hashes.+ data := usersView{+ adminView: newAdminView(c, a.i18n.T("globals.terms.users"), "", "users.users"),+ Type: fType,+ Status: fStatus,+ UserRoleID: fUserRole,+ ListRoleID: fListRole,+ }+for n := range users {+ // Empty the password hash.users[n].Password = null.String{}- }- data := usersView{- adminView: newAdminView(c, a.i18n.T("globals.terms.users"), "", "users.users"),- Users: users,+ // Capture the role names for rendering in the filter badges on the admin UI.+ if fUserRole > 0 {+ data.UserRoleName = users[n].UserRole.Name+ }+ if fListRole > 0 && users[n].ListRole != nil {+ data.ListRoleName = users[n].ListRole.Name+ }}+ data.Users = users+ data.Page = models.NewPageProps(q, len(users), 1, 0)+return c.Render(http.StatusOK, "admin-users", data)}@@ -156,7 +198,7 @@ func (a *App) GetUser(c echo.Context) error {// GetUsers retrieves all users.func (a *App) GetUsers(c echo.Context) error {// Get all users from the DB.- out, err := a.core.GetUsers()+ out, err := a.core.GetUsers("", "", 0, 0)if err != nil {return err}@@ -484,7 +526,7 @@ func (a *App) DisableTOTP(c echo.Context) error {// It also returns a bool indicating whether there are any actual users in the DB at all,// which if there aren't, the first time user setup needs to be run.func cacheUsers(co *core.Core, a *auth.Auth) (bool, error) {- users, err := co.GetUsers()+ users, err := co.GetUsers("", "", 0, 0)if err != nil {return false, err}diff --git a/internal/core/campaigns.go b/internal/core/campaigns.goindex 65c9509a..2ef489b6 100644--- a/internal/core/campaigns.go+++ b/internal/core/campaigns.go@@ -23,7 +23,7 @@ const (// QueryCampaigns retrieves paginated campaigns optionally filtering them by the given arbitrary// query expression. It also returns the total number of records in the DB.-func (c *Core) QueryCampaigns(searchStr string, statuses, tags []string, orderBy, order string, getAll bool, permittedLists []int, offset, limit int) (models.Campaigns, int, error) {+func (c *Core) QueryCampaigns(searchStr string, statuses, tags []string, typ, orderBy, order string, getAll bool, permittedLists []int, offset, limit int) (models.Campaigns, int, error) {queryStr, stmt := makeSearchQuery(searchStr, orderBy, order, c.q.QueryCampaigns, campQuerySortFields)if statuses == nil {@@ -36,7 +36,7 @@ func (c *Core) QueryCampaigns(searchStr string, statuses, tags []string, orderBy// Unsafe to ignore scanning fields not present in models.Campaigns.var out models.Campaigns- if err := c.db.Select(&out, stmt, 0, pq.StringArray(statuses), pq.StringArray(tags), queryStr, getAll, pq.Array(permittedLists), offset, limit); err != nil {+ if err := c.db.Select(&out, stmt, 0, pq.StringArray(statuses), pq.StringArray(tags), queryStr, typ, getAll, pq.Array(permittedLists), offset, limit); err != nil {c.log.Printf("error fetching campaigns: %v", err)return nil, 0, echo.NewHTTPError(http.StatusInternalServerError,c.i18n.Ts("globals.messages.errorFetching", "name", "{globals.terms.campaign}", "error", pqErrMsg(err)))diff --git a/internal/core/templates.go b/internal/core/templates.goindex 7ae8d82b..132dbc3e 100644--- a/internal/core/templates.go+++ b/internal/core/templates.go@@ -10,9 +10,9 @@ import ()// GetTemplates retrieves all templates.-func (c *Core) GetTemplates(status string, noBody bool) ([]models.Template, error) {+func (c *Core) GetTemplates(typ string, noBody bool) ([]models.Template, error) {out := []models.Template{}- if err := c.q.GetTemplates.Select(&out, 0, noBody, status); err != nil {+ if err := c.q.GetTemplates.Select(&out, 0, noBody, typ); err != nil {return nil, echo.NewHTTPError(http.StatusInternalServerError,c.i18n.Ts("globals.messages.errorFetching", "name", "{globals.terms.templates}", "error", pqErrMsg(err)))}diff --git a/internal/core/users.go b/internal/core/users.goindex 125bc301..3652169d 100644--- a/internal/core/users.go+++ b/internal/core/users.go@@ -13,9 +13,10 @@ import ("gopkg.in/volatiletech/null.v6")-func (c *Core) GetUsers() ([]auth.User, error) {+// GetUsers retrieves users.+func (c *Core) GetUsers(typ, status string, userRoleID, listRoleID int) ([]auth.User, error) {out := []auth.User{}- if err := c.q.GetUsers.Select(&out); err != nil {+ if err := c.q.GetUsers.Select(&out, typ, status, userRoleID, listRoleID); err != nil {return nil, echo.NewHTTPError(http.StatusInternalServerError,c.i18n.Ts("globals.messages.errorFetching", "name", "{globals.terms.users}", "error", pqErrMsg(err)))}diff --git a/models/common.go b/models/common.goindex c8a7e43c..166b9b5a 100644--- a/models/common.go+++ b/models/common.go@@ -261,6 +261,22 @@ func (p PageProps) FormFields(exclude ...string) template.HTML {return template.HTML(out.String())}+// FilterURL returns the base path with the given filter param keys and other existing+// params except for "page" which is removed. Used in "clear filter X" links on admin+// pages that render results with arbitrary query filters.+func (p PageProps) FilterURL(base string, exclude ...string) string {+ query := p.Encode(append([]string{"page"}, exclude...)...)+ if query == "" {+ return base+ }++ if strings.Contains(base, "?") {+ return base + "&" + query+ }++ return base + "?" + query+}+// PageResults is a generic HTTP response container for paginated results of list of items.type PageResults struct {Results any `json:"results"`diff --git a/queries/campaigns.sql b/queries/campaigns.sqlindex 5d6c840a..c75531c4 100644--- a/queries/campaigns.sql+++ b/queries/campaigns.sql@@ -74,13 +74,14 @@ WHERE ($1 = 0 OR id = $1)AND (CARDINALITY($2::campaign_status[]) = 0 OR status = ANY($2))AND (CARDINALITY($3::VARCHAR(100)[]) = 0 OR $3 <@ tags)AND ($4 = '' OR TO_TSVECTOR(CONCAT(name, ' ', subject)) @@ PLAINTO_TSQUERY($4) OR CONCAT(c.name, ' ', c.subject) ILIKE ('%' || $4 || '%'))+ AND ($5 = '' OR type = $5::campaign_type)-- Get all campaigns or filter by list IDs.AND (- $5 OR EXISTS (- SELECT 1 FROM campaign_lists WHERE campaign_id = c.id AND list_id = ANY($6::INT[])+ $6 OR EXISTS (+ SELECT 1 FROM campaign_lists WHERE campaign_id = c.id AND list_id = ANY($7::INT[])))-ORDER BY %order% OFFSET $7 LIMIT (CASE WHEN $8 < 1 THEN NULL ELSE $8 END);+ORDER BY %order% OFFSET $8 LIMIT (CASE WHEN $9 < 1 THEN NULL ELSE $9 END);-- name: get-campaignSELECT campaigns.*,diff --git a/queries/users.sql b/queries/users.sqlindex 105cc131..0145339b 100644--- a/queries/users.sql+++ b/queries/users.sql@@ -89,6 +89,10 @@ FROM usersLEFT JOIN ur ON users.user_role_id = ur.idLEFT JOIN lp ON users.list_role_id = lp.list_role_idLEFT JOIN lr ON lp.list_role_id = lr.id+ WHERE ($1 = '' OR users.type = $1::user_type)+ AND ($2 = '' OR users.status = $2::user_status)+ AND ($3 = 0 OR users.user_role_id = $3)+ AND ($4 = 0 OR users.list_role_id = $4)ORDER BY users.created_at;-- name: get-userdiff --git a/static/admin/assets/css/style.css b/static/admin/assets/css/style.cssindex 6b2b5252..d74702e4 100644--- a/static/admin/assets/css/style.css+++ b/static/admin/assets/css/style.css@@ -65,18 +65,6 @@ table {border-bottom: 1px solid var(--border);}- td {- .tag {- border-radius: var(--radius-small);- color: var(--muted-foreground);- padding: calc(var(--space-1) / 4) var(--space-2);-- &:hover {- color: var(--foreground);- }- }- }-.view {color: var(--faint-foreground);font-size: var(--text-8);@@ -239,6 +227,37 @@ a:has(> .badge:only-child) {}}+.tag {+ border-radius: var(--radius-small);+ color: var(--muted-foreground);+ padding: calc(var(--space-1) / 4) var(--space-2);++ &:hover {+ color: var(--foreground);+ }+}++.filter-tag {+ display: inline-flex;+ align-items: center;+ gap: var(--space-1);+ vertical-align: middle;++ a {+ display: inline-flex;+ align-items: center;+ }++ .icon {+ font-size: var(--text-8);+ margin: 0;+ }++ &:hover .icon {+ opacity: 1;+ }+}+/* Tables */td .badge {margin-block: 1px;diff --git a/static/admin/assets/static/icons.svg b/static/admin/assets/static/icons.svgindex 4c45e398..ce431100 100644--- a/static/admin/assets/static/icons.svg+++ b/static/admin/assets/static/icons.svg@@ -198,4 +198,8 @@<symbol id="icon-x-circle" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10" /><line x1="15" y1="9" x2="9" y2="15" /><line x1="9" y1="9" x2="15" y2="15" /></symbol>++ <symbol id="icon-x" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">+ <line x1="18" y1="6" x2="6" y2="18" /><line x1="6" y1="6" x2="18" y2="18" />+ </symbol></svg>diff --git a/static/admin/icons.txt b/static/admin/icons.txtindex 035e9889..c1f3ba25 100644--- a/static/admin/icons.txt+++ b/static/admin/icons.txt@@ -49,3 +49,4 @@ user-checkuser-xusersx-circle+x\ No newline at end of filediff --git a/static/admin/views/campaigns.html b/static/admin/views/campaigns.htmlindex 3ceaa272..2caa03f4 100644--- a/static/admin/views/campaigns.html+++ b/static/admin/views/campaigns.html@@ -2,6 +2,8 @@{{ template "admin-header" . }}{{- $d := .Data -}}{{- $base := URI "/admin/campaigns" -}}+{{- $status := $d.Page.Param "status" -}}+{{- $type := $d.Page.Param "type" -}}{{- $tags := $d.Page.Param "tag" -}}<section class="campaigns" x-data="campaignsView">@@ -9,8 +11,10 @@<div class="col-6"><h1 class="page-title">{{ .L.T "globals.terms.campaigns" }}- {{- if $tags }} <span class="text-light">#{{ $tags }}</span>{{ end }}<span>({{ $d.Page.Total }})</span>+ {{- if $status }} {{ template "filter-badge" dict "Label" (.L.T (printf "campaigns.status.%s" $status)) "Class" (printf "enum status-%s" $status) "URL" ($d.Page.FilterURL $base "status") }}{{ end }}+ {{- if $type }} {{ template "filter-badge" dict "Label" (.L.T "lists.optin") "Class" "enum optin" "URL" ($d.Page.FilterURL $base "type") }}{{ end }}+ {{- if $tags }} {{ template "filter-badge" dict "Label" (printf "#%s" $tags) "Class" "outline tag" "URL" ($d.Page.FilterURL $base "tag") }}{{ end }}</h1></div><div class="col-6 col-end align-right hstack justify-end">@@ -74,7 +78,7 @@<tr data-campaign-id="{{ .ID }}" {{ if eq .Status "running" }}class="running"{{ end }}><td><input name="id" type="checkbox" value="{{ .ID }}"></td><td class="status">- <a href="{{ $base }}/{{ .ID }}">+ <a href="{{ $base }}?status={{ .Status }}">{{ Badge ($.L.T (printf "campaigns.status.%s" .Status)) (printf "enum status-%s" .Status) }}{{- if eq .Status "running" }}<span class="spinner" data-spinner="small" aria-busy="true"></span>{{ end }}</a>@@ -86,7 +90,7 @@<a href="{{ $base }}/{{ .ID }}">{{ .Name }}</a><p class="text-light">{{ .Subject }}</p><div class="hstack gap-1">- {{- if eq .Type "optin" }}{{ Badge ($.L.T "lists.optin") "enum optin" }}{{ end }}+ {{- if eq .Type "optin" }}<a href="{{ $base }}?type=optin">{{ Badge ($.L.T "lists.optin") "enum optin" }}</a>{{ end }}{{ range .Tags }}<a href="?{{ $d.Page.Encode "tag" }}&tag={{ . }}">{{ Badge (printf "#%s" .) "outline tag" }}</a>{{ end }}</div></td>diff --git a/static/admin/views/lists.html b/static/admin/views/lists.htmlindex 43c4e6b4..91c121bd 100644--- a/static/admin/views/lists.html+++ b/static/admin/views/lists.html@@ -1,7 +1,10 @@{{ define "admin-lists" -}}{{ template "admin-header" . }}{{- $d := .Data -}}+{{- $base := URI "/admin/lists" -}}{{- $status := $d.Page.Param "status" -}}+{{- $type := $d.Page.Param "type" -}}+{{- $optin := $d.Page.Param "optin" -}}{{- $orderBy := $d.Page.Param "order_by" -}}{{- $order := $d.Page.Param "order" -}}{{- $tags := $d.Page.Param "tag" -}}@@ -11,9 +14,14 @@<div class="col-6"><h1 class="page-title">{{ .L.T "globals.terms.lists" }}- {{- if eq $status "archived" }} / {{ $status }}{{ end }}- {{- if $tags }} <span class="text-light">#{{ $tags }}</span>{{ end }}<span>({{ $d.Page.Total }})</span>+ {{- if eq $status "archived" }} {{ template "filter-badge" dict "Label" (.L.T "lists.archived") "Class" "outline" "URL" ($d.Page.FilterURL $base "status") }}{{ end }}+ {{- if $type }} {{ template "filter-badge" dict "Label" (.L.T (printf "lists.types.%s" $type)) "Class" (printf "enum %s" $type) "URL" ($d.Page.FilterURL $base "type") }}{{ end }}+ {{- if $optin }}+ {{- $optinIcon := "user-x" }}{{ if eq $optin "double" }}{{ $optinIcon = "user-check" }}{{ end }}+ {{ template "filter-badge" dict "Label" (list (Icon $optinIcon) (.L.T (printf "lists.optins.%s" $optin))) "Class" "enum" "Variant" "secondary" "URL" ($d.Page.FilterURL $base "optin") }}+ {{- end }}+ {{- if $tags }} {{ template "filter-badge" dict "Label" (printf "#%s" $tags) "Class" "outline tag" "URL" ($d.Page.FilterURL $base "tag") }}{{ end }}</h1></div><div class="col-6 col-end align-right hstack justify-end">@@ -76,9 +84,9 @@</td><td><div class="hstack">- {{ Badge ($.L.T (printf "lists.types.%s" .Type)) (printf "enum %s" .Type) }}+ <a href="{{ $base }}?type={{ .Type }}">{{ Badge ($.L.T (printf "lists.types.%s" .Type)) (printf "enum %s" .Type) }}</a>{{- $icon := "user-x" }}{{ if eq .Optin "double" }}{{ $icon = "user-check" }}{{ end }}- {{ Badge (list (Icon $icon) ($.L.T (printf "lists.optins.%s" .Optin))) "enum" "secondary" }}+ <a href="{{ $base }}?optin={{ .Optin }}">{{ Badge (list (Icon $icon) ($.L.T (printf "lists.optins.%s" .Optin))) "enum" "secondary" }}</a></div></td><td class="subscribers">diff --git a/static/admin/views/subscribers.html b/static/admin/views/subscribers.htmlindex ef134b49..fddfc771 100644--- a/static/admin/views/subscribers.html+++ b/static/admin/views/subscribers.html@@ -21,10 +21,8 @@<h1 class="page-title">{{ .L.T "globals.terms.subscribers" }}<span>({{ $d.Page.Total }})</span>- {{- if $d.CurrentList }}- » <a href="{{ URI "/admin/lists" }}/{{ $d.CurrentList.ID }}">{{ $d.CurrentList.Name }}</a>- {{- if $subStatus }}<span class="text-light">({{ $subStatus }})</span>{{ end }}- {{- end }}+ {{- if $d.CurrentList }} {{ template "filter-badge" dict "Label" $d.CurrentList.Name "Class" "outline" "URL" (URI "/admin/subscribers") }}{{ end }}+ {{- if $subStatus }} {{ template "filter-badge" dict "Label" (.L.T (printf "subscribers.status.%s" $subStatus)) "Class" (printf "status-%s" $subStatus) "URL" ($d.Page.FilterURL $base "subscription_status") }}{{ end }}</h1></div><div class="col-6 col-end hstack justify-end">@@ -102,7 +100,13 @@<td><input name="id" type="checkbox" value="{{ .ID }}"></td><td class="email"><a href="{{ URI "/admin/subscribers" }}/{{ .ID }}">{{ .Email }}</a>- {{- if ne .Status "enabled" }}{{ Badge ($.L.T (printf "subscribers.status.%s" .Status)) (printf "status-%s" .Status) }}{{ end }}+ {{- if ne .Status "enabled" }}+ {{- if $d.Can "subscribers:sql_query" }}+ <a href="{{ $base }}?query={{ printf "subscribers.status = '%s'" .Status | urlquery }}">{{ Badge ($.L.T (printf "subscribers.status.%s" .Status)) (printf "status-%s" .Status) }}</a>+ {{- else }}+ {{ Badge ($.L.T (printf "subscribers.status.%s" .Status)) (printf "status-%s" .Status) }}+ {{- end }}+ {{- end }}<div class="badge-list hstack gap-1">{{- range .ParsedLists }}{{- $sup := "" }}diff --git a/static/admin/views/templates.html b/static/admin/views/templates.htmlindex f3b0d903..f7877545 100644--- a/static/admin/views/templates.html+++ b/static/admin/views/templates.html@@ -10,6 +10,13 @@<h1 class="page-title">{{ .L.T "globals.terms.templates" }}<span>({{ len $d.Templates }})</span>+ {{- if $d.Type }}+ {{- $label := $d.Type }}{{ $class := "enum" }}+ {{- if eq $d.Type "tx" }}{{ $label = .L.Tc "globals.terms.tx" 1 }}{{ $class = "enum tx" }}+ {{- else if eq $d.Type "campaign_visual" }}{{ $label = .L.T "campaigns.visual" }}{{ $class = "enum campaign" }}+ {{- else if eq $d.Type "campaign" }}{{ $label = .L.Tc "globals.terms.campaign" 1 }}{{ $class = "enum campaign" }}{{ end }}+ {{ template "filter-badge" dict "Label" $label "Class" $class "URL" $base }}+ {{- end }}</h1></div><div class="col-6 col-end align-right hstack justify-end">@@ -44,13 +51,13 @@<td><div class="hstack">{{- if eq .Type "tx" }}- {{ Badge ($.L.Tc "globals.terms.tx" 1) "enum tx" }}+ <a href="{{ $base }}?type={{ .Type }}">{{ Badge ($.L.Tc "globals.terms.tx" 1) "enum tx" }}</a>{{- else }}- {{ Badge ($.L.Tc "globals.terms.campaign" 1) "enum campaign" }}+ <a href="{{ $base }}?type={{ .Type }}">{{ Badge ($.L.Tc "globals.terms.campaign" 1) "enum campaign" }}</a>{{- if eq .Type "campaign_visual" }}- {{ Badge ($.L.T "campaigns.visual") "enum" "secondary" }}+ <a href="{{ $base }}?type={{ .Type }}">{{ Badge ($.L.T "campaigns.visual") "enum" "secondary" }}</a>{{- else }}- {{ Badge "HTML" "enum" "secondary" }}+ <a href="{{ $base }}?type={{ .Type }}">{{ Badge "HTML" "enum" "secondary" }}</a>{{- end }}{{- end }}</div>diff --git a/static/admin/views/users.html b/static/admin/views/users.htmlindex 264d8f0f..12a5d7f8 100644--- a/static/admin/views/users.html+++ b/static/admin/views/users.html@@ -1,6 +1,7 @@{{ define "admin-users" -}}{{ template "admin-header" . }}{{- $d := .Data -}}+{{- $base := URI "/admin/users" -}}<section class="users" x-data="usersView()"><header class="row page-header">@@ -9,6 +10,19 @@<h1 class="page-title">{{ .L.T "globals.terms.users" }}<span>({{ len $d.Users }})</span>+ {{- if $d.Type }}+ {{- if eq $d.Type "api" }}+ {{ template "filter-badge" dict "Label" (list (Icon "code") (.L.T "users.type.api")) "Class" "outline tag" "URL" ($d.Page.FilterURL $base "type") }}+ {{- else }}+ {{ template "filter-badge" dict "Label" $d.Type "Class" "outline" "URL" ($d.Page.FilterURL $base "type") }}+ {{- end }}+ {{- end }}+ {{- if $d.Status }} {{ template "filter-badge" dict "Label" (.L.T (printf "users.status.%s" $d.Status)) "Class" "enum" "Variant" "danger" "URL" ($d.Page.FilterURL $base "status") }}{{ end }}+ {{- if $d.UserRoleID }}+ {{- $roleIcon := "user" }}{{ if eq $d.UserRoleID 1 }}{{ $roleIcon = "star" }}{{ end }}+ {{ template "filter-badge" dict "Label" (list (Icon $roleIcon) $d.UserRoleName) "Variant" (ternary "" "secondary" (eq $d.UserRoleID 1)) "URL" ($d.Page.FilterURL $base "user_role_id") }}+ {{- end }}+ {{- if $d.ListRoleID }} {{ template "filter-badge" dict "Label" (list (Icon "list") $d.ListRoleName) "Class" "outline" "URL" ($d.Page.FilterURL $base "list_role_id") }}{{ end }}</h1></div></div>@@ -64,19 +78,19 @@{{- else }}<span class="{{ if eq .Status "disabled" }}text-danger{{ end }}">{{ .Username }}</span>{{- end }}- {{- if eq .Type "api" }}{{ Badge (list (Icon "code") ($.L.T "users.type.api")) "outline tag" }}{{ end }}- {{- if eq .Status "disabled" }}{{ Badge ($.L.T "users.status.disabled") "enum" "danger" }}{{ end }}+ {{- if eq .Type "api" }}<a href="{{ $base }}?type=api">{{ Badge (list (Icon "code") ($.L.T "users.type.api")) "outline tag" }}</a>{{ end }}+ {{- if eq .Status "disabled" }}<a href="{{ $base }}?status=disabled">{{ Badge ($.L.T "users.status.disabled") "enum" "danger" }}</a>{{ end }}{{- if .Name }}<div class="text-light text-8">{{ .Name }}</div>{{ end }}</td><td><div class="hstack gap-1">{{- if eq .UserRole.ID 1 }}- <a href="{{ URI "/admin/users/roles" }}/{{ .UserRole.ID }}">{{ Badge (list (Icon "star") .UserRole.Name) }}</a>+ <a href="{{ $base }}?user_role_id={{ .UserRole.ID }}">{{ Badge (list (Icon "star") .UserRole.Name) }}</a>{{- else }}- <a href="{{ URI "/admin/users/roles" }}/{{ .UserRole.ID }}">{{ Badge (list (Icon "user") .UserRole.Name) "" "secondary" }}</a>+ <a href="{{ $base }}?user_role_id={{ .UserRole.ID }}">{{ Badge (list (Icon "user") .UserRole.Name) "" "secondary" }}</a>{{- end }}{{- with .ListRole }}- <a href="{{ URI "/admin/users/roles/lists" }}/{{ .ID }}">{{ Badge (list (Icon "list") .Name) "outline" }}</a>+ <a href="{{ $base }}?list_role_id={{ .ID }}">{{ Badge (list (Icon "list") .Name) "outline" }}</a>{{- end }}</div></td>