Skip to content

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

SSR: Port subscriber import page.

Kailash Nadh720b55b0ae5d
diff --git a/cmd/admin.go b/cmd/admin.go
index 9b99485b..2e804fa3 100644
--- a/cmd/admin.go
+++ b/cmd/admin.go
@@ -71,6 +71,12 @@ var adminJSI18nKeys = []string{
"lists.optins.single",
"lists.optins.double",
+ "import.importStarted",
+ "import.subscribeWarning",
+ "import.recordsCount",
+ "import.importDone",
+ "import.stopImport",
+
"public.sub",
"public.subName",
"subscribers.email",
diff --git a/cmd/handlers.go b/cmd/handlers.go
index 72f899be..8d226941 100644
--- a/cmd/handlers.go
+++ b/cmd/handlers.go
@@ -75,6 +75,7 @@ func initHTTPHandlers(e *echo.Echo, a *App) {
g.GET(path.Join(uriAdmin, "/lists"), a.ViewLists)
g.GET(path.Join(uriAdmin, "/lists/:id"), hasID(a.ViewList))
g.GET(path.Join(uriAdmin, "/lists/forms"), a.ViewForms)
+ g.GET(path.Join(uriAdmin, "/import"), a.ViewImport)
g.GET(path.Join(uriAdmin, "/subscribers"), a.ViewSubscribers)
g.POST(path.Join(uriAdmin, "/subscribers"), a.ViewSubscribers)
g.GET(path.Join(uriAdmin, "/subscribers/lists/:id"), hasID(a.ViewSubscribers))
diff --git a/cmd/import.go b/cmd/import.go
index c51893a6..bdf42f1f 100644
--- a/cmd/import.go
+++ b/cmd/import.go
@@ -13,6 +13,49 @@ import (
"github.com/labstack/echo/v4"
)
+// importView is the admin view for the subscriber import page.
+type importView struct {
+ adminView
+
+ AllLists []models.List
+ SelectedLists []models.List
+ Status subimporter.Status
+}
+
+// ViewImport renders the HTML view for the subscriber CSV import page.
+func (a *App) ViewImport(c echo.Context) error {
+ // Get the lists the user can access.
+ allLists, err := a.getViewableLists(c)
+ if err != nil {
+ return err
+ }
+
+ // Get the lists to pre-select (in the form) from the `list_id`` query param.
+ var selected []models.List
+ if ids, err := getQueryInts("list_id", c.QueryParams()); err == nil && len(ids) > 0 {
+ s := make(map[int]struct{}, len(ids))
+ for _, id := range ids {
+ s[id] = struct{}{}
+ }
+ for _, l := range allLists {
+ if _, ok := s[l.ID]; ok {
+ selected = append(selected, l)
+ }
+ }
+ }
+
+ data := importView{
+ adminView: newAdminView(c, a.i18n.T("import.title"), ""),
+ AllLists: allLists,
+ SelectedLists: selected,
+
+ // Live import stats.
+ Status: a.importer.GetStats(),
+ }
+
+ return c.Render(http.StatusOK, "admin-import", data)
+}
+
// ImportSubscribers handles the uploading and bulk importing of
// a ZIP file of one or more CSV files.
func (a *App) ImportSubscribers(c echo.Context) error {
diff --git a/frontend-vue/src/router/index.js b/frontend-vue/src/router/index.js
index 14d50fd4..245bed8f 100644
--- a/frontend-vue/src/router/index.js
+++ b/frontend-vue/src/router/index.js
@@ -17,12 +17,6 @@ const routes = [
meta: { title: '' },
component: () => import('../views/Dashboard.vue'),
},
- {
- path: '/subscribers/import',
- name: 'import',
- meta: { title: 'import.title', group: 'subscribers' },
- component: () => import('../views/Import.vue'),
- },
{
path: '/subscribers/bounces',
name: 'bounces',
diff --git a/frontend-vue/src/views/Import.vue b/frontend-vue/src/views/Import.vue
deleted file mode 100644
index f8b6121b..00000000
--- a/frontend-vue/src/views/Import.vue
+++ /dev/null
@@ -1,380 +0,0 @@
-<template>
- <section class="import">
- <header class="row page-header">
- <div class="col-8">
- <h1>
- {{ $t('import.title') }}
- </h1>
- </div>
- </header>
-
- <div class="card page-content" :aria-busy="isLoading ? 'true' : null" data-spinner="large overlay">
- <section v-if="isFree()">
- <form @submit.prevent="onUpload" class="card">
- <div>
- <div class="row">
- <div class="col-12">
- <b-field :label="$t('import.mode')" :addons="false">
- <div>
- <b-radio v-model="form.mode" name="mode" native-value="subscribe" data-cy="check-subscribe">
- {{ $t('import.subscribe') }}
- </b-radio>
- <br />
- <b-radio v-model="form.mode" name="mode" native-value="blocklist" data-cy="check-blocklist">
- {{ $t('import.blocklist') }}
- </b-radio>
- </div>
- </b-field>
- </div>
- <div class="col-12">
- <b-field :label="$t('globals.fields.status')" :addons="false">
- <template v-if="form.mode === 'subscribe'">
- <b-radio v-model="form.subStatus" name="subStatus" native-value="unconfirmed"
- data-cy="check-unconfirmed">
- {{ $t('subscribers.status.unconfirmed') }}
- </b-radio>
- <b-radio v-model="form.subStatus" name="subStatus" native-value="confirmed"
- data-cy="check-confirmed">
- {{ $t('subscribers.status.confirmed') }}
- </b-radio>
- </template>
-
- <b-radio v-else v-model="form.subStatus" name="subStatus" native-value="unsubscribed"
- data-cy="check-unsubscribed">
- {{ $t('subscribers.status.unsubscribed') }}
- </b-radio>
- </b-field>
- </div>
-
- <div class="col-12">
- <b-field :label="$t('import.csvDelim')" :message="$t('import.csvDelimHelp')" class="delimiter">
- <input aria-label="field" v-model="form.delim" name="delim" placeholder="," maxlength="1" required>
- </b-field>
- </div>
- </div>
-
- <div class="row">
- <div class="col-4">
- <b-field v-if="form.mode === 'subscribe'" :label="$t('import.overwriteUserInfo')"
- :message="$t('import.overwriteUserInfoHelp')">
- <div>
- <b-switch v-model="form.overwriteUserInfo" name="overwriteUserInfo"
- data-cy="overwrite-user-info" />
- </div>
- </b-field>
- </div>
-
- <div class="col-12">
- <b-field v-if="form.mode === 'subscribe'" :label="$t('import.overwriteSubStatus')"
- :message="$t('import.overwriteSubStatusHelp')">
- <div>
- <b-switch v-model="form.overwriteSubStatus" name="overwriteSubStatus"
- data-cy="overwrite-sub-status" />
- </div>
- </b-field>
- </div>
- </div>
-
- <list-selector v-if="form.mode === 'subscribe'" :label="$t('globals.terms.lists')"
- :placeholder="$t('import.listSubHelp')" :message="$t('import.listSubHelp')" v-model="form.lists"
- :selected="form.lists" :all="lists.results" />
- <hr />
-
- <b-field :label="$t('import.csvFile')">
- <b-upload v-model="form.file">
- <div class="align-center app-section">
- <p>
- <b-icon icon="file-upload-outline" />
- </p>
- <p>{{ $t('import.csvFileHelp') }}</p>
- </div>
- </b-upload>
- </b-field>
- <div class="hstack" v-if="form.file">
- <span closable @close="clearFile">
- {{ form.file.name }}
- </span>
- </div>
- <div class="hstack">
- <button type="submit" data-variant="primary"
- :disabled="!form.file || (form.mode === 'subscribe' && form.lists.length === 0)"
- :loading="isProcessing">
- {{ $t('import.upload') }}
- </button>
- </div>
- </div>
- </form>
- <br /><br />
-
- <div class="import-help">
- <h5>
- {{ $t('import.instructions') }}
- </h5>
- <p>{{ $t('import.instructionsHelp') }}</p>
- <br />
- <blockquote class="csv-example">
- <code class="csv-headers"> <span>email,</span> <span>name,</span> <span>attributes</span></code>
- </blockquote>
-
- <hr />
-
- <h5>
- {{ $t('import.csvExample') }}
- </h5>
-
- <pre class="csv-example" v-text="example" />
- </div>
- </section><!-- upload //-->
-
- <section v-if="isRunning() || isDone()" class="wrap status card align-center">
- <progress :value="progress" data-variant="primary" />
- <br />
- <p
- :class="['text-5', 'capitalize', { 'text-success': status.status === 'finished' }, { 'text-danger': (status.status === 'failed' || status.status === 'stopped') }]">
- {{ status.status }}
- </p>
-
- <p>{{ $t('import.recordsCount', { num: status.imported, total: status.total }) }}</p>
- <br />
-
- <p>
- <button type="button" @click="stopImport" :loading="isProcessing" data-variant="primary">
- {{ isDone() ? $t('import.importDone') : $t('import.stopImport') }}
- </button>
- </p>
- <br />
-
- <div class="import-logs">
- <log-view :lines="logs" :loading="false" />
- </div>
- </section>
- </div>
- </section>
-</template>
-
-<script>
-import Vue from 'vue';
-import { mapState } from 'vuex';
-import ListSelector from '../components/ListSelector.vue';
-import LogView from '../components/LogView.vue';
-
-export default Vue.extend({
- components: {
- ListSelector,
- LogView,
- },
-
- props: {
- data: { type: Object, default: () => { } },
- isEditing: { type: Boolean, default: false },
- },
-
- data() {
- return {
- form: {
- mode: 'subscribe',
- subStatus: 'unconfirmed',
- delim: ',',
- lists: [],
- overwriteUserInfo: false,
- overwriteSubStatus: false,
- file: null,
- example: '',
- },
-
- // Initial page load still has to wait for the status API to return
- // to either show the form or the status card.
- isLoading: true,
-
- isProcessing: false,
- status: { status: '' },
- logs: [],
- pollID: null,
- };
- },
-
- watch: {
- 'form.mode': function formMode() {
- // Select the appropriate status radio whenever mode changes.
- this.$nextTick(() => {
- if (this.form.mode === 'subscribe') {
- this.form.subStatus = 'unconfirmed';
- } else {
- this.form.subStatus = 'unsubscribed';
- }
- });
- },
- },
-
- methods: {
- clearFile() {
- this.form.file = null;
- },
-
- // Returns true if we're free to do an upload.
- isFree() {
- if (this.status.status === 'none') {
- return true;
- }
- return false;
- },
-
- // Returns true if an import is running.
- isRunning() {
- if (this.status.status === 'importing'
- || this.status.status === 'stopping') {
- return true;
- }
- return false;
- },
-
- isSuccessful() {
- return this.status.status === 'finished';
- },
-
- isFailed() {
- return (
- this.status.status === 'stopped'
- || this.status.status === 'failed'
- );
- },
-
- // Returns true if an import has finished (failed or successful).
- isDone() {
- if (this.status.status === 'finished'
- || this.status.status === 'stopped'
- || this.status.status === 'failed'
- ) {
- return true;
- }
- return false;
- },
-
- pollStatus() {
- // Clear any running status polls.
- clearInterval(this.pollID);
-
- // Poll for the status as long as the import is running.
- this.pollID = setInterval(() => {
- this.$api.getImportStatus().then((data) => {
- this.isProcessing = false;
- this.isLoading = false;
- this.status = data;
- this.getLogs();
-
- if (!this.isRunning()) {
- clearInterval(this.pollID);
- }
- }, () => {
- this.isProcessing = false;
- this.isLoading = false;
- this.status = { status: 'none' };
- clearInterval(this.pollID);
- });
- return true;
- }, 250);
- },
-
- getLogs() {
- this.$api.getImportLogs().then((data) => {
- this.logs = data.split('\n').map((line) => line.replace(/\s+importer\.go:\d+:\s*/, ' *: '));
- Vue.nextTick(() => {
- // vue.$refs doesn't work as the logs textarea is rendered dynamically.
- const ref = document.getElementById('import-log');
- if (ref) {
- ref.scrollTop = ref.scrollHeight;
- }
- });
- });
- },
-
- // Cancel a running import or clears a finished import.
- stopImport() {
- this.isProcessing = true;
- this.$api.stopImport().then(() => {
- this.pollStatus();
- this.form.file = null;
- });
- },
-
- renderExample() {
- const h = 'email,name,attributes\n'
- + '[email protected],"User One","{""age"": 42, ""planet"": ""Mars""}"\n'
- + '[email protected],"User Two","{""age"": 24, ""job"": ""Time Traveller""}"';
-
- this.example = h;
- },
-
- resetForm() {
- this.form.mode = 'subscribe';
- this.form.overwriteUserInfo = false;
- this.form.overwriteSubStatus = false;
- this.form.file = null;
- this.form.lists = [];
- this.form.subStatus = 'unconfirmed';
- this.form.delim = ',';
- },
-
- onUpload() {
- if (this.form.mode === 'subscribe' && this.form.overwriteSubStatus) {
- this.$utils.confirm(this.$t('import.subscribeWarning'), this.onSubmit, this.resetForm);
- return;
- }
-
- this.onSubmit();
- },
-
- onSubmit() {
- this.isProcessing = true;
-
- // Prepare the upload payload.
- const params = new FormData();
- params.set('params', JSON.stringify({
- mode: this.form.mode,
- subscription_status: this.form.subStatus,
- delim: this.form.delim,
- lists: this.form.lists.map((l) => l.id),
- overwrite_userinfo: this.form.overwriteUserInfo,
- overwrite_subscription_status: this.form.overwriteSubStatus,
- }));
- params.set('file', this.form.file);
-
- // Post.
- this.$api.importSubscribers(params).then(() => {
- // On file upload, show a confirmation.
- this.$utils.toast(this.$t('import.importStarted'));
-
- // Start polling status.
- this.pollStatus();
- }, () => {
- this.isProcessing = false;
- this.form.file = null;
- });
- },
- },
-
- computed: {
- ...mapState(['lists']),
-
- // Import progress bar value.
- progress() {
- if (!this.status || !this.status.total > 0) {
- return 0;
- }
- return Math.ceil((this.status.imported / this.status.total) * 100);
- },
- },
-
- mounted() {
- this.renderExample();
- this.pollStatus();
-
- const ids = this.$utils.parseQueryIDs(this.$route.query.list_id);
- if (ids.length > 0 && this.lists.results) {
- this.$nextTick(() => {
- this.form.lists = this.lists.results.filter((l) => ids.indexOf(l.id) > -1);
- });
- }
- },
-});
-</script>
diff --git a/static/admin/src/css/style.css b/static/admin/src/css/style.css
index 5aa92cac..9100ea15 100644
--- a/static/admin/src/css/style.css
+++ b/static/admin/src/css/style.css
@@ -1098,6 +1098,10 @@ section.import {
max-height: 240px;
text-align: start;
}
+
+ .fields fieldset {
+ min-height: 170px;
+ }
}
.media-files {
diff --git a/static/admin/src/js/views/import.js b/static/admin/src/js/views/import.js
new file mode 100644
index 00000000..211cd64c
--- /dev/null
+++ b/static/admin/src/js/views/import.js
@@ -0,0 +1,229 @@
+import {
+ urls,
+ i18n,
+} from '../main.js';
+import * as u from '../utils.js';
+
+// ListTag is the object used in the <ot-taginput> list selector.
+class ListTag {
+ constructor(list) {
+ Object.assign(this, list);
+ }
+
+ toString() {
+ return this.name;
+ }
+}
+
+// _listAutocomplete populates the <ot-taginput> listselector's suggestions with lists.
+window._listAutocomplete = (el) => {
+ const ti = el.closest('ot-taginput');
+ const chosen = new Set((ti ? ti.value : []).map((l) => l.id));
+ const q = el.value.toLowerCase();
+
+ el.list.replaceChildren(...(window._lists || [])
+ .filter((l) => !chosen.has(l.id) && l.name.toLowerCase().includes(q))
+ .slice(0, 10)
+ .map((l) => {
+ const o = new Option(l.name);
+ o.data = new ListTag(l);
+ return o;
+ }));
+};
+
+// 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(.+)$/;
+
+function component() {
+ return {
+ form: {
+ mode: 'subscribe',
+ subStatus: 'unconfirmed',
+ delim: ',',
+ lists: (window._selectedLists || []).map((l) => new ListTag(l)),
+ overwriteUserInfo: false,
+ overwriteSubStatus: false,
+ file: null,
+ },
+
+ isProcessing: false,
+ status: window._importStatus || { status: 'none' },
+ logLines: [],
+ pollID: null,
+
+ init() {
+ // Reset the status radio whenever the mode changes.
+ this.$watch('form.mode', (mode) => {
+ this.form.subStatus = mode === 'subscribe' ? 'unconfirmed' : 'unsubscribed';
+ });
+
+ // Start polling if the upload's running.
+ if (this.isRunning) {
+ this.pollStatus();
+ } else if (this.isDone) {
+ this.getLogs();
+ }
+ },
+
+ // ===============
+ // State getters.
+ get isRunning() {
+ return this.status.status === 'importing' || this.status.status === 'stopping';
+ },
+
+ get isDone() {
+ return ['finished', 'stopped', 'failed'].includes(this.status.status);
+ },
+
+ get canUpload() {
+ return !!this.form.file && !(this.form.mode === 'subscribe' && this.form.lists.length === 0);
+ },
+
+ get progress() {
+ if (!this.status || !(this.status.total > 0)) {
+ return 0;
+ }
+ return Math.ceil((this.status.imported / this.status.total) * 100);
+ },
+
+ get recordsLabel() {
+ return i18n.ts('import.recordsCount', { num: this.status.imported || 0, total: this.status.total || 0 });
+ },
+
+ // Badge colour for the current status.
+ get statusVariant() {
+ if (this.status.status === 'finished') {
+ return 'success';
+ }
+ if (['failed', 'stopped'].includes(this.status.status)) {
+ return 'danger';
+ }
+
+ return 'secondary';
+ },
+
+ // ===============
+ // Event handlers.
+ onUpload() {
+ if (this.form.mode === 'subscribe' && this.form.overwriteSubStatus) {
+ u.confirm(i18n.t('import.subscribeWarning')).then((ok) => {
+ if (ok) {
+ this.onSubmit();
+ }
+ });
+ return;
+ }
+ this.onSubmit();
+ },
+
+ async onSubmit() {
+ this.isProcessing = true;
+
+ const params = new FormData();
+ params.set('params', JSON.stringify({
+ mode: this.form.mode,
+ subscription_status: this.form.subStatus,
+ delim: this.form.delim,
+ lists: this.form.lists.map((l) => l.id),
+ overwrite_userinfo: this.form.overwriteUserInfo,
+ overwrite_subscription_status: this.form.overwriteSubStatus,
+ }));
+ params.set('file', this.form.file);
+
+ try {
+ const resp = await fetch(`${urls.api}/import/subscribers`, {
+ method: 'POST',
+ body: params,
+ headers: { Accept: 'application/json' },
+ });
+
+ const out = await resp.json().catch(() => ({}));
+ if (!resp.ok) {
+ u.toast(out.message || resp.statusText, 'danger');
+ this.isProcessing = false;
+ this.form.file = null;
+ return;
+ }
+
+ // Reload so the server re-renders the page into the status view.
+ u.reload({ message: i18n.t('import.importStarted') });
+ } catch (err) {
+ u.toast(err.message, 'danger');
+ this.isProcessing = false;
+ this.form.file = null;
+ }
+ },
+
+ // Stop a running import or clear a finished one.
+ async stopImport() {
+ this.isProcessing = true;
+ try {
+ await fetch(`${urls.api}/import/subscribers`, {
+ method: 'DELETE',
+ headers: { Accept: 'application/json' },
+ });
+ } catch (err) { }
+
+ // After clearing the server state, reload the page.
+ if (this.isDone) {
+ u.reload();
+ } else {
+ this.pollStatus();
+ }
+ },
+
+ // ===============
+ // Private functions.
+ pollStatus() {
+ clearInterval(this.pollID);
+
+ const f = async () => {
+ try {
+ const resp = await fetch(`${urls.api}/import/subscribers`, { headers: { Accept: 'application/json' } });
+ const out = await resp.json();
+ this.isProcessing = false;
+ this.status = out.data;
+ await this.getLogs();
+
+ if (!this.isRunning) {
+ clearInterval(this.pollID);
+ }
+ } catch (err) {
+ this.isProcessing = false;
+ this.status = { status: 'none' };
+ clearInterval(this.pollID);
+ }
+ };
+
+ this.pollID = setInterval(f, 500);
+ f();
+ },
+
+ async getLogs() {
+ const resp = await fetch(`${urls.api}/import/subscribers/logs`, { headers: { Accept: 'application/json' } });
+ const out = await resp.json();
+ this.logLines = (out.data || '').split('\n')
+ .filter((l) => l)
+ .map((l) => this._splitLine(l.replace(/\s+importer\.go:\d+:\s*/, ' *: ')));
+
+ this.$nextTick(() => {
+ if (this.$refs.logLines) {
+ this.$refs.logLines.scrollTop = this.$refs.logLines.scrollHeight;
+ }
+ });
+ },
+
+ _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] };
+ },
+ };
+}
+
+document.addEventListener('alpine:init', () => {
+ window.Alpine.data('importView', component);
+}, { once: true });
diff --git a/static/admin/views/import.html b/static/admin/views/import.html
new file mode 100644
index 00000000..8a8a9b32
--- /dev/null
+++ b/static/admin/views/import.html
@@ -0,0 +1,155 @@
+{{ define "admin-import" -}}
+{{ template "admin-header" . }}
+{{- $d := .Data -}}
+{{- $show := or (eq $d.Status.Status "none") (eq $d.Status.Status "") -}}
+
+<script>
+ window._lists = {{ ToJSON $d.AllLists }};
+ window._selectedLists = {{ ToJSON $d.SelectedLists }};
+ window._importStatus = {{ ToJSON $d.Status }};
+</script>
+
+<section class="import" x-data="importView()">
+ <header class="row page-header">
+ <div class="col-6">
+ <h1 class="page-title">{{ .L.T "import.title" }}</h1>
+ </div>
+ </header>
+
+ <div class="card page-content">
+ <!-- Upload form. -->
+ {{ if $show }}
+ <form @submit.prevent="onUpload">
+ <div class="row fields">
+ <div class="col-4">
+ <fieldset class="vstack gap-6">
+ <legend>{{ .L.T "import.mode" }}</legend>
+ <div class="hstack">
+ <label><input type="radio" name="mode" value="subscribe" x-model="form.mode" data-cy="check-subscribe" /> {{ .L.T "import.subscribe" }}</label>
+ <label><input type="radio" name="mode" value="blocklist" x-model="form.mode" data-cy="check-blocklist" /> {{ .L.T "import.blocklist" }}</label>
+ </div>
+ <label data-field>
+ <input type="checkbox" role="switch" x-model="form.overwriteUserInfo" data-cy="overwrite-user-info" /> {{ .L.T "import.overwriteUserInfo" }}
+ <small data-hint>{{ .L.T "import.overwriteUserInfoHelp" }}</small>
+ </label>
+ </fieldset>
+ </div>
+ <div class="col-4">
+ <fieldset class="vstack gap-6">
+ <legend>{{ .L.T "globals.fields.status" }}</legend>
+ <template x-if="form.mode === 'subscribe'">
+ <div class="hstack">
+ <label><input type="radio" name="subStatus" value="unconfirmed" x-model="form.subStatus" data-cy="check-unconfirmed" /> {{ .L.T "subscribers.status.unconfirmed" }}</label>
+ <label><input type="radio" name="subStatus" value="confirmed" x-model="form.subStatus" data-cy="check-confirmed" /> {{ .L.T "subscribers.status.confirmed" }}</label>
+ </div>
+ </template>
+ <template x-if="form.mode === 'blocklist'">
+ <label><input type="radio" name="subStatus" value="unsubscribed" x-model="form.subStatus" data-cy="check-unsubscribed" /> {{ .L.T "subscribers.status.unsubscribed" }}</label>
+ </template>
+ <template x-if="form.mode === 'subscribe'">
+ <label data-field>
+ <input type="checkbox" role="switch" x-model="form.overwriteSubStatus" data-cy="overwrite-sub-status" /> {{ .L.T "import.overwriteSubStatus" }}
+ <small data-hint>{{ .L.T "import.overwriteSubStatusHelp" }}</small>
+ </label>
+ </template>
+ </fieldset>
+ </div>
+ <div class="col-4">
+ <fieldset class="vstack gap-6">
+ <legend>{{ .L.T "import.csvDelim" }}</legend>
+ <label data-field class="delimiter">
+ <input name="delim" x-model="form.delim" placeholder="," maxlength="1" required />
+ <small data-hint>{{ .L.T "import.csvDelimHelp" }}</small>
+ </label>
+ </fieldset>
+ </div>
+ </div>
+
+ <template x-if="form.mode === 'subscribe'">
+ {{ template "list-selector" dict "Root" . "Model" "form.lists" "ListID" "import-lists" "Label" "globals.terms.lists" "Placeholder" "import.listSubHelp" }}
+ </template>
+
+ <div data-field>
+ <ot-upload>
+ <div data-field class="vstack">
+ <input type="file" name="file" accept=".csv,.zip" hidden @change="form.file = $event.target.files[0]" />
+ <strong>{{ .L.T "import.csvFile" }}</strong>
+
+ <button type="button" class="ghost" aria-label="{{ .L.T "import.csvFile" }}">
+ {{ Icon "upload" }}
+ </button>
+
+ <div data-files>
+ <small data-hint>{{ .L.T "import.csvFileHelp" }}</small>
+ </div>
+ </div>
+ </ot-upload>
+ </div>
+
+ <div class="hstack">
+ <button type="submit" data-variant="primary" data-cy="btn-upload" :disabled="!canUpload || isProcessing" :aria-busy="isProcessing">
+ {{ Icon "upload" }} {{ .L.T "import.upload" }}
+ </button>
+ </div>
+ </form>
+ {{ end }}
+
+ <!-- Running / done status. -->
+ {{ if not $show }}
+ <section class="status">
+ <article class="card stat-card">
+ <div class="row">
+ <header class="col-8">
+ <small class="text-light hstack">
+ <span class="badge" :data-variant="statusVariant" x-text="progress + '%'"></span>
+ <span x-show="isRunning" aria-busy="true" data-spinner="small"></span>
+ </small>
+ <div class="stat-value capitalize" :class="{ 'text-danger': status.status === 'failed' || status.status === 'stopped' }" x-text="status.status">{{ $d.Status.Status }}</div>
+ </header>
+ <div class="col-4 hstack justify-end items-center">
+ <button type="button" data-variant="danger" data-cy="btn-stop" x-show="!isDone" @click="stopImport" :disabled="isProcessing || status.status === 'stopping'" :aria-busy="isProcessing">{{ .L.T "import.stopImport" }}</button>
+ <button type="button" data-variant="primary" data-cy="btn-done" x-show="isDone" @click="stopImport" :disabled="isProcessing" :aria-busy="isProcessing">{{ .L.T "import.importDone" }}</button>
+ </div>
+ </div>
+ <footer>
+ <progress value="0" :value="progress" max="100"></progress>
+ <small class="text-light" x-text="recordsLabel">{{ .L.Ts "import.recordsCount" "num" (printf "%d" $d.Status.Imported) "total" (printf "%d" $d.Status.Total) }}</small>
+ </footer>
+ </article>
+
+ <div class="import-logs log-view mt-6">
+ <div class="lines" x-ref="logLines">
+ <template x-for="(l, i) in logLines" :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>
+ </section>
+ {{ end }}
+
+ {{ if $show }}
+ <div class="import-help mt-6">
+ <hr />
+ <h6>{{ .L.T "import.instructions" }}</h6>
+ <p class="text-light">{{ .L.T "import.instructionsHelp" }}</p>
+ <blockquote class="csv-example">
+ <code class="csv-headers"><span>email,</span> <span>name,</span> <span>attributes</span></code>
+ </blockquote>
+
+ <h6>{{ .L.T "import.csvExample" }}</h6>
+ <pre class="csv-example">email,name,attributes
[email protected],"User One","{""age"": 42, ""planet"": ""Mars""}"
[email protected],"User Two","{""age"": 24, ""job"": ""Time Traveller""}"</pre>
+ </div>
+ {{ end }}
+ </div>
+</section>
+
+<script type="module" src="{{ URI "/admin/static/js/views/import.js" }}?v={{ .AssetVersion }}" defer></script>
+
+{{ template "admin-footer" . -}}
+{{ end }}