2017-08-22 10:53:26 +03:00
|
|
|
import Component from '@ember/component';
|
2017-04-05 20:45:35 +03:00
|
|
|
import moment from 'moment';
|
2017-08-22 10:53:26 +03:00
|
|
|
import {computed} from '@ember/object';
|
|
|
|
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
|
|
|
|
|
|
|
export default Component.extend({
|
2018-01-11 20:43:23 +03:00
|
|
|
clock: service(),
|
|
|
|
|
2016-07-26 13:24:37 +03:00
|
|
|
classNames: ['form-group', 'for-select'],
|
|
|
|
|
2020-06-24 17:34:59 +03:00
|
|
|
timezone: null,
|
2016-07-26 13:24:37 +03:00
|
|
|
availableTimezones: null,
|
|
|
|
|
2018-03-20 17:57:59 +03:00
|
|
|
// Allowed actions
|
|
|
|
update: () => {},
|
|
|
|
|
2016-07-26 13:24:37 +03:00
|
|
|
availableTimezoneNames: mapBy('availableTimezones', 'name'),
|
|
|
|
|
2020-06-24 17:34:59 +03:00
|
|
|
hasTimezoneOverride: computed('timezone', 'availableTimezoneNames', function () {
|
|
|
|
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);
|
2016-07-26 13:24:37 +03:00
|
|
|
}),
|
|
|
|
|
2020-06-24 17:34:59 +03:00
|
|
|
selectedTimezone: computed('timezone', 'availableTimezones', 'hasTimezoneOverride', function () {
|
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');
|
|
|
|
}),
|
|
|
|
|
|
|
|
selectableTimezones: computed('availableTimezones', 'hasTimezoneOverride', function () {
|
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;
|
|
|
|
}),
|
|
|
|
|
2020-06-24 17:34:59 +03:00
|
|
|
localTime: computed('hasTimezoneOverride', 'timezone', 'selectedTimezone', 'clock.second', function () {
|
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');
|
|
|
|
}),
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
setTimezone(timezone) {
|
2018-03-20 17:57:59 +03:00
|
|
|
this.update(timezone);
|
2016-07-26 13:24:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|