1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00
Ghost-Admin/app/components/gh-date-time-picker.js
Kevin Ansfield 7eefbba69f 💄🐷 sort-imports eslint rule (#712)
no issue

- adds `eslint-plugin-sort-imports-es6-autofix` dependency
  - implements ESLint's base `sort-imports` rule but has a distinction in that `import {foo} from 'bar';` is considered `multiple` rather than `single`
  - fixes ESLint's autofix behaviour so `eslint --fix` will actually fix the sort order
- updates all unordered import rules by using `eslint --fix`

With the increased number of `import` statements since Ember+ecosystem started moving towards es6 modules I've found it frustrating at times trying to search through randomly ordered import statements. Recently I've been sorting imports manually when I've added new code or touched old code so I thought I'd add an ESLint rule to codify it.
2017-05-29 20:50:03 +02:00

111 lines
3.3 KiB
JavaScript

import Component from 'ember-component';
import computed, {or, reads} from 'ember-computed';
import injectService from 'ember-service/inject';
import moment from 'moment';
import {isBlank, isEmpty} from 'ember-utils';
export default Component.extend({
settings: injectService(),
tagName: '',
date: '',
time: '',
errors: null,
dateErrorProperty: null,
timeErrorProperty: null,
_time: '',
_previousTime: '',
_minDate: null,
_maxDate: null,
blogTimezone: reads('settings.activeTimezone'),
hasError: or('dateError', 'timeError'),
timezone: computed('blogTimezone', function () {
let blogTimezone = this.get('blogTimezone');
return moment.utc().tz(blogTimezone).format('z');
}),
dateError: computed('errors.[]', 'dateErrorProperty', function () {
let errors = this.get('errors');
let property = this.get('dateErrorProperty');
if (!isEmpty(errors.errorsFor(property))) {
return errors.errorsFor(property).get('firstObject').message;
}
}),
timeError: computed('errors.[]', 'timeErrorProperty', function () {
let errors = this.get('errors');
let property = this.get('timeErrorProperty');
if (!isEmpty(errors.errorsFor(property))) {
return errors.errorsFor(property).get('firstObject').message;
}
}),
didReceiveAttrs() {
let date = this.get('date');
let time = this.get('time');
let minDate = this.get('minDate');
let maxDate = this.get('maxDate');
let blogTimezone = this.get('blogTimezone');
if (!isBlank(date)) {
this.set('_date', moment(date));
} else {
this.set('_date', moment().tz(blogTimezone));
}
if (isBlank(time)) {
this.set('_time', this.get('_date').format('HH:mm'));
} else {
this.set('_time', this.get('time'));
}
this.set('_previousTime', this.get('_time'));
// unless min/max date is at midnight moment will diable that day
if (minDate === 'now') {
this.set('_minDate', moment(moment().format('YYYY-MM-DD')));
} else if (!isBlank(minDate)) {
this.set('_minDate', moment(moment(minDate).format('YYYY-MM-DD')));
} else {
this.set('_minDate', null);
}
if (maxDate === 'now') {
this.set('_maxDate', moment(moment().format('YYYY-MM-DD')));
} else if (!isBlank(maxDate)) {
this.set('_maxDate', moment(moment(maxDate).format('YYYY-MM-DD')));
} else {
this.set('_maxDate', null);
}
},
actions: {
// if date or time is set and the other property is blank set that too
// so that we don't get "can't be blank" errors
setDate(date) {
if (date !== this.get('_date')) {
this.get('setDate')(date);
if (isBlank(this.get('time'))) {
this.get('setTime')(this.get('_time'));
}
}
},
setTime(time) {
if (time !== this.get('_previousTime')) {
this.get('setTime')(time);
this.set('_previousTime', time);
if (isBlank(this.get('date'))) {
this.get('setDate')(this.get('_date'));
}
}
}
}
});