FIX: Populate the Email Digest preview with the current username

This commit is contained in:
Robin Ward 2017-06-28 15:36:34 -04:00
parent 6200d7d6ab
commit f6222ff225
7 changed files with 48 additions and 47 deletions

View File

@ -2,11 +2,13 @@ import EmailPreview from 'admin/models/email-preview';
import { popupAjaxError } from 'discourse/lib/ajax-error';
export default Ember.Controller.extend({
username: null,
lastSeen: null,
emailEmpty: Em.computed.empty('email'),
sendEmailDisabled: Em.computed.or('emailEmpty', 'sendingEmail'),
showSendEmailForm: Em.computed.notEmpty('model.html_content'),
htmlEmpty: Em.computed.empty('model.html_content'),
emailEmpty: Ember.computed.empty('email'),
sendEmailDisabled: Ember.computed.or('emailEmpty', 'sendingEmail'),
showSendEmailForm: Ember.computed.notEmpty('model.html_content'),
htmlEmpty: Ember.computed.empty('model.html_content'),
actions: {
refresh() {
@ -14,7 +16,14 @@ export default Ember.Controller.extend({
this.set('loading', true);
this.set('sentEmail', false);
EmailPreview.findDigest(this.get('lastSeen'), this.get('username')).then(email => {
let username = this.get('username');
if (!username) {
username = this.currentUser.get('username');
this.set('username', username);
}
EmailPreview.findDigest(username, this.get('lastSeen')).then(email => {
model.setProperties(email.getProperties('html_content', 'text_content'));
this.set('loading', false);
});
@ -28,16 +37,14 @@ export default Ember.Controller.extend({
this.set('sendingEmail', true);
this.set('sentEmail', false);
const self = this;
EmailPreview.sendDigest(this.get('lastSeen'), this.get('username'), this.get('email')).then(result => {
EmailPreview.sendDigest(this.get('username'), this.get('lastSeen'), this.get('email')).then(result => {
if (result.errors) {
bootbox.alert(result.errors);
} else {
self.set('sentEmail', true);
this.set('sentEmail', true);
}
}).catch(popupAjaxError).finally(function() {
self.set('sendingEmail', false);
}).catch(popupAjaxError).finally(() => {
this.set('sendingEmail', false);
});
}
}

View File

@ -1,42 +1,24 @@
import { ajax } from 'discourse/lib/ajax';
const EmailPreview = Discourse.Model.extend({});
export function oneWeekAgo() {
return moment().locale('en').subtract(7, 'days').format('YYYY-MM-DD');
}
EmailPreview.reopenClass({
findDigest: function(lastSeenAt, username) {
if (Em.isEmpty(lastSeenAt)) {
lastSeenAt = this.oneWeekAgo();
}
if (Em.isEmpty(username)) {
username = Discourse.User.current().username;
}
findDigest(username, lastSeenAt) {
return ajax("/admin/email/preview-digest.json", {
data: { last_seen_at: lastSeenAt, username: username }
}).then(function (result) {
return EmailPreview.create(result);
});
data: { last_seen_at: lastSeenAt || oneWeekAgo(), username }
}).then(result => EmailPreview.create(result));
},
sendDigest: function(lastSeenAt, username, email) {
if (Em.isEmpty(lastSeenAt)) {
lastSeenAt = this.oneWeekAgo();
}
if (Em.isEmpty(username)) {
username = Discourse.User.current().username;
}
sendDigest(username, lastSeenAt, email) {
return ajax("/admin/email/send-digest.json", {
data: { last_seen_at: lastSeenAt, username: username, email: email }
data: { last_seen_at: lastSeenAt || oneWeekAgo(), username, email }
});
},
oneWeekAgo() {
const en = moment().locale('en');
return en.subtract(7, 'days').format('YYYY-MM-DD');
}
});
export default EmailPreview;

View File

@ -1,16 +1,17 @@
import EmailPreview from 'admin/models/email-preview';
import { default as EmailPreview, oneWeekAgo } from 'admin/models/email-preview';
export default Discourse.Route.extend({
model() {
return EmailPreview.findDigest();
return EmailPreview.findDigest(this.currentUser.get('username'));
},
afterModel(model) {
const controller = this.controllerFor('adminEmailPreviewDigest');
controller.setProperties({
model: model,
lastSeen: moment().subtract(7, 'days').format('YYYY-MM-DD'),
model,
username: this.currentUser.get('username'),
lastSeen: oneWeekAgo(),
showHtml: true
});
}

View File

@ -1,11 +1,11 @@
<p>{{i18n 'admin.email.preview_digest_desc'}}</p>
<div class='admin-controls'>
<div class='admin-controls email-preview'>
<div class='span7 controls'>
<label for='last-seen'>{{i18n 'admin.email.last_seen_user'}}</label>
{{date-picker-past value=lastSeen id="last-seen"}}
<label>{{i18n 'admin.email.user'}}:</label>
{{user-selector single="true" usernames=username}}
{{user-selector single="true" usernames=username canReceiveUpdates="true"}}
<button class='btn' {{action "refresh"}}>{{i18n 'admin.email.refresh'}}</button>
<div class="toggle">
<label>{{i18n 'admin.email.format'}}</label>

View File

@ -2,7 +2,7 @@
import loadScript from "discourse/lib/load-script";
import { default as computed, on } from "ember-addons/ember-computed-decorators";
export default Em.Component.extend({
export default Ember.Component.extend({
classNames: ["date-picker-wrapper"],
_picker: null,

View File

@ -1 +1 @@
{{input type="text" class="date-picker" placeholder=placeholder}}
{{input type="text" class="date-picker" placeholder=placeholder value=value}}

View File

@ -316,6 +316,17 @@ td.flaggers td {
}
}
.email-preview {
.ac-wrap {
.item {
margin: 0.2em 0 0 0.4em;
}
// input[type=text] {
// margin-left: 0.4em;
// }
}
}
.paste-users {
width: 400px;
height: 150px;