Renamed activeTimezone setting to timezone

refs https://github.com/TryGhost/Ghost/issues/10318

- API has been updated to still work with `active_timezone` for backwards compatibility but it makes sense for the client to match the underlying settings keys
This commit is contained in:
Kevin Ansfield 2020-06-24 15:34:59 +01:00
parent 99dbcdb3b0
commit fcb9b87884
13 changed files with 38 additions and 38 deletions

View File

@ -30,7 +30,7 @@ export default Component.extend({
// actions
setTypedDateError() {},
blogTimezone: reads('settings.activeTimezone'),
blogTimezone: reads('settings.timezone'),
hasError: or('dateError', 'timeError'),
dateValue: computed('_date', '_scratchDate', function () {

View File

@ -1,7 +1,7 @@
<span class="gh-select" data-select-text="{{this.selectedTimezone.label}}" tabindex="0">
<OneWaySelect
@id="activeTimezone"
@name="general[activeTimezone]"
@id="timezone"
@name="general[timezone]"
@options={{this.selectableTimezones}}
@optionValuePath="name"
@optionLabelPath="label"
@ -11,6 +11,6 @@
{{svg-jar "arrow-down-small"}}
</span>
{{#if this.hasTimezoneOverride}}
<p>Your timezone has been automatically set to {{this.activeTimezone}}.</p>
<p>Your timezone has been automatically set to {{this.timezone}}.</p>
{{/if}}
<p>The local time here is currently {{this.localTime}}</p>

View File

@ -9,7 +9,7 @@ export default Component.extend({
classNames: ['form-group', 'for-select'],
activeTimezone: null,
timezone: null,
availableTimezones: null,
// Allowed actions
@ -17,16 +17,16 @@ export default Component.extend({
availableTimezoneNames: mapBy('availableTimezones', 'name'),
hasTimezoneOverride: computed('activeTimezone', 'availableTimezoneNames', function () {
let activeTimezone = this.activeTimezone;
hasTimezoneOverride: computed('timezone', 'availableTimezoneNames', function () {
let timezone = this.timezone;
let availableTimezoneNames = this.availableTimezoneNames;
return !availableTimezoneNames.includes(activeTimezone);
return !availableTimezoneNames.includes(timezone);
}),
selectedTimezone: computed('activeTimezone', 'availableTimezones', 'hasTimezoneOverride', function () {
selectedTimezone: computed('timezone', 'availableTimezones', 'hasTimezoneOverride', function () {
let hasTimezoneOverride = this.hasTimezoneOverride;
let activeTimezone = this.activeTimezone;
let timezone = this.timezone;
let availableTimezones = this.availableTimezones;
if (hasTimezoneOverride) {
@ -34,7 +34,7 @@ export default Component.extend({
}
return availableTimezones
.filterBy('name', activeTimezone)
.filterBy('name', timezone)
.get('firstObject');
}),
@ -49,9 +49,9 @@ export default Component.extend({
return availableTimezones;
}),
localTime: computed('hasTimezoneOverride', 'activeTimezone', 'selectedTimezone', 'clock.second', function () {
localTime: computed('hasTimezoneOverride', 'timezone', 'selectedTimezone', 'clock.second', function () {
let hasTimezoneOverride = this.hasTimezoneOverride;
let timezone = hasTimezoneOverride ? this.activeTimezone : this.get('selectedTimezone.name');
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');

View File

@ -69,7 +69,7 @@ export default Controller.extend({
},
setTimezone(timezone) {
this.set('settings.activeTimezone', timezone.name);
this.set('settings.timezone', timezone.name);
},
removeImage(image) {

View File

@ -14,7 +14,7 @@ export default Helper.extend({
return moment(timeago).from(moment.utc());
}
let timezone = this.get('settings.activeTimezone');
let timezone = this.get('settings.timezone');
let time = moment.tz(timeago, timezone);
let now = moment.tz(moment.utc(), timezone);

View File

@ -177,7 +177,7 @@ export default Model.extend(Comparable, ValidationEngine, {
}
}),
publishedAtBlogTZ: computed('publishedAtBlogDate', 'publishedAtBlogTime', 'settings.activeTimezone', {
publishedAtBlogTZ: computed('publishedAtBlogDate', 'publishedAtBlogTime', 'settings.timezone', {
get() {
return this._getPublishedAtBlogTZ();
},
@ -192,7 +192,7 @@ export default Model.extend(Comparable, ValidationEngine, {
let publishedAtUTC = this.publishedAtUTC;
let publishedAtBlogDate = this.publishedAtBlogDate;
let publishedAtBlogTime = this.publishedAtBlogTime;
let blogTimezone = this.get('settings.activeTimezone');
let blogTimezone = this.get('settings.timezone');
if (!publishedAtUTC && isBlank(publishedAtBlogDate) && isBlank(publishedAtBlogTime)) {
return null;
@ -226,14 +226,14 @@ export default Model.extend(Comparable, ValidationEngine, {
// TODO: is there a better way to handle this?
// eslint-disable-next-line ghost/ember/no-observers
_setPublishedAtBlogTZ: on('init', observer('publishedAtUTC', 'settings.activeTimezone', function () {
_setPublishedAtBlogTZ: on('init', observer('publishedAtUTC', 'settings.timezone', function () {
let publishedAtUTC = this.publishedAtUTC;
this._setPublishedAtBlogStrings(publishedAtUTC);
})),
_setPublishedAtBlogStrings(momentDate) {
if (momentDate) {
let blogTimezone = this.get('settings.activeTimezone');
let blogTimezone = this.get('settings.timezone');
let publishedAtBlog = moment.tz(momentDate, blogTimezone);
this.set('publishedAtBlogDate', publishedAtBlog.format('YYYY-MM-DD'));

View File

@ -12,7 +12,7 @@ export default Model.extend(ValidationEngine, {
icon: attr('string'),
accentColor: attr('string'),
lang: attr('string'),
activeTimezone: attr('string', {defaultValue: 'Etc/UTC'}),
timezone: attr('string', {defaultValue: 'Etc/UTC'}),
codeinjectionHead: attr('string'),
codeinjectionFoot: attr('string'),
facebook: attr('facebook-url-user'),

View File

@ -62,7 +62,7 @@
{{#liquid-if this.timezoneOpen}}
<div class="gh-setting-content-extended">
<GhTimezoneSelect
@activeTimezone={{this.settings.activeTimezone}}
@timezone={{this.settings.timezone}}
@availableTimezones={{this.availableTimezones}}
@update={{action "setTimezone"}} />
</div>

View File

@ -147,7 +147,7 @@ export default [
id: 19,
created_at: '2015-09-11T09:44:30.810Z',
created_by: 1,
key: 'active_timezone',
key: 'timezone',
group: 'site',
updated_at: '2015-09-23T13:32:49.868Z',
updated_by: 1,

View File

@ -266,17 +266,17 @@ describe('Acceptance: Editor', function () {
expect(currentURL(), 'currentURL for settings')
.to.equal('/settings/general');
expect(find('#activeTimezone option:checked').textContent.trim(), 'default timezone')
expect(find('#timezone option:checked').textContent.trim(), 'default timezone')
.to.equal('(GMT) UTC');
// select a new timezone
find('#activeTimezone option[value="Pacific/Kwajalein"]').selected = true;
find('#timezone option[value="Pacific/Kwajalein"]').selected = true;
await triggerEvent('#activeTimezone', 'change');
await triggerEvent('#timezone', 'change');
// save the settings
await click('.gh-btn.gh-btn-blue');
expect(find('#activeTimezone option:checked').textContent.trim(), 'new timezone after saving')
expect(find('#timezone option:checked').textContent.trim(), 'new timezone after saving')
.to.equal('(GMT +12:00) International Date Line West');
// and now go back to the editor
@ -526,7 +526,7 @@ describe('Acceptance: Editor', function () {
let compareDateString = compareDate.format('YYYY-MM-DD');
let compareTimeString = compareDate.format('HH:mm');
this.server.create('post', {publishedAt: moment.utc().add(4, 'minutes'), status: 'scheduled', authors: [author]});
this.server.create('setting', {activeTimezone: 'Europe/Dublin'});
this.server.create('setting', {timezone: 'Europe/Dublin'});
clock.restore();
await visit('/editor/post/1');

View File

@ -311,13 +311,13 @@ describe('Acceptance: Settings - General', function () {
expect(currentURL(), 'currentURL').to.equal('/settings/general');
expect(findAll('#activeTimezone option').length, 'available timezones').to.equal(66);
expect(find('#activeTimezone option:checked').textContent.trim()).to.equal('(GMT) UTC');
find('#activeTimezone option[value="Africa/Cairo"]').selected = true;
expect(findAll('#timezone option').length, 'available timezones').to.equal(66);
expect(find('#timezone option:checked').textContent.trim()).to.equal('(GMT) UTC');
find('#timezone option[value="Africa/Cairo"]').selected = true;
await triggerEvent('#activeTimezone', 'change');
await triggerEvent('#timezone', 'change');
await click('[data-test-save-button]');
expect(find('#activeTimezone option:checked').textContent.trim()).to.equal('(GMT +2:00) Cairo, Egypt');
expect(find('#timezone option:checked').textContent.trim()).to.equal('(GMT +2:00) Cairo, Egypt');
});
it('handles private blog settings correctly', async function () {

View File

@ -14,13 +14,13 @@ describe('Integration: Component: gh-timezone-select', function () {
{name: 'Etc/UTC', label: '(GMT) UTC'},
{name: 'Pacific/Kwajalein', label: '(GMT +12:00) International Date Line West'}
]);
this.set('activeTimezone', 'Etc/UTC');
this.set('timezone', 'Etc/UTC');
});
it('renders', async function () {
await render(hbs`{{gh-timezone-select
availableTimezones=availableTimezones
activeTimezone=activeTimezone}}`);
timezone=timezone}}`);
expect(this.element, 'top-level elements').to.exist;
expect(findAll('option'), 'number of options').to.have.length(3);
@ -28,11 +28,11 @@ describe('Integration: Component: gh-timezone-select', function () {
});
it('handles an unknown timezone', async function () {
this.set('activeTimezone', 'Europe/London');
this.set('timezone', 'Europe/London');
await render(hbs`{{gh-timezone-select
availableTimezones=availableTimezones
activeTimezone=activeTimezone}}`);
timezone=timezone}}`);
// we have an additional blank option at the top
expect(findAll('option'), 'number of options').to.have.length(4);
@ -48,7 +48,7 @@ describe('Integration: Component: gh-timezone-select', function () {
await render(hbs`{{gh-timezone-select
availableTimezones=availableTimezones
activeTimezone=activeTimezone
timezone=timezone
update=(action update)}}`);
await fillIn('select', 'Pacific/Pago_Pago');

View File

@ -17,7 +17,7 @@ describe('Integration: Helper: gh-format-post-time', function () {
beforeEach(function () {
let settings = this.owner.lookup('service:settings');
settings.content = {};
settings.set('activeTimezone', timezoneForTest);
settings.set('timezone', timezoneForTest);
});
afterEach(function () {