diff --git a/admin.go b/admin.go index 4111e04..f704e32 100644 --- a/admin.go +++ b/admin.go @@ -1,13 +1,43 @@ package main import ( + "bytes" + "encoding/json" "net/http" "github.com/labstack/echo" ) +type configScript struct { + RootURL string `json:"rootURL"` + UploadURI string `json:"uploadURL"` + FromEmail string `json:"fromEmail"` + Messengers []string `json:"messengers"` +} + // handleGetStats returns a collection of general statistics. func handleGetStats(c echo.Context) error { app := c.Get("app").(*App) return c.JSON(http.StatusOK, okResp{app.Runner.GetMessengerNames()}) } + +// handleGetConfigScript returns general configuration as a Javascript +// variable that can be included in an HTML page directly. +func handleGetConfigScript(c echo.Context) error { + var ( + app = c.Get("app").(*App) + out = configScript{ + RootURL: app.Constants.RootURL, + UploadURI: app.Constants.UploadURI, + FromEmail: app.Constants.FromEmail, + Messengers: app.Runner.GetMessengerNames(), + } + + b = bytes.Buffer{} + j = json.NewEncoder(&b) + ) + + b.Write([]byte(`var CONFIG = `)) + j.Encode(out) + return c.Blob(http.StatusOK, "application/javascript", b.Bytes()) +} diff --git a/campaigns.go b/campaigns.go index 5843ea3..f5a3c6b 100644 --- a/campaigns.go +++ b/campaigns.go @@ -401,12 +401,6 @@ func handleGetRunningCampaignStats(c echo.Context) error { return c.JSON(http.StatusOK, okResp{out}) } -// handleGetCampaignMessengers returns the list of registered messengers. -func handleGetCampaignMessengers(c echo.Context) error { - app := c.Get("app").(*App) - return c.JSON(http.StatusOK, okResp{app.Runner.GetMessengerNames()}) -} - // handleTestCampaign handles the sending of a campaign message to // arbitrary subscribers for testing. func handleTestCampaign(c echo.Context) error { diff --git a/config.toml.sample b/config.toml.sample index 2d3bf91..15f57f8 100644 --- a/config.toml.sample +++ b/config.toml.sample @@ -3,8 +3,8 @@ # Interface and port where the app will run its webserver. address = "0.0.0.0:9000" -# Root to the listmonk installation that'll be used in the e-mails for linking to -# images, the unsubscribe URL etc. +# Public root URL of the listmonk installation that'll be used +# in the messages for linking to images, unsubscribe page etc. root = "http://listmonk.mysite.com" # The default 'from' e-mail for outgoing e-mail campaigns. diff --git a/frontend/my/public/index.html b/frontend/my/public/index.html index 7f64787..ac8ab82 100644 --- a/frontend/my/public/index.html +++ b/frontend/my/public/index.html @@ -4,21 +4,9 @@ - + - React App diff --git a/frontend/my/src/App.js b/frontend/my/src/App.js index 59c2a64..702839d 100644 --- a/frontend/my/src/App.js +++ b/frontend/my/src/App.js @@ -118,6 +118,7 @@ class App extends React.PureComponent { ) diff --git a/frontend/my/src/Campaign.js b/frontend/my/src/Campaign.js index e21aa0b..3d4a1c9 100644 --- a/frontend/my/src/Campaign.js +++ b/frontend/my/src/Campaign.js @@ -298,7 +298,7 @@ class TheFormDef extends React.PureComponent { {getFieldDecorator("from_email", { - initialValue: record.from_email, + initialValue: record.from_email ? record.from_email : this.props.config.fromEmail, rules: [{ required: true }, { validator: this.validateEmail }] })()} @@ -325,10 +325,10 @@ class TheFormDef extends React.PureComponent { )} - + {getFieldDecorator("messenger", { initialValue: record.messenger ? record.messenger : "email" })( - {[...this.props.messengers].map((v, i) => + {[...this.props.config.messengers].map((v, i) => { v } )} @@ -395,7 +395,6 @@ class Campaign extends React.PureComponent { campaignID: this.props.route.match.params ? parseInt(this.props.route.match.params.campaignID, 10) : 0, record: {}, contentType: "richtext", - messengers: [], previewRecord: null, body: "", currentTab: "form", @@ -412,14 +411,11 @@ class Campaign extends React.PureComponent { // Fetch templates. this.props.modelRequest(cs.ModelTemplates, cs.Routes.GetTemplates, cs.MethodGet) - // Fetch messengers. - this.props.request(cs.Routes.GetCampaignMessengers, cs.MethodGet).then((r) => { - this.setState({ messengers: r.data.data, loading: false }) - }) - // Fetch campaign. if(this.state.campaignID) { this.fetchRecord(this.state.campaignID) + } else { + this.setState({ loading: false }) } } @@ -482,7 +478,6 @@ class Campaign extends React.PureComponent {