Skip to content

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

SSR: Port logs and maintenance pages.

Kailash Nadha15e36b5000c
diff --git a/cmd/admin.go b/cmd/admin.go
index e6ed0296..e0012bed 100644
--- a/cmd/admin.go
+++ b/cmd/admin.go
@@ -69,6 +69,8 @@ var adminJSI18nKeys = []string{
"globals.terms.month",
"globals.terms.year",
"globals.terms.year",
+ "globals.terms.subscribers",
+ "globals.terms.subscriptions",
"lists.confirmDelete",
"lists.confirmSub",
diff --git a/cmd/handlers.go b/cmd/handlers.go
index f806d016..c4b1fe66 100644
--- a/cmd/handlers.go
+++ b/cmd/handlers.go
@@ -101,6 +101,8 @@ func initHTTPHandlers(e *echo.Echo, a *App) {
// Settings.
g.GET(path.Join(uriAdmin, "/settings"), a.ViewSettings)
+ g.GET(path.Join(uriAdmin, "/settings/logs"), a.ViewLogs)
+ g.GET(path.Join(uriAdmin, "/settings/maintenance"), a.ViewMaintenance)
}
// =================================================================
diff --git a/cmd/maintenance.go b/cmd/maintenance.go
index bf10ac60..e3b0a7c3 100644
--- a/cmd/maintenance.go
+++ b/cmd/maintenance.go
@@ -8,9 +8,40 @@ import (
"time"
"github.com/jmoiron/sqlx"
+ "github.com/knadh/listmonk/internal/auth"
"github.com/labstack/echo/v4"
)
+// maintenanceView is the admin page view for the maintenance/garbage-collection page.
+type maintenanceView struct {
+ adminView
+
+ DBSettings struct {
+ Vacuum bool `json:"vacuum"`
+ VacuumInterval string `json:"vacuum_cron_interval"`
+ }
+}
+
+// ViewMaintenance renders the HTML view for the maintenance page.
+func (a *App) ViewMaintenance(c echo.Context) error {
+ if !can(auth.GetUser(c), "settings:maintain") {
+ return auth.ErrPermDenied
+ }
+
+ s, err := a.core.GetSettings()
+ if err != nil {
+ return err
+ }
+
+ data := maintenanceView{
+ adminView: newAdminView(c, a.i18n.T("maintenance.title"), "", "settings.maintenance"),
+ }
+ data.DBSettings.Vacuum = s.MaintenanceDB.Vacuum
+ data.DBSettings.VacuumInterval = s.MaintenanceDB.VacuumInterval
+
+ return c.Render(http.StatusOK, "admin-maintenance", data)
+}
+
// GCSubscribers garbage collects (deletes) orphaned or blocklisted subscribers.
func (a *App) GCSubscribers(c echo.Context) error {
var (
diff --git a/cmd/settings.go b/cmd/settings.go
index 26be8b27..9fd2fc5b 100644
--- a/cmd/settings.go
+++ b/cmd/settings.go
@@ -427,6 +427,27 @@ func (a *App) handleSettingsRestart(c echo.Context) error {
return c.JSON(http.StatusOK, okResp{true})
}
+// logsView is the admin page view for the log viewer.
+type logsView struct {
+ adminView
+
+ Lines []string
+}
+
+// ViewLogs renders the HTML view for the application log viewer.
+func (a *App) ViewLogs(c echo.Context) error {
+ if !can(auth.GetUser(c), "settings:get") {
+ return auth.ErrPermDenied
+ }
+
+ data := logsView{
+ adminView: newAdminView(c, a.i18n.T("logs.title"), "", "settings.logs"),
+ Lines: a.bufLog.Lines(),
+ }
+
+ return c.Render(http.StatusOK, "admin-logs", data)
+}
+
// GetLogs returns the log entries stored in the log buffer.
func (a *App) GetLogs(c echo.Context) error {
return c.JSON(http.StatusOK, okResp{a.bufLog.Lines()})
diff --git a/frontend-vue/src/components/LogView.vue b/frontend-vue/src/components/LogView.vue
deleted file mode 100644
index 4b05073e..00000000
--- a/frontend-vue/src/components/LogView.vue
+++ /dev/null
@@ -1,63 +0,0 @@
-<template>
- <section class="log-view" :aria-busy="loading ? 'true' : null" data-spinner="large overlay">
- <div class="lines" ref="lines">
- <template v-for="(l, i) in lines">
- <template v-if="l">
- <span :set="line = splitLine(l)" :key="i" class="line">
- <span class="timestamp">{{ line.timestamp }}&nbsp;</span>
- <span v-if="line.file !== '*'" class="file">{{ line.file }}:&nbsp;</span>
- <span class="log-message">{{ line.message }}</span>
- </span>
- </template>
- </template>
- </div>
- </section>
-</template>
-
-<script>
-// Regexp for splitting log lines in the following format to
-// [timestamp] [file] [message].
-// 2021/05/01 00:00:00:00 init.go:99: reading config: config.toml
-const reFormatLine = /^([0-9\s:/]+\.[0-9]{6}) (.+?\.go:[0-9]+|\*):\s(.+)$/;
-
-export default {
- name: 'LogView',
-
- props: {
- loading: Boolean,
- lines: {
- type: Array,
- default: () => [],
- },
- },
-
- methods: {
- splitLine: (l) => {
- const parts = l.split(reFormatLine);
- if (parts.length !== 5) {
- return {
- timestamp: '',
- file: '',
- message: l,
- };
- }
-
- return {
- timestamp: parts[1],
- file: parts[2],
- message: parts[3],
- };
- },
-
- formatLine: (l) => l.replace(reFormatLine, '<span class="stamp">$1</span> '),
- },
-
- watch: {
- lines() {
- this.$nextTick(() => {
- this.$refs.lines.scrollTop = this.$refs.lines.scrollHeight;
- });
- },
- },
-};
-</script>
diff --git a/frontend-vue/src/router/index.js b/frontend-vue/src/router/index.js
index 6b9c4822..8dd2840f 100644
--- a/frontend-vue/src/router/index.js
+++ b/frontend-vue/src/router/index.js
@@ -53,18 +53,6 @@ const routes = [
meta: { title: 'globals.terms.settings', group: 'settings' },
component: () => import('../views/Settings.vue'),
},
- {
- path: '/settings/logs',
- name: 'logs',
- meta: { title: 'logs.title', group: 'settings' },
- component: () => import('../views/Logs.vue'),
- },
- {
- path: '/settings/maintenance',
- name: 'maintenance',
- meta: { title: 'maintenance.title', group: 'settings' },
- component: () => import('../views/Maintenance.vue'),
- },
];
const router = new VueRouter({
diff --git a/frontend-vue/src/views/Logs.vue b/frontend-vue/src/views/Logs.vue
deleted file mode 100644
index 25cf3b56..00000000
--- a/frontend-vue/src/views/Logs.vue
+++ /dev/null
@@ -1,57 +0,0 @@
-<template>
- <section class="logs relative">
- <header class="row page-header">
- <div class="col-8">
- <h1>
- {{ $t('logs.title') }}
- </h1>
- </div>
- </header>
-
- <div class="card page-content">
- <log-view :loading="loading.logs" :lines="lines" />
- </div>
- </section>
-</template>
-
-<script>
-import Vue from 'vue';
-import { mapState } from 'vuex';
-import LogView from '../components/LogView.vue';
-
-export default Vue.extend({
- components: {
- LogView,
- },
-
- data() {
- return {
- lines: [],
- pollId: null,
- };
- },
-
- methods: {
- getLogs() {
- this.$api.getLogs().then((data) => {
- this.lines = data;
- });
- },
- },
-
- computed: {
- ...mapState(['logs', 'loading']),
- },
-
- mounted() {
- this.getLogs();
-
- // Update the logs every 10 seconds.
- this.pollId = setInterval(() => this.getLogs(), 10000);
- },
-
- destroyed() {
- clearInterval(this.pollId);
- },
-});
-</script>
diff --git a/frontend-vue/src/views/Maintenance.vue b/frontend-vue/src/views/Maintenance.vue
deleted file mode 100644
index a27e3a83..00000000
--- a/frontend-vue/src/views/Maintenance.vue
+++ /dev/null
@@ -1,281 +0,0 @@
-<template>
- <section class="maintenance">
- <header class="row page-header">
- <div class="col-8">
- <h1>
- {{ $t('maintenance.title') }}
- </h1>
- <p class="text-light text-7">
- {{ $t('maintenance.help') }}
- </p>
- </div>
- </header>
-
- <div class="card page-content" :aria-busy="isLoading ? 'true' : null" data-spinner="large overlay">
- <div class="card">
- <h4 class="text-4">
- {{ $t('globals.terms.subscribers') }}
- </h4><br />
- <div class="row">
- <div class="col-4">
- <b-field label="Data" :message="$t('maintenance.orphanHelp')">
- <select aria-label="field" v-model="subscriberType">
- <option value="orphan">
- {{ $t('dashboard.orphanSubs') }}
- </option>
- <option value="blocklisted">
- {{ $t('subscribers.status.blocklisted') }}
- </option>
- </select>
- </b-field>
- </div>
- <div class="col-5" />
- <div class="col-12">
- <br />
- <b-field>
- <button type="button" data-variant="danger" :loading="loading.maintenance" @click="deleteSubscribers">
- {{ $t('globals.buttons.delete') }}
- </button>
- </b-field>
- </div>
- </div>
- </div><!-- subscribers -->
-
- <div class="card mt-6">
- <h4 class="text-4">
- {{ $tc('globals.terms.subscriptions', 2) }}
- </h4><br />
- <div class="row">
- <div class="col-4">
- <b-field label="Data">
- <select aria-label="field" v-model="subscriptionType">
- <option value="optin">
- {{ $t('maintenance.maintenance.unconfirmedOptins') }}
- </option>
- </select>
- </b-field>
- </div>
- <div class="col-4">
- <b-field :label="$t('maintenance.olderThan')">
- <b-datepicker v-model="subscriptionDate" required />
- </b-field>
- </div>
- <div class="col-1" />
- <div class="col-12">
- <br />
- <b-field>
- <button type="button" data-variant="danger" :loading="loading.maintenance" @click="deleteSubscriptions">
- {{ $t('globals.buttons.delete') }}
- </button>
- </b-field>
- </div>
- </div>
- </div><!-- subscriptions -->
-
- <div class="card mt-6">
- <h4 class="text-4">
- {{ $t('globals.terms.analytics') }}
- </h4><br />
- <div class="row">
- <div class="col-4">
- <b-field label="Data">
- <select aria-label="field" v-model="analyticsType">
- <option selected value="all">
- {{ $t('globals.terms.all') }}
- </option>
- <option value="views">
- {{ $t('dashboard.campaignViews') }}
- </option>
- <option value="clicks">
- {{ $t('dashboard.linkClicks') }}
- </option>
- </select>
- </b-field>
- </div>
- <div class="col-4">
- <b-field :label="$t('maintenance.olderThan')">
- <b-datepicker v-model="analyticsDate" required />
- </b-field>
- </div>
- <div class="col-1" />
- <div class="col-12">
- <br />
- <b-field>
- <button type="button" data-variant="danger" :loading="loading.maintenance" @click="deleteAnalytics">
- {{ $t('globals.buttons.delete') }}
- </button>
- </b-field>
- </div>
- </div>
-
- <hr />
- <h5 class="text-5">
- {{ $t('subscribers.export') }}
- </h5>
- <br />
- <div class="row">
- <div class="col-4">
- <b-field label="Data">
- <select aria-label="field" v-model="exportType">
- <option value="views">
- {{ $t('dashboard.campaignViews') }}
- </option>
- <option value="clicks">
- {{ $t('dashboard.linkClicks') }}
- </option>
- </select>
- </b-field>
- </div>
- <div class="col-4">
- <b-field :label="$t('analytics.fromDate')">
- <b-datepicker v-model="exportDate" required />
- </b-field>
- </div>
- <div class="col-1" />
- <div class="col-12">
- <br />
- <b-field>
- <button type="button" data-variant="primary" tag="a" :href="exportURL">
- {{ $t('subscribers.export') }}
- </button>
- </b-field>
- </div>
- </div>
- </div><!-- analytics -->
-
- <form @submit.prevent="onUpdateDBSettings" class="card mt-6">
- <h4 class="text-4">
- {{ $t('maintenance.database.title') }}
- </h4><br />
- <h5 class="text-5">Vacuum</h5>
- <p class="text-light text-7 ">
- {{ $t('maintenance.database.vacuumHelp') }}
- </p>
- <br />
- <div class="row">
- <div class="col-2">
- <b-field :label="$t('globals.buttons.enabled')">
- <b-switch v-model="dbSettings.vacuum" />
- </b-field>
- </div>
- <div class="col-4" :class="{ disabled: !dbSettings.vacuum }">
- <b-field :label="$t('settings.maintenance.cron')">
- <input aria-label="field" v-model="dbSettings.vacuum_cron_interval" placeholder="0 2 * * *"
- :disabled="!dbSettings.vacuum" pattern="((\*|[0-9,\-\/]+)\s+){4}(\*|[0-9,\-\/]+)">
- </b-field>
- </div>
- <div class="col-3" />
- <div class="col-3">
- <br />
- <button data-variant="primary" type="submit" :loading="loading.settings">
- {{ $t('globals.buttons.save') }}
- </button>
- </div>
- </div>
- </form><!-- database -->
- </div>
- </section>
-</template>
-
-<script>
-import dayjs from 'dayjs';
-import Vue from 'vue';
-import { mapState } from 'vuex';
-
-export default Vue.extend({
- components: {
- },
-
- data() {
- return {
- isLoading: false,
- subscriberType: 'orphan',
- analyticsType: 'all',
- subscriptionType: 'optin',
- analyticsDate: dayjs().subtract(7, 'day').toDate(),
- subscriptionDate: dayjs().subtract(7, 'day').toDate(),
- exportType: 'views',
- exportDate: dayjs().subtract(30, 'day').toDate(),
- dbSettings: {
- vacuum: false,
- vacuum_cron_interval: '0 2 * * *',
- },
- };
- },
-
- mounted() {
- this.loadDBSettings();
- },
-
- methods: {
- formatDateTime(s) {
- return dayjs(s).format('YYYY-MM-DD');
- },
-
- deleteSubscribers() {
- this.$utils.confirm(
- null,
- () => {
- this.$api.deleteGCSubscribers(this.subscriberType).then((data) => {
- this.$utils.toast(this.$t(
- 'globals.messages.deletedCount',
- { name: this.$tc('globals.terms.subscribers', 2), num: data.count },
- ));
- });
- },
- );
- },
-
- deleteSubscriptions() {
- this.$utils.confirm(
- null,
- () => {
- this.$api.deleteGCSubscriptions(this.subscriptionDate).then((data) => {
- this.$utils.toast(this.$t(
- 'globals.messages.deletedCount',
- { name: this.$tc('globals.terms.subscriptions', 2), num: data.count },
- ));
- });
- },
- );
- },
-
- deleteAnalytics() {
- this.$utils.confirm(
- null,
- () => {
- this.$api.deleteGCCampaignAnalytics(this.analyticsType, this.analyticsDate)
- .then(() => {
- this.$utils.toast(this.$t('globals.messages.done'));
- });
- },
- );
- },
-
- loadDBSettings() {
- this.$api.getSettings().then((data) => {
- if (data['maintenance.db'] !== undefined) {
- this.dbSettings = { ...data['maintenance.db'] };
- }
- });
- },
-
- async onUpdateDBSettings() {
- this.isLoading = true;
- const data = await this.$api.updateSettingsByKey('maintenance.db', this.dbSettings);
- await this.$root.awaitRestart(data);
- this.isLoading = false;
- },
- },
-
- computed: {
- ...mapState(['loading']),
-
- exportURL() {
- const since = encodeURIComponent(dayjs(this.exportDate).toISOString());
- return `/api/maintenance/analytics/${this.exportType}/export?since=${since}`;
- },
- },
-
-});
-</script>
diff --git a/static/admin/src/css/style.css b/static/admin/src/css/style.css
index 1dd5367a..c8bce297 100644
--- a/static/admin/src/css/style.css
+++ b/static/admin/src/css/style.css
@@ -1065,7 +1065,7 @@ section.analytics {
color: var(--primary);
display: inline-block;
margin-inline-end: var(--space-2);
- min-width: 175px;
+ min-width: 100px;
user-select: auto;
}
diff --git a/static/admin/src/js/views/logs.js b/static/admin/src/js/views/logs.js
new file mode 100644
index 00000000..4c498390
--- /dev/null
+++ b/static/admin/src/js/views/logs.js
@@ -0,0 +1,56 @@
+import { urls } from '../main.js';
+
+// Regexp for splitting a log line into [timestamp] [file] [message].
+// 2021/05/01 00:00:00:00 init.go:99: reading config: config.toml
+const reLine = /^([0-9\s:/]+\.[0-9]{6}) (.+?\.go:[0-9]+|\*):\s(.+)$/;
+
+const POLL_INTERVAL = 10000;
+
+function splitLine(l) {
+ const parts = l.split(reLine);
+ if (parts.length !== 5) {
+ return { timestamp: '', file: '', message: l };
+ }
+ return { timestamp: parts[1], file: parts[2], message: parts[3] };
+}
+
+function component() {
+ return {
+ lines: (window._logs || []).filter((l) => l).map(splitLine),
+ loading: false,
+ pollID: null,
+
+ init() {
+ this.$nextTick(() => this.scrollToBottom());
+
+ // Refresh the logs every 10 seconds.
+ this.pollID = setInterval(() => this.getLogs(), POLL_INTERVAL);
+ },
+
+ destroy() {
+ clearInterval(this.pollID);
+ },
+
+ async getLogs() {
+ this.loading = true;
+ try {
+ const resp = await fetch(`${urls.api}/logs`, { headers: { Accept: 'application/json' } });
+ const out = await resp.json();
+ this.lines = (out.data || []).filter((l) => l).map(splitLine);
+ this.$nextTick(() => this.scrollToBottom());
+ } finally {
+ this.loading = false;
+ }
+ },
+
+ scrollToBottom() {
+ if (this.$refs.lines) {
+ this.$refs.lines.scrollTop = this.$refs.lines.scrollHeight;
+ }
+ },
+ };
+}
+
+document.addEventListener('alpine:init', () => {
+ window.Alpine.data('logsView', component);
+}, { once: true });
diff --git a/static/admin/src/js/views/maintenance.js b/static/admin/src/js/views/maintenance.js
new file mode 100644
index 00000000..2762cfea
--- /dev/null
+++ b/static/admin/src/js/views/maintenance.js
@@ -0,0 +1,115 @@
+import {
+ api,
+ isLoading,
+ i18n,
+ urls,
+} from '../main.js';
+import * as u from '../utils.js';
+
+// Returns a 'YYYY-MM-DD' string for (today - n days), for <input type="date"> defaults.
+function daysAgo(n) {
+ const d = new Date();
+ d.setDate(d.getDate() - n);
+ return d.toISOString().slice(0, 10);
+}
+
+// Converts a 'YYYY-MM-DD' date input value to an RFC3339 timestamp.
+function toRFC3339(date) {
+ return new Date(date).toISOString();
+}
+
+function component() {
+ return {
+ isLoading,
+
+ subscriberType: 'orphan',
+ subscriptionType: 'optin',
+ analyticsType: 'all',
+ exportType: 'views',
+ subscriptionDate: daysAgo(7),
+ analyticsDate: daysAgo(7),
+ exportDate: daysAgo(30),
+
+ dbSettings: {
+ vacuum: false,
+ vacuum_cron_interval: '0 2 * * *',
+ ...(window._dbSettings || {}),
+ },
+ isSaving: false,
+
+ get exportURL() {
+ if (!this.exportDate) {
+ return '#';
+ }
+ const since = encodeURIComponent(toRFC3339(this.exportDate));
+ return `${urls.api}/maintenance/analytics/${this.exportType}/export?since=${since}`;
+ },
+
+ // ===============
+ // Event handlers.
+ async deleteSubscribers() {
+ if (!(await u.confirm())) {
+ return;
+ }
+
+ const data = await api('maintenance', `/maintenance/subscribers/${this.subscriberType}`, 'DELETE');
+ u.toast(i18n.ts('globals.messages.deletedCount', {
+ name: i18n.tc('globals.terms.subscribers', 2),
+ num: data.count,
+ }));
+ },
+
+ async deleteSubscriptions() {
+ if (!(await u.confirm())) {
+ return;
+ }
+
+ const since = encodeURIComponent(toRFC3339(this.subscriptionDate));
+ const data = await api('maintenance', `/maintenance/subscriptions/unconfirmed?before_date=${since}`, 'DELETE');
+ u.toast(i18n.ts('globals.messages.deletedCount', {
+ name: i18n.tc('globals.terms.subscriptions', 2),
+ num: data.count,
+ }));
+ },
+
+ async deleteAnalytics() {
+ if (!(await u.confirm())) {
+ return;
+ }
+
+ const since = encodeURIComponent(toRFC3339(this.analyticsDate));
+ await api('maintenance', `/maintenance/analytics/${this.analyticsType}?before_date=${since}`, 'DELETE');
+ u.toast(i18n.t('globals.messages.done'));
+ },
+
+ async onUpdateDBSettings() {
+ this.isSaving = true;
+ try {
+ await api('settings', '/settings/maintenance.db', 'PUT', this.dbSettings);
+ await this._awaitRestart();
+ } finally {
+ this.isSaving = false;
+ }
+ },
+
+ // Poll the health endpoint until the app is back up after a settings-triggered
+ // restart, then reload the page.
+ _awaitRestart() {
+ u.toast(i18n.ts('globals.messages.updated', { name: i18n.t('settings.title') }));
+ return new Promise((resolve) => {
+ const poll = setInterval(() => {
+ fetch(`${urls.api}/health`).then((r) => {
+ if (r.ok) {
+ clearInterval(poll);
+ resolve();
+ }
+ }).catch(() => { });
+ }, 500);
+ });
+ },
+ };
+}
+
+document.addEventListener('alpine:init', () => {
+ window.Alpine.data('maintenanceView', component);
+}, { once: true });
diff --git a/static/admin/views/logs.html b/static/admin/views/logs.html
new file mode 100644
index 00000000..1fcde60f
--- /dev/null
+++ b/static/admin/views/logs.html
@@ -0,0 +1,33 @@
+{{ define "admin-logs" -}}
+{{ template "admin-header" . }}
+{{- $d := .Data -}}
+
+<section class="logs relative" x-data="logsView">
+ <header class="row page-header">
+ <div class="col-8">
+ <h1 class="page-title">{{ .L.T "logs.title" }}</h1>
+ </div>
+ </header>
+
+ <div class="card page-content">
+ <div class="log-view">
+ <div class="lines" x-ref="lines">
+ <template x-for="(l, i) in lines" :key="i">
+ <span class="line">
+ <span class="timestamp" x-text="l.timestamp"></span>
+ <span class="file" x-show="l.file && l.file !== '*'" x-text="l.file + ':'"></span>
+ <span class="log-message" x-text="l.message"></span>
+ </span>
+ </template>
+ </div>
+ </div>
+ </div>
+</section>
+
+<script>
+ window._logs = {{ ToJSON $d.Lines }};
+</script>
+<script type="module" src="{{ URI "/admin/static/js/views/logs.js" }}?v={{ .AssetVersion }}" defer></script>
+
+{{ template "admin-footer" . -}}
+{{ end }}
diff --git a/static/admin/views/maintenance.html b/static/admin/views/maintenance.html
new file mode 100644
index 00000000..2391be68
--- /dev/null
+++ b/static/admin/views/maintenance.html
@@ -0,0 +1,160 @@
+{{ define "admin-maintenance" -}}
+{{ template "admin-header" . }}
+{{- $d := .Data -}}
+
+<section class="maintenance" x-data="maintenanceView">
+ <header class="row page-header">
+ <div class="col-8">
+ <h1 class="page-title">{{ .L.T "maintenance.title" }}</h1>
+ <p class="text-light text-7">{{ .L.T "maintenance.help" }}</p>
+ </div>
+ </header>
+
+ <div class="page-content vstack gap-6">
+ <!-- Subscribers -->
+ <div class="card">
+ <h4 class="text-4">{{ .L.T "globals.terms.subscribers" }}</h4>
+ <div class="row">
+ <div class="col-4">
+ <label data-field>
+ Data
+ <select aria-label="Data" x-model="subscriberType">
+ <option value="orphan">{{ .L.T "dashboard.orphanSubs" }}</option>
+ <option value="blocklisted">{{ .L.T "subscribers.status.blocklisted" }}</option>
+ </select>
+ <small data-hint>{{ .L.T "maintenance.orphanHelp" }}</small>
+ </label>
+ </div>
+ <div class="col-8 col-end hstack justify-end">
+ <button type="button" data-variant="danger" data-cy="btn-delete-subscribers"
+ :disabled="isLoading('maintenance')" :aria-busy="isLoading('maintenance')" data-spinner="small"
+ @click="deleteSubscribers">
+ {{ Icon "trash-2" }} {{ .L.T "globals.buttons.delete" }}
+ </button>
+ </div>
+ </div>
+ </div>
+
+ <!-- Subscriptions -->
+ <div class="card">
+ <h4 class="text-4">{{ .L.Tc "globals.terms.subscriptions" 2 }}</h4>
+ <div class="row">
+ <div class="col-4">
+ <label data-field>
+ Data
+ <select aria-label="Data" x-model="subscriptionType">
+ <option value="optin">{{ .L.T "maintenance.maintenance.unconfirmedOptins" }}</option>
+ </select>
+ </label>
+ </div>
+ <div class="col-4">
+ <label data-field>
+ {{ .L.T "maintenance.olderThan" }}
+ <input type="date" x-model="subscriptionDate" required />
+ </label>
+ </div>
+ <div class="col-4 col-end hstack justify-end">
+ <button type="button" data-variant="danger" data-cy="btn-delete-subscriptions"
+ :disabled="isLoading('maintenance') || !subscriptionDate" :aria-busy="isLoading('maintenance')" data-spinner="small"
+ @click="deleteSubscriptions">
+ {{ Icon "trash-2" }} {{ .L.T "globals.buttons.delete" }}
+ </button>
+ </div>
+ </div>
+ </div>
+
+ <!-- Analytics -->
+ <div class="card">
+ <h4 class="text-4">{{ .L.T "globals.terms.analytics" }}</h4>
+ <div class="row">
+ <div class="col-4">
+ <label data-field>
+ Data
+ <select aria-label="Data" x-model="analyticsType">
+ <option value="all">{{ .L.T "globals.terms.all" }}</option>
+ <option value="views">{{ .L.T "dashboard.campaignViews" }}</option>
+ <option value="clicks">{{ .L.T "dashboard.linkClicks" }}</option>
+ </select>
+ </label>
+ </div>
+ <div class="col-4">
+ <label data-field>
+ {{ .L.T "maintenance.olderThan" }}
+ <input type="date" x-model="analyticsDate" required />
+ </label>
+ </div>
+ <div class="col-4 col-end hstack justify-end">
+ <button type="button" data-variant="danger" data-cy="btn-delete-analytics"
+ :disabled="isLoading('maintenance') || !analyticsDate" :aria-busy="isLoading('maintenance')" data-spinner="small"
+ @click="deleteAnalytics">
+ {{ Icon "trash-2" }} {{ .L.T "globals.buttons.delete" }}
+ </button>
+ </div>
+ </div>
+
+ <hr />
+ <h5 class="text-5">{{ .L.T "subscribers.export" }}</h5>
+ <div class="row">
+ <div class="col-4">
+ <label data-field>
+ Data
+ <select aria-label="Data" x-model="exportType">
+ <option value="views">{{ .L.T "dashboard.campaignViews" }}</option>
+ <option value="clicks">{{ .L.T "dashboard.linkClicks" }}</option>
+ </select>
+ </label>
+ </div>
+ <div class="col-4">
+ <label data-field>
+ {{ .L.T "analytics.fromDate" }}
+ <input type="date" x-model="exportDate" required />
+ </label>
+ </div>
+ <div class="col-4 col-end hstack justify-end">
+ <a class="button" data-variant="primary" data-cy="btn-export-analytics"
+ :href="exportURL" :aria-disabled="!exportDate">
+ {{ Icon "download-cloud" }} {{ .L.T "subscribers.export" }}
+ </a>
+ </div>
+ </div>
+ </div>
+
+ {{- if $d.Can "settings:manage" }}
+ <!-- Database -->
+ <form class="card" @submit.prevent="onUpdateDBSettings">
+ <h4 class="text-4">{{ .L.T "maintenance.database.title" }}</h4>
+ <h5 class="text-5">Vacuum</h5>
+ <p class="text-light text-7">{{ .L.T "maintenance.database.vacuumHelp" }}</p>
+ <div class="row">
+ <div class="col-3">
+ <label data-field>
+ <input type="checkbox" role="switch" x-model="dbSettings.vacuum" />
+ {{ .L.T "globals.buttons.enabled" }}
+ </label>
+ </div>
+ <div class="col-4" :aria-disabled="!dbSettings.vacuum">
+ <label data-field>
+ {{ .L.T "settings.maintenance.cron" }}
+ <input placeholder="0 2 * * *" pattern="((\*|[0-9,\-\/]+)\s+){4}(\*|[0-9,\-\/]+)"
+ :disabled="!dbSettings.vacuum" x-model="dbSettings.vacuum_cron_interval" />
+ </label>
+ </div>
+ <div class="col-5 col-end hstack justify-end">
+ <button type="submit" data-variant="primary" data-cy="btn-save-db"
+ :disabled="isSaving" :aria-busy="isSaving" data-spinner="small">
+ {{ Icon "save" }} {{ .L.T "globals.buttons.save" }}
+ </button>
+ </div>
+ </div>
+ </form>
+ {{- end }}
+ </div>
+</section>
+
+<script>
+ window._dbSettings = {{ ToJSON $d.DBSettings }};
+</script>
+<script type="module" src="{{ URI "/admin/static/js/views/maintenance.js" }}?v={{ .AssetVersion }}" defer></script>
+
+{{ template "admin-footer" . -}}
+{{ end }}