Skip to content

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

Fix campaign template preview not working without saving. Closes #553.

Kailash Nadh5bfbe15c2437
diff --git a/cmd/campaigns.go b/cmd/campaigns.go
index f2a024e1..a48cc2a1 100644
--- a/cmd/campaigns.go
+++ b/cmd/campaigns.go
@@ -160,8 +160,9 @@ func handleGetCampaigns(c echo.Context) error {
// handlePreviewCampaign renders the HTML preview of a campaign body.
func handlePreviewCampaign(c echo.Context) error {
var (
- app = c.Get("app").(*App)
- id, _ = strconv.Atoi(c.Param("id"))
+ app = c.Get("app").(*App)
+ id, _ = strconv.Atoi(c.Param("id"))
+ tplID, _ = strconv.Atoi(c.FormValue("template_id"))
)
if id < 1 {
@@ -169,8 +170,7 @@ func handlePreviewCampaign(c echo.Context) error {
}
var camp models.Campaign
- err := app.queries.GetCampaignForPreview.Get(&camp, id)
- if err != nil {
+ if err := app.queries.GetCampaignForPreview.Get(&camp, id, tplID); err != nil {
if err == sql.ErrNoRows {
return echo.NewHTTPError(http.StatusBadRequest,
app.i18n.Ts("globals.messages.notFound", "name", "{globals.terms.campaign}"))
diff --git a/frontend/src/components/CampaignPreview.vue b/frontend/src/components/CampaignPreview.vue
index b6a4446b..71ded773 100644
--- a/frontend/src/components/CampaignPreview.vue
+++ b/frontend/src/components/CampaignPreview.vue
@@ -11,6 +11,7 @@
<section expanded class="modal-card-body preview">
<b-loading :active="isLoading" :is-full-page="false"></b-loading>
<form v-if="body" method="post" :action="previewURL" target="iframe" ref="form">
+ <input type="hidden" name="template_id" :value="templateId" />
<input type="hidden" name="content_type" :value="contentType" />
<input type="hidden" name="body" :value="body" />
</form>
@@ -44,6 +45,10 @@ export default {
type: String,
body: String,
contentType: String,
+ templateId: {
+ type: Number,
+ default: 0,
+ },
},
data() {
diff --git a/frontend/src/components/Editor.vue b/frontend/src/components/Editor.vue
index d07bf75b..fa373e9b 100644
--- a/frontend/src/components/Editor.vue
+++ b/frontend/src/components/Editor.vue
@@ -77,6 +77,7 @@
:id="id"
:title="title"
:contentType="form.format"
+ :templateId="templateId"
:body="form.body"></campaign-preview>
<!-- image picker -->
@@ -156,6 +157,10 @@ export default {
title: String,
body: String,
contentType: String,
+ templateId: {
+ type: Number,
+ default: 0,
+ },
disabled: Boolean,
},
diff --git a/frontend/src/views/Campaign.vue b/frontend/src/views/Campaign.vue
index 232eb32c..b8b3a4e6 100644
--- a/frontend/src/views/Campaign.vue
+++ b/frontend/src/views/Campaign.vue
@@ -160,6 +160,7 @@
v-model="form.content"
:id="data.id"
:title="data.name"
+ :templateId="form.templateId"
:contentType="data.contentType"
:body="data.body"
:disabled="!canEdit"
diff --git a/queries.sql b/queries.sql
index 35d4fb9d..108abf6d 100644
--- a/queries.sql
+++ b/queries.sql
@@ -495,7 +495,7 @@ SELECT campaigns.*, COALESCE(templates.body, (SELECT body FROM templates WHERE i
) l
) AS lists
FROM campaigns
-LEFT JOIN templates ON (templates.id = campaigns.template_id)
+LEFT JOIN templates ON (templates.id = (CASE WHEN $2=0 THEN campaigns.template_id ELSE $2 END))
WHERE campaigns.id = $1;
-- name: get-campaign-status