mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-26 20:34:02 +03:00
fa84808048
no issue Since `ember-moment@10.0` it's not been necessary to use the `ember-cli-moment-shim` package, with `moment` instead being usable directly via `ember-auto-import`. Getting rid of the shim package is necessary for compatibility with `embroider`, Ember's new build tooling. - dropped `ember-cli-moment-shim` dependency - added `moment-timezone` dependency and updated all imports to reflect the different package - worked around `ember-power-calendar` having `ember-cli-moment-shim` as a sub-dependency - added empty in-repo-addon `ember-power-calendar-moment` to avoid `ember-power-calendar` complaining about a missing package - added `ember-power-calendar-utils` in-repo-addon that is a copy of `ember-power-calendar-moment` but without the build-time renaming of the tree for better compatibility with embroider
72 lines
2.1 KiB
JavaScript
72 lines
2.1 KiB
JavaScript
import Component from '@ember/component';
|
|
import classic from 'ember-classic-decorator';
|
|
import moment from 'moment-timezone';
|
|
import {action, computed} from '@ember/object';
|
|
import {classNames} from '@ember-decorators/component';
|
|
import {mapBy} from '@ember/object/computed';
|
|
import {inject as service} from '@ember/service';
|
|
|
|
@classic
|
|
@classNames('form-group', 'for-select')
|
|
export default class GhTimezoneSelect extends Component {
|
|
@service clock;
|
|
|
|
timezone = null;
|
|
availableTimezones = null;
|
|
|
|
// Allowed actions
|
|
update = () => {};
|
|
|
|
@mapBy('availableTimezones', 'name')
|
|
availableTimezoneNames;
|
|
|
|
@computed('timezone', 'availableTimezoneNames')
|
|
get hasTimezoneOverride() {
|
|
let timezone = this.timezone;
|
|
let availableTimezoneNames = this.availableTimezoneNames;
|
|
|
|
return !availableTimezoneNames.includes(timezone);
|
|
}
|
|
|
|
@computed('timezone', 'availableTimezones', 'hasTimezoneOverride')
|
|
get selectedTimezone() {
|
|
let hasTimezoneOverride = this.hasTimezoneOverride;
|
|
let timezone = this.timezone;
|
|
let availableTimezones = this.availableTimezones;
|
|
|
|
if (hasTimezoneOverride) {
|
|
return {name: '', label: ''};
|
|
}
|
|
|
|
return availableTimezones
|
|
.filterBy('name', timezone)
|
|
.get('firstObject');
|
|
}
|
|
|
|
@computed('availableTimezones', 'hasTimezoneOverride')
|
|
get selectableTimezones() {
|
|
let hasTimezoneOverride = this.hasTimezoneOverride;
|
|
let availableTimezones = this.availableTimezones;
|
|
|
|
if (hasTimezoneOverride) {
|
|
return [{name: '', label: ''}, ...availableTimezones];
|
|
}
|
|
|
|
return availableTimezones;
|
|
}
|
|
|
|
@computed('hasTimezoneOverride', 'timezone', 'selectedTimezone', 'clock.second')
|
|
get localTime() {
|
|
let hasTimezoneOverride = this.hasTimezoneOverride;
|
|
let timezone = hasTimezoneOverride ? this.timezone : this.get('selectedTimezone.name');
|
|
|
|
this.get('clock.second');
|
|
return timezone ? moment().tz(timezone).format('HH:mm:ss') : moment().utc().format('HH:mm:ss');
|
|
}
|
|
|
|
@action
|
|
setTimezone(timezone) {
|
|
this.update(timezone);
|
|
}
|
|
}
|