From 3da8815759604bc6714ba527df2c06a2dfc0dc59 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Wed, 24 Jun 2020 15:34:59 +0100 Subject: [PATCH] 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 --- app/components/gh-date-time-picker.js | 2 +- app/components/gh-timezone-select.hbs | 6 +++--- app/components/gh-timezone-select.js | 18 +++++++++--------- app/controllers/settings/general.js | 2 +- app/helpers/gh-format-post-time.js | 2 +- app/models/post.js | 8 ++++---- app/models/setting.js | 2 +- app/templates/settings/general.hbs | 2 +- mirage/fixtures/settings.js | 2 +- tests/acceptance/editor-test.js | 10 +++++----- tests/acceptance/settings/general-test.js | 10 +++++----- .../components/gh-timezone-select-test.js | 10 +++++----- .../helpers/gh-format-post-time-test.js | 2 +- 13 files changed, 38 insertions(+), 38 deletions(-) diff --git a/app/components/gh-date-time-picker.js b/app/components/gh-date-time-picker.js index 8e1f417d0..06445a0e7 100644 --- a/app/components/gh-date-time-picker.js +++ b/app/components/gh-date-time-picker.js @@ -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 () { diff --git a/app/components/gh-timezone-select.hbs b/app/components/gh-timezone-select.hbs index efc747c4e..84dbc10f2 100644 --- a/app/components/gh-timezone-select.hbs +++ b/app/components/gh-timezone-select.hbs @@ -1,7 +1,7 @@ {{#if this.hasTimezoneOverride}} -

Your timezone has been automatically set to {{this.activeTimezone}}.

+

Your timezone has been automatically set to {{this.timezone}}.

{{/if}}

The local time here is currently {{this.localTime}}

diff --git a/app/components/gh-timezone-select.js b/app/components/gh-timezone-select.js index ff4229069..fa13dcb9d 100644 --- a/app/components/gh-timezone-select.js +++ b/app/components/gh-timezone-select.js @@ -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'); diff --git a/app/controllers/settings/general.js b/app/controllers/settings/general.js index 03310ac7b..0d0153773 100644 --- a/app/controllers/settings/general.js +++ b/app/controllers/settings/general.js @@ -69,7 +69,7 @@ export default Controller.extend({ }, setTimezone(timezone) { - this.set('settings.activeTimezone', timezone.name); + this.set('settings.timezone', timezone.name); }, removeImage(image) { diff --git a/app/helpers/gh-format-post-time.js b/app/helpers/gh-format-post-time.js index e041bc4d5..55e89b438 100644 --- a/app/helpers/gh-format-post-time.js +++ b/app/helpers/gh-format-post-time.js @@ -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); diff --git a/app/models/post.js b/app/models/post.js index 492ee0ba1..781fa98ad 100644 --- a/app/models/post.js +++ b/app/models/post.js @@ -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')); diff --git a/app/models/setting.js b/app/models/setting.js index a46a809f1..6b092e2f0 100644 --- a/app/models/setting.js +++ b/app/models/setting.js @@ -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'), diff --git a/app/templates/settings/general.hbs b/app/templates/settings/general.hbs index 12ee03ae2..55dce4102 100644 --- a/app/templates/settings/general.hbs +++ b/app/templates/settings/general.hbs @@ -62,7 +62,7 @@ {{#liquid-if this.timezoneOpen}}
diff --git a/mirage/fixtures/settings.js b/mirage/fixtures/settings.js index 8f880299d..d2f808ec8 100644 --- a/mirage/fixtures/settings.js +++ b/mirage/fixtures/settings.js @@ -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, diff --git a/tests/acceptance/editor-test.js b/tests/acceptance/editor-test.js index 2f1879a54..2af5f82b4 100644 --- a/tests/acceptance/editor-test.js +++ b/tests/acceptance/editor-test.js @@ -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'); diff --git a/tests/acceptance/settings/general-test.js b/tests/acceptance/settings/general-test.js index e35dc85c5..18b9cbf1c 100644 --- a/tests/acceptance/settings/general-test.js +++ b/tests/acceptance/settings/general-test.js @@ -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 () { diff --git a/tests/integration/components/gh-timezone-select-test.js b/tests/integration/components/gh-timezone-select-test.js index 9365a1b7a..9ee7998d1 100644 --- a/tests/integration/components/gh-timezone-select-test.js +++ b/tests/integration/components/gh-timezone-select-test.js @@ -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'); diff --git a/tests/integration/helpers/gh-format-post-time-test.js b/tests/integration/helpers/gh-format-post-time-test.js index 05edeb948..13cf82f71 100644 --- a/tests/integration/helpers/gh-format-post-time-test.js +++ b/tests/integration/helpers/gh-format-post-time-test.js @@ -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 () {