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
{{ define "admin-import" -}}
{{ template "admin-header" . }}
{{ template "breadcrumbs" dict "Root" . "Current" .Data.Title "Parents" (list (dict "Label" (.L.T "globals.terms.subscribers") "URL" (URI "/admin/subscribers") "CanLink" (.Data.Can "subscribers:get" "subscribers:get_all"))) }}
{{- $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="page-header">
<h1 class="page-title">{{ .L.T "import.title" }}</h1>
</header>
<div class="page-content">
<!-- Upload form. -->
{{ if $show }}
<form @submit.prevent="onUpload">
<fieldset class="card">
<legend>{{ .L.T "import.title" }}</legend>
<div class="row fields">
<div class="col-4">
<fieldset class="vstack gap-6">
<legend>{{ .L.T "globals.fields.mode" }}</legend>
<div class="hstack">
<label><input type="radio" name="mode" value="subscribe" x-model="form.mode" data-testid="check-subscribe" /> {{ .L.T "globals.buttons.subscribe" }}</label>
<label><input type="radio" name="mode" value="blocklist" x-model="form.mode" data-testid="check-blocklist" /> {{ .L.T "globals.terms.blocklist" }}</label>
</div>
<label data-field>
<input type="checkbox" role="switch" x-model="form.overwriteUserInfo" data-testid="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-testid="check-unconfirmed" /> {{ .L.T "globals.terms.unconfirmed" }}</label>
<label><input type="radio" name="subStatus" value="confirmed" x-model="form.subStatus" data-testid="check-confirmed" /> {{ .L.T "globals.terms.confirmed" }}</label>
</div>
</template>
<template x-if="form.mode === 'blocklist'">
<label><input type="radio" name="subStatus" value="unsubscribed" x-model="form.subStatus" data-testid="check-unsubscribed" /> {{ .L.T "globals.terms.unsubscribed" }}</label>
</template>
<template x-if="form.mode === 'subscribe'">
<label data-field>
<input type="checkbox" role="switch" x-model="form.overwriteSubStatus" data-testid="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>
</fieldset>
<template x-if="form.mode === 'subscribe'">
<fieldset class="card">
<legend>{{ .L.T "globals.terms.lists" }}</legend>
{{ template "list-selector" dict "Root" . "Model" "form.lists" "ListID" "import-lists" "Placeholder" "import.listSubHelp" }}
</fieldset>
</template>
<fieldset class="card">
<legend>{{ .L.T "globals.buttons.upload" }}</legend>
<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>
</fieldset>
<footer class="hstack justify-end mt-6">
<button type="submit" data-variant="primary" data-testid="btn-upload" :disabled="!canUpload || isProcessing" :aria-busy="isProcessing">
{{ Icon "upload" }} {{ .L.T "globals.buttons.upload" }}
</button>
</footer>
</form>
{{ end }}
<!-- Running / done status. -->
{{ if not $show }}
<section class="status">
<article class="card float">
<h5 class="title capitalize" :class="{ 'text-danger': status.status === 'failed' || status.status === 'stopped' }" x-text="status.status">{{ $d.Status.Status }}</h5>
<div class="row">
<header class="col-8">
<small class="text-light hstack">
<!-- Not the Badge template func as Alpine binds the variant and the content here. -->
<span class="badge" :data-variant="statusVariant" x-text="progress + '%'"></span>
<span x-show="isRunning" aria-busy="true" data-spinner="small"></span>
</small>
</header>
<div class="col-4 hstack justify-end items-center">
<button type="button" data-variant="danger" data-testid="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-testid="btn-done" x-show="isDone" @click="stopImport" :disabled="isProcessing" :aria-busy="isProcessing">{{ .L.T "globals.messages.done" }}</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>
<article class="card float import-logs log-view mt-6">
<h5 class="title">{{ .L.T "globals.terms.logs" }}</h5>
<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>
</article>
</section>
{{ end }}
{{ if $show }}
<div class="import-help mt-6">
<h6>{{ .L.T "globals.terms.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 }}