mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-29 07:09:48 +03:00
107ed0e1f3
refs https://github.com/TryGhost/Team/issues/947 - With email-only posts there's a new "send" status that deserved it's own publishing action in the post publish menu. With with addition the post ended up having few more publishing states: publish, send, and publish&send. In addition to all this there's a "schedule" option. An addition of the "send" only select option there became a need to persist the "email_only" flag when the option was changed in the publish menu. Such persistance was not done before from the publishing menu and led a whole chain of additional methods being passed down from publishmenu component all the way down to distribution-action-select component - At this moment only a happy path work properly when selecting one of the publishing options and publishing. More states will need to be handled for scheduled, unblished, etc. states of the post
114 lines
3.5 KiB
JavaScript
114 lines
3.5 KiB
JavaScript
import Component from '@glimmer/component';
|
|
import moment from 'moment';
|
|
import {action} from '@ember/object';
|
|
import {isEmpty} from '@ember/utils';
|
|
import {inject as service} from '@ember/service';
|
|
import {task} from 'ember-concurrency-decorators';
|
|
import {tracked} from '@glimmer/tracking';
|
|
|
|
export default class GhPublishMenuDraftComponent extends Component {
|
|
@service config;
|
|
@service feature;
|
|
@service session;
|
|
@service settings;
|
|
@service store;
|
|
|
|
@tracked totalMemberCount = 0;
|
|
|
|
// used to set minDate in datepicker
|
|
_minDate = null;
|
|
_publishedAtBlogTZ = null;
|
|
|
|
get disableEmailOption() {
|
|
// TODO: remove owner or admin check when editors can count members
|
|
return this.session.user.isAdmin && (this.totalMemberCount === 0 || this.countTotalMembersTask.isRunning);
|
|
}
|
|
|
|
get nextActionName() {
|
|
return this.args.post.emailOnly ? 'send' : 'publish';
|
|
}
|
|
|
|
get showEmailSection() {
|
|
return this.args.canSendEmail && this.args.post.emailRecipientFilter !== 'none';
|
|
}
|
|
|
|
get showEmailOnlyInput() {
|
|
return this.feature.emailOnlyPosts && this.args.post.isPost;
|
|
}
|
|
|
|
constructor() {
|
|
super(...arguments);
|
|
this.args.post.set('publishedAtBlogTZ', this.args.post.publishedAtUTC);
|
|
}
|
|
|
|
@action
|
|
setSaveType(type) {
|
|
if (this.args.saveType !== type) {
|
|
let hasDateError = !isEmpty(this.args.post.errors.errorsFor('publishedAtBlogDate'));
|
|
let hasTimeError = !isEmpty(this.args.post.errors.errorsFor('publishedAtBlogTime'));
|
|
let minDate = this._getMinDate();
|
|
|
|
this._minDate = minDate;
|
|
this.args.setSaveType(type);
|
|
|
|
// when publish: switch to now to avoid validation errors
|
|
// when schedule: switch to last valid or new minimum scheduled date
|
|
if (type === 'publish') {
|
|
if (!hasDateError && !hasTimeError) {
|
|
this._publishedAtBlogTZ = this.args.post.publishedAtBlogTZ;
|
|
} else {
|
|
this._publishedAtBlogTZ = this.args.post.publishedAtUTC;
|
|
}
|
|
|
|
this.args.post.set('publishedAtBlogTZ', this.args.post.publishedAtUTC);
|
|
} else {
|
|
if (!this._publishedAtBlogTZ || moment(this._publishedAtBlogTZ).isBefore(minDate)) {
|
|
this.args.post.set('publishedAtBlogTZ', minDate);
|
|
} else {
|
|
this.args.post.set('publishedAtBlogTZ', this._publishedAtBlogTZ);
|
|
}
|
|
}
|
|
|
|
this.args.post.validate();
|
|
}
|
|
}
|
|
|
|
@action
|
|
setDistributionAction(type) {
|
|
this.args.setDistributionAction(type);
|
|
}
|
|
|
|
@action
|
|
setDate(date) {
|
|
let post = this.args.post;
|
|
let dateString = moment(date).format('YYYY-MM-DD');
|
|
|
|
post.set('publishedAtBlogDate', dateString);
|
|
return post.validate();
|
|
}
|
|
|
|
@action
|
|
setTime(time) {
|
|
let post = this.args.post;
|
|
|
|
post.set('publishedAtBlogTime', time);
|
|
return post.validate();
|
|
}
|
|
|
|
@task
|
|
*countTotalMembersTask() {
|
|
const user = yield this.session.user;
|
|
|
|
if (user.isAdmin) {
|
|
const result = yield this.store.query('member', {limit: 1, filter: 'subscribed:true'});
|
|
this.totalMemberCount = result.meta.pagination.total;
|
|
}
|
|
}
|
|
|
|
// API only accepts dates at least 2 mins in the future, default the
|
|
// scheduled date 5 mins in the future to avoid immediate validation errors
|
|
_getMinDate() {
|
|
return moment.utc().add(5, 'minutes');
|
|
}
|
|
}
|