mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-29 07:09:48 +03:00
8f5e305721
closes https://github.com/TryGhost/Team/issues/738 refs https://github.com/TryGhost/Admin/pull/1972 - when we switched from the segment select back to checkboxes and label select we lost the automatic member counting which meant other parts of the publishing workflow had no counts - fixed subscribed status counts shown in publish menu - added the async count back to the confirm modal, taking full free/paid/specific query into account - added total subscribed member count back to the draft publish menu so the email options can be disabled when no subscribed members exist - fixed missing disabled styling inside `<GhMembersRecipientSelect>`
97 lines
3.3 KiB
JavaScript
97 lines
3.3 KiB
JavaScript
import Component from '@ember/component';
|
|
import moment from 'moment';
|
|
import {computed} from '@ember/object';
|
|
import {isEmpty} from '@ember/utils';
|
|
import {inject as service} from '@ember/service';
|
|
import {task} from 'ember-concurrency';
|
|
|
|
export default Component.extend({
|
|
config: service(),
|
|
feature: service(),
|
|
session: service(),
|
|
settings: service(),
|
|
store: service(),
|
|
|
|
post: null,
|
|
saveType: null,
|
|
|
|
// used to set minDate in datepicker
|
|
_minDate: null,
|
|
_publishedAtBlogTZ: null,
|
|
|
|
'data-test-publishmenu-draft': true,
|
|
|
|
// TODO: remove owner or admin check when editors can count members
|
|
disableEmailOption: computed('totalMemberCount', 'countTotalMembersTask.isRunning', function () {
|
|
return this.get('session.user.isOwnerOrAdmin') && (this.totalMemberCount === 0 || this.countTotalMembersTask.isRunning);
|
|
}),
|
|
|
|
didInsertElement() {
|
|
this.post.set('publishedAtBlogTZ', this.get('post.publishedAtUTC'));
|
|
this.send('setSaveType', 'publish');
|
|
},
|
|
|
|
actions: {
|
|
setSaveType(type) {
|
|
if (this.saveType !== type) {
|
|
let hasDateError = !isEmpty(this.get('post.errors').errorsFor('publishedAtBlogDate'));
|
|
let hasTimeError = !isEmpty(this.get('post.errors').errorsFor('publishedAtBlogTime'));
|
|
let minDate = this._getMinDate();
|
|
|
|
this.set('_minDate', minDate);
|
|
this.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.get('post.publishedAtBlogTZ');
|
|
} else {
|
|
this._publishedAtBlogTZ = this.get('post.publishedAtUTC');
|
|
}
|
|
|
|
this.post.set('publishedAtBlogTZ', this.get('post.publishedAtUTC'));
|
|
} else {
|
|
if (!this._publishedAtBlogTZ || moment(this._publishedAtBlogTZ).isBefore(minDate)) {
|
|
this.post.set('publishedAtBlogTZ', minDate);
|
|
} else {
|
|
this.post.set('publishedAtBlogTZ', this._publishedAtBlogTZ);
|
|
}
|
|
}
|
|
|
|
this.post.validate();
|
|
}
|
|
},
|
|
|
|
setDate(date) {
|
|
let post = this.post;
|
|
let dateString = moment(date).format('YYYY-MM-DD');
|
|
|
|
post.set('publishedAtBlogDate', dateString);
|
|
return post.validate();
|
|
},
|
|
|
|
setTime(time) {
|
|
let post = this.post;
|
|
|
|
post.set('publishedAtBlogTime', time);
|
|
return post.validate();
|
|
}
|
|
},
|
|
|
|
countTotalMembersTask: task(function*() {
|
|
const user = yield this.session.user;
|
|
|
|
if (user.isOwnerOrAdmin) {
|
|
const result = yield this.store.query('member', {limit: 1, filter: 'subscribed:true'});
|
|
this.set('totalMemberCount', result.meta.pagination.total);
|
|
}
|
|
}),
|
|
|
|
// scheduled date 5 mins in the future to avoid immediate validation errors
|
|
_getMinDate() {
|
|
return moment.utc().add(5, 'minutes');
|
|
}
|
|
// API only accepts dates at least 2 mins in the future, default the
|
|
});
|