mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-26 04:13:30 +03:00
f07940f0e7
no issue - find+replace to make service injection style consistent and take up much less space at the top of files that used multi-line syntax
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';
|
|
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);
|
|
}
|
|
}
|