2017-08-22 10:53:26 +03:00
|
|
|
import Component from '@ember/component';
|
2022-02-01 12:34:03 +03:00
|
|
|
import classic from 'ember-classic-decorator';
|
2017-04-05 20:45:35 +03:00
|
|
|
import moment from 'moment';
|
2022-02-01 12:34:03 +03:00
|
|
|
import {action, computed} from '@ember/object';
|
|
|
|
import {classNames} from '@ember-decorators/component';
|
2017-08-22 10:53:26 +03:00
|
|
|
import {mapBy} from '@ember/object/computed';
|
2017-10-30 12:38:01 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2016-07-26 13:24:37 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@classic
|
|
|
|
@classNames('form-group', 'for-select')
|
|
|
|
export default class GhTimezoneSelect extends Component {
|
2022-02-01 20:03:45 +03:00
|
|
|
@service clock;
|
2018-01-11 20:43:23 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
timezone = null;
|
|
|
|
availableTimezones = null;
|
2016-07-26 13:24:37 +03:00
|
|
|
|
2018-03-20 17:57:59 +03:00
|
|
|
// Allowed actions
|
2022-02-01 12:34:03 +03:00
|
|
|
update = () => {};
|
2018-03-20 17:57:59 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@mapBy('availableTimezones', 'name')
|
|
|
|
availableTimezoneNames;
|
2016-07-26 13:24:37 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@computed('timezone', 'availableTimezoneNames')
|
|
|
|
get hasTimezoneOverride() {
|
2020-06-24 17:34:59 +03:00
|
|
|
let timezone = this.timezone;
|
2019-03-06 16:53:54 +03:00
|
|
|
let availableTimezoneNames = this.availableTimezoneNames;
|
2016-07-26 13:24:37 +03:00
|
|
|
|
2020-06-24 17:34:59 +03:00
|
|
|
return !availableTimezoneNames.includes(timezone);
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2016-07-26 13:24:37 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@computed('timezone', 'availableTimezones', 'hasTimezoneOverride')
|
|
|
|
get selectedTimezone() {
|
2019-03-06 16:53:54 +03:00
|
|
|
let hasTimezoneOverride = this.hasTimezoneOverride;
|
2020-06-24 17:34:59 +03:00
|
|
|
let timezone = this.timezone;
|
2019-03-06 16:53:54 +03:00
|
|
|
let availableTimezones = this.availableTimezones;
|
2016-07-26 13:24:37 +03:00
|
|
|
|
|
|
|
if (hasTimezoneOverride) {
|
|
|
|
return {name: '', label: ''};
|
|
|
|
}
|
|
|
|
|
|
|
|
return availableTimezones
|
2020-06-24 17:34:59 +03:00
|
|
|
.filterBy('name', timezone)
|
2016-07-26 13:24:37 +03:00
|
|
|
.get('firstObject');
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2016-07-26 13:24:37 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@computed('availableTimezones', 'hasTimezoneOverride')
|
|
|
|
get selectableTimezones() {
|
2019-03-06 16:53:54 +03:00
|
|
|
let hasTimezoneOverride = this.hasTimezoneOverride;
|
|
|
|
let availableTimezones = this.availableTimezones;
|
2016-07-26 13:24:37 +03:00
|
|
|
|
|
|
|
if (hasTimezoneOverride) {
|
|
|
|
return [{name: '', label: ''}, ...availableTimezones];
|
|
|
|
}
|
|
|
|
|
|
|
|
return availableTimezones;
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2016-07-26 13:24:37 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@computed('hasTimezoneOverride', 'timezone', 'selectedTimezone', 'clock.second')
|
|
|
|
get localTime() {
|
2019-03-06 16:53:54 +03:00
|
|
|
let hasTimezoneOverride = this.hasTimezoneOverride;
|
2020-06-24 17:34:59 +03:00
|
|
|
let timezone = hasTimezoneOverride ? this.timezone : this.get('selectedTimezone.name');
|
2016-07-26 13:24:37 +03:00
|
|
|
|
|
|
|
this.get('clock.second');
|
|
|
|
return timezone ? moment().tz(timezone).format('HH:mm:ss') : moment().utc().format('HH:mm:ss');
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2016-07-26 13:24:37 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@action
|
|
|
|
setTimezone(timezone) {
|
|
|
|
this.update(timezone);
|
2016-07-26 13:24:37 +03:00
|
|
|
}
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|