Skip to content

High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.

11.8 KB
Raw Blame
{{ define "admin-lists" -}}
{{ template "admin-header" . }}
{{- $d := .Data -}}
{{- $base := URI "/admin/lists" -}}
{{- $statusIcons := dict "confirmed" "check" "unsubscribed" "x" -}}
{{- $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" -}}

<section class="lists" x-data="listsView">
	<header class="hstack justify-between page-header">
		<div class="hstack page-heading">
			<h1 class="page-title">
				{{ .L.T "globals.terms.lists" }}
				<span>({{ $d.Page.Total }})</span>
			</h1>
			{{- if eq $status "archived" }} {{ template "filter-badge" dict "Label" (.L.T "globals.terms.archived") "URL" ($d.Page.FilterURL $base "status") }}{{ end }}
			{{- if $type }}
				{{- $typeIcon := "eye-off" }}{{ if eq $type "public" }}{{ $typeIcon = "eye" }}{{ end }}
				{{ template "filter-badge" dict "Label" (list (Icon $typeIcon) (.L.T (printf "globals.terms.%s" $type))) "Class" "enum" "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" "URL" ($d.Page.FilterURL $base "optin") }}
			{{- end }}
			{{- if $tags }} {{ template "filter-badge" dict "Label" (printf "#%s" $tags) "Class" "tag" "URL" ($d.Page.FilterURL $base "tag") }}{{ end }}
			{{- if gt $d.Page.Page 1 }} {{ template "filter-badge" dict "Label" (.L.Ts "globals.terms.page" "n" (printf "%d" $d.Page.Page)) "URL" ($d.Page.FilterURL $base) }}{{ end }}
		</div>
		<div class="hstack justify-end buttons">
			<form method="get" action="{{ URI "/admin/lists" }}" class="search-form">
				{{- $d.Page.FormFields "query" -}}
				<fieldset class="group">
					<input name="query" aria-label="{{ .L.T "globals.buttons.search" }}" data-testid="query" placeholder="{{ .L.T "globals.buttons.search" }}" value="{{ $d.Page.Query }}" autofocus />
					<button type="submit" class="outline external" data-testid="btn-query" aria-label="{{ .L.T "globals.buttons.search" }}">{{ Icon "search" }}</button>
				</fieldset>
			</form>
			{{- if $d.Can "lists:manage_all" }}
				<a href="{{ URI "/admin/lists/new" }}" class="button" data-variant="primary" data-testid="btn-new">
					{{ Icon "plus" }} {{ .L.T "globals.buttons.new" }}
				</a>
			{{- end }}
		</div>
	</header>

	<div class="card page-content has-table">
		<div class="table-wrapper" x-data="table({ query: {{ ToJSON $d.Page.Query }}, filters: {{ ToJSON $d.Page.QueryParams }}, total: {{ $d.Page.Total }} })" :aria-busy="isLoading('lists')" @change="onChange($event)">
			<template x-if="numSelected > 0">
				<ot-dropdown class="bulk-actions" data-variant="primary">
					<button popovertarget="bulk-actions" type="button" class="small" data-testid="btn-bulk-actions">
						<span x-text="numSelectedLabel"></span> {{ Icon "more-vertical" }}
					</button>
					<menu popover id="bulk-actions">
						{{- if gt $d.Page.Total $d.Page.PerPage }}
							<button type="button" role="menuitem" class="ghost" data-testid="select-all-lists" x-cloak x-show="!allSelected" @click.prevent="onSelectAllQuery()">
								{{ Icon "list" }} <span x-text="selectAllLabel"></span>
							</button>
						{{- end }}
						<button type="button" role="menuitem" class="ghost" data-variant="danger" data-testid="btn-delete-lists" :disabled="isLoading('lists')" @click.prevent="onDeleteSelected(numSelected, selectedQueryParams().toString())">
							{{ Icon "trash-2" }} {{ .L.T "globals.buttons.delete" }} <span x-text="numSelected"></span>
						</button>
					</menu>
				</ot-dropdown>
			</template>

			<table class="has-select">
				<thead>
					<tr>
						<th width="5%"><input type="checkbox" aria-label="{{ .L.T "globals.buttons.toggleSelect" }}"></th>
						<th width="27%">{{ $d.Page.SortLink (URI "/admin/lists") "name" (.L.T "globals.fields.name") }}</th>
						<th width="22%">{{ $d.Page.SortLink (URI "/admin/lists") "type" (.L.T "globals.fields.type") }}</th>
						<th width="20%" class="subscribers">{{ $d.Page.SortLink (URI "/admin/lists") "subscriber_count" (.L.T "globals.terms.subscribers") }}</th>
						<th width="12%">{{ $d.Page.SortLink (URI "/admin/lists") "created_at" (.L.T "globals.fields.createdAt") }}</th>
						<th width="5%" class="align-right"></th>
					</tr>
				</thead>
				<tbody>
					{{- range $d.Lists }}
						<tr class="list-main-row" data-testid="list-row" data-id="{{ .ID }}">
							<td><input name="id" type="checkbox" value="{{ .ID }}"></td>
							<td class="list-name">
								<div class="avatar{{ if eq .Status "archived" }} disabled{{ end }}">
									{{ template "avatar-icon" dict "Kind" "list" "Name" .Name "Href" (printf "%s/%d" (URI "/admin/lists") .ID) "Title" (printf "%s %s" ($.L.T "globals.buttons.view") .Name) }}
									<div class="avatar-label">
										<a href="{{ URI "/admin/lists" }}/{{ .ID }}" class="unstyled">{{ .Name }}</a>
										{{- if .Description }}<div class="description text-light text-8" title="{{ .Description }}">{{ .Description }}</div>{{ end }}
										<div class="hstack gap-2 text-8">
											{{ range .Tags }}<a href="?{{ $d.Page.Encode "tag" }}&tag={{ . }}" title="{{ $.L.T "globals.buttons.filter" }} {{ . }}">#{{ . }}</a>{{ end }}
										</div>
									</div>
								</div>
							</td>
							<td>
								<div class="hstack">
									{{- $typeIcon := "eye-off" }}{{ if eq .Type "public" }}{{ $typeIcon = "eye" }}{{ end }}
									<a href="{{ $base }}?type={{ .Type }}" title="{{ $.L.T "globals.buttons.filter" }} {{ $.L.T (printf "globals.terms.%s" .Type) }}">{{ Badge (list (Icon $typeIcon) ($.L.T (printf "globals.terms.%s" .Type))) (printf "enum type-%s" .Type) }}</a>
									{{- $icon := "user-x" }}{{ if eq .Optin "double" }}{{ $icon = "user-check" }}{{ end }}
									<a href="{{ $base }}?optin={{ .Optin }}" title="{{ $.L.T "globals.buttons.filter" }} {{ $.L.T (printf "lists.optins.%s" .Optin) }}">{{ Badge (list (Icon $icon) ($.L.T (printf "lists.optins.%s" .Optin))) "enum" }}</a>
								</div>
							</td>
							<td class="subscribers" data-label="{{ $.L.T "globals.terms.subscribers" }}">
								{{- if $d.Can "subscribers:get" "subscribers:get_all" }}
									<a class="subscriber-total" href="{{ URI "/admin/subscribers/lists" }}/{{ .ID }}" title="{{ $.L.T "globals.buttons.view" }} {{ $.L.T "globals.terms.subscribers" }}">{{ FormatNumber .SubscriberCount }}</a>
								{{- else }}
									<span class="subscriber-total">{{ FormatNumber .SubscriberCount }}</span>
								{{- end }}
								{{- $listID := .ID -}}
								{{- $total := max .SubscriberCount 1 -}}
								{{- $counts := .SubscriberCounts -}}
								{{- $stats := list -}}
								{{- $statuses := list "unsubscribed" -}}
								{{- if eq .Optin "double" -}}
									{{- $statuses = list "confirmed" "unconfirmed" "unsubscribed" -}}
								{{- end -}}
								{{- range $statuses -}}
									{{- $count := index $counts . -}}
									{{- $label := $.L.T (printf "globals.terms.%s" .) -}}
									{{- $percent := mulf (divf $count $total) 100 -}}
									{{- $title := printf "%s %s (%.0f%%)" $label (FormatNumber $count) $percent -}}
									{{- $stats = append $stats (dict "Status" . "Count" $count "Label" $label "Percent" $percent "Title" $title) -}}
								{{- end }}
								<div class="subscriber-breakdown">
									<div class="subscriber-meters" role="group" aria-label="{{ $.L.T "globals.terms.subscribers" }}: {{ .Name }} — {{ $.L.T "globals.fields.status" }}">
										{{- range $stats }}
											<meter class="status-{{ .Status }}" min="0" max="{{ $total }}" value="{{ .Count }}" style="width: {{ .Percent }}%" aria-label="{{ .Label }}" aria-valuetext="{{ .Title }}" title="{{ .Title }}">{{ .Title }}</meter>
										{{- end }}
									</div>
									<div class="subscriber-legend text-8">
										{{- range $stats }}
											<a class="unstyled text-grey" href="{{ URI "/admin/subscribers/lists" }}/{{ $listID }}?subscription_status={{ .Status }}" title="{{ .Title }}" aria-label="{{ .Title }}"><span class="status-icon status-{{ .Status }}" aria-hidden="true">{{ if eq .Status "unconfirmed" }}?{{ else }}{{ Icon (index $statusIcons .Status) }}{{ end }}</span> {{ printf "%.0f%%" .Percent }}</a>
										{{- end }}
									</div>
								</div>
							</td>
							<td class="date-stack" data-label="{{ $.L.T "globals.fields.createdAt" }}">
								{{ NiceDate .CreatedAt }}
								<!-- <p class="text-lighter text-8">{{ NiceDate .UpdatedAt }}</p> -->
							</td>
							<td class="actions align-right">
									<ot-dropdown>
										<button popovertarget="list-actions-{{ .ID }}" type="button" class="ghost more icon" aria-label="{{ $.L.T "globals.buttons.more" }}">
											{{ Icon "more-vertical" }}
										</button>
										<menu popover id="list-actions-{{ .ID }}">
											<a href="{{ URI "/admin/lists" }}/{{ .ID }}" role="menuitem" class="button ghost" data-testid="btn-view">{{ Icon "eye" }} {{ $.L.T "globals.buttons.view" }}</a>
											<a href="{{ URI "/admin/lists/analytics" }}?id={{ .ID }}&from={{ (now.AddDate 0 -3 0).Format "2006-01-02" }}" role="menuitem" class="button ghost" data-testid="btn-analytics">{{ Icon "bar-chart-2" }} {{ $.L.T "globals.terms.analytics" }}</a>
											{{- if or ($d.Can "campaigns:manage" "campaigns:manage_all") ($d.CanManageList .ID) ($d.Can "subscribers:import") }}
												<hr />
											{{- end }}
											{{- if $d.CanManageList .ID }}
												<a href="{{ URI "/admin/lists" }}/{{ .ID }}/edit" role="menuitem" class="button ghost" data-testid="btn-edit">{{ Icon "edit-2" }} {{ $.L.T "globals.buttons.edit" }}</a>
											{{- end }}
											{{- if $d.Can "subscribers:import" }}
												<a href="{{ URI "/admin/import" }}?list_id={{ .ID }}" role="menuitem" class="button ghost" data-testid="btn-import">{{ Icon "upload" }} {{ $.L.T "globals.terms.import" }}</a>
											{{- end }}
											{{- if $d.CanManageList .ID }}
												<button type="button" role="menuitem" class="ghost" data-variant="danger" data-testid="btn-delete" :disabled="isLoading('lists')" @click.prevent="onDeleteList({{ .ID }}, {{ ToJSON .Name }})">{{ Icon "trash-2" }} {{ $.L.T "globals.buttons.delete" }}</button>
											{{- end }}
											{{- if and ($d.Can "campaigns:manage" "campaigns:manage_all") (or ($d.CanManageList .ID) ($d.Can "subscribers:import")) }}<hr />{{ end }}
											{{- if $d.Can "campaigns:manage" "campaigns:manage_all" }}
												<a href="{{ URI "/admin/campaigns/new" }}?list_id={{ .ID }}" role="menuitem" class="button ghost" data-testid="btn-campaign">{{ Icon "send" }} {{ $.L.T "campaigns.newCampaign" }}</a>
											{{- end }}
											{{- if and (eq .Optin "double") ($d.Can "campaigns:manage" "campaigns:manage_all") }}
												<button type="button" role="menuitem" class="ghost send-optin" data-testid="btn-send-optin-campaign" :disabled="isLoading('lists')" @click.prevent="onCreateOptinCampaign({{ .ID }}, {{ ToJSON .Name }})">
													{{ Icon "send" }} {{ $.L.T "lists.sendOptinCampaign" }}
												</button>
											{{- end }}
										</menu>
									</ot-dropdown>
							</td>
						</tr>
					{{- else }}
						{{ template "empty-state" 6 }}
					{{- end }}
				</tbody>
			</table>

			{{- template "pagination" $d.Page.Pagination }}
		</div>
	</div>

</section>

{{- if $d.CacheSlowQueries }}
	<p class="text-light">
		*{{ .L.T "globals.messages.slowQueriesCached" }}
		<a href="https://listmonk.app/docs/maintenance/performance/" target="_blank" rel="noopener noreferrer" class="text-light">
			{{ Icon "link-2" }} {{ .L.T "globals.buttons.learnMore" }}
		</a>
	</p>
{{- end }}

<script type="module" src="{{ URI "/admin/static/js/views/lists.js" }}?v={{ .AssetVersion }}" defer></script>

{{ template "admin-footer" . -}}
{{ end }}