2021-07-09 00:44:52 +03:00
|
|
|
import Component from '@glimmer/component';
|
2017-05-29 21:50:03 +03:00
|
|
|
import moment from 'moment';
|
2021-07-09 00:44:52 +03:00
|
|
|
import {action} from '@ember/object';
|
2017-10-30 12:38:01 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2021-07-09 00:44:52 +03:00
|
|
|
import {tracked} from '@glimmer/tracking';
|
2017-04-11 16:39:45 +03:00
|
|
|
|
2021-07-09 00:44:52 +03:00
|
|
|
export default class GhPublishmenuScheduledComponent extends Component {
|
|
|
|
@service clock;
|
|
|
|
@service session;
|
|
|
|
@service feature;
|
|
|
|
@service settings;
|
|
|
|
@service config;
|
2017-04-11 16:39:45 +03:00
|
|
|
|
|
|
|
// used to set minDate in datepicker
|
2021-07-09 00:44:52 +03:00
|
|
|
@tracked minDate = null;
|
2017-04-11 16:39:45 +03:00
|
|
|
|
2021-07-09 00:44:52 +03:00
|
|
|
get timeToPublished() {
|
|
|
|
let publishedAtUTC = this.args.post.publishedAtUTC;
|
2017-04-11 16:39:45 +03:00
|
|
|
|
2017-05-22 19:03:04 +03:00
|
|
|
if (!publishedAtUTC) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-07-09 00:44:52 +03:00
|
|
|
this.clock.get('second');
|
2017-04-11 16:39:45 +03:00
|
|
|
|
|
|
|
return publishedAtUTC.toNow(true);
|
2021-07-09 00:44:52 +03:00
|
|
|
}
|
2017-04-11 16:39:45 +03:00
|
|
|
|
2022-04-27 12:49:55 +03:00
|
|
|
get selectedNewsletter() {
|
2022-05-10 13:16:38 +03:00
|
|
|
return this.args.availableNewsletters.find(n => n.id === this.args.post.newsletter?.id);
|
2022-04-27 12:49:55 +03:00
|
|
|
}
|
|
|
|
|
2021-07-09 00:44:52 +03:00
|
|
|
constructor() {
|
|
|
|
super(...arguments);
|
|
|
|
this.minDate = new Date();
|
|
|
|
}
|
2017-04-11 16:39:45 +03:00
|
|
|
|
2021-07-09 00:44:52 +03:00
|
|
|
@action
|
|
|
|
setSaveType(type) {
|
2021-10-11 12:30:12 +03:00
|
|
|
if (this.args.saveType !== type) {
|
2021-07-09 00:44:52 +03:00
|
|
|
this.minDate = new Date();
|
|
|
|
this.args.setSaveType(type);
|
|
|
|
|
|
|
|
// when draft switch to now to avoid validation errors
|
|
|
|
// when schedule switch back to saved date to avoid unnecessary re-scheduling
|
|
|
|
if (type === 'draft') {
|
|
|
|
this.args.post.set('publishedAtBlogTZ', new Date());
|
|
|
|
} else {
|
|
|
|
this.args.post.set('publishedAtBlogTZ', this.args.post.publishedAtUTC);
|
2017-04-11 16:39:45 +03:00
|
|
|
}
|
|
|
|
|
2021-07-09 00:44:52 +03:00
|
|
|
this.args.post.validate();
|
|
|
|
}
|
|
|
|
}
|
2017-04-11 16:39:45 +03:00
|
|
|
|
2021-07-09 00:44:52 +03:00
|
|
|
@action
|
|
|
|
setDate(date) {
|
|
|
|
let post = this.args.post;
|
|
|
|
let dateString = moment(date).format('YYYY-MM-DD');
|
|
|
|
|
|
|
|
post.set('publishedAtBlogDate', dateString);
|
|
|
|
return post.validate();
|
|
|
|
}
|
2017-04-11 16:39:45 +03:00
|
|
|
|
2021-07-09 00:44:52 +03:00
|
|
|
@action
|
|
|
|
setTime(time) {
|
|
|
|
let post = this.args.post;
|
2017-04-11 16:39:45 +03:00
|
|
|
|
2021-07-09 00:44:52 +03:00
|
|
|
if (!this.args.isClosing) {
|
|
|
|
post.set('publishedAtBlogTime', time);
|
|
|
|
return post.validate();
|
2017-04-11 16:39:45 +03:00
|
|
|
}
|
|
|
|
}
|
2021-07-09 00:44:52 +03:00
|
|
|
}
|