From f8e791cffc17d9b5c913c21de84e00115647591e Mon Sep 17 00:00:00 2001 From: Nicolas Pennec Date: Tue, 16 Jul 2024 09:44:13 +0200 Subject: [PATCH] [settings] fix the handling of booleans in the Settings form --- src/components/lists/TimesheetList.vue | 3 +- src/components/pages/Edit.vue | 4 +-- src/components/pages/Settings.vue | 8 ++++- .../pages/playlists/PlaylistPlayer.vue | 4 +-- src/components/previews/PreviewPlayer.vue | 4 +-- src/lib/auth.js | 8 ----- src/store/api/people.js | 29 ++++--------------- src/store/modules/people.js | 9 +++--- 8 files changed, 21 insertions(+), 48 deletions(-) diff --git a/src/components/lists/TimesheetList.vue b/src/components/lists/TimesheetList.vue index 563b3469a7..c76318d38f 100644 --- a/src/components/lists/TimesheetList.vue +++ b/src/components/lists/TimesheetList.vue @@ -311,8 +311,7 @@ export default { 'px' this.disabledDates = { to: - this.isCurrentUserArtist && - this.organisation.timesheets_locked === 'true' + this.isCurrentUserArtist && this.organisation.timesheets_locked ? moment().subtract(1, 'weeks').toDate() // Disable dates older than one week : undefined, from: moment().toDate() // Disable dates after today diff --git a/src/components/pages/Edit.vue b/src/components/pages/Edit.vue index 9b55c1862e..c1b99c40e6 100644 --- a/src/components/pages/Edit.vue +++ b/src/components/pages/Edit.vue @@ -686,9 +686,7 @@ export default { this.$on('annotation-changed', this.onAnnotationChanged) this.$options.scrubbing = false - this.isHd = this.organisation - ? this.organisation.hd_by_default === 'true' - : false + this.isHd = Boolean(this.organisation.hd_by_default) if (this.picturePlayer) { this.picturePlayer.addEventListener('load', async () => { const wasPlaying = this.isPlaying diff --git a/src/components/pages/Settings.vue b/src/components/pages/Settings.vue index d17717a684..6eaf12795b 100644 --- a/src/components/pages/Settings.vue +++ b/src/components/pages/Settings.vue @@ -200,7 +200,13 @@ export default { if (this.checkWebhook()) { this.loading.save = true this.errors.save = false - this.saveOrganisation(this.form) + const organisation = { + ...this.form, + hd_by_default: this.form.hd_by_default === 'true', + timesheets_locked: this.form.timesheets_locked === 'true', + use_original_file_name: this.form.use_original_file_name === 'true' + } + this.saveOrganisation(organisation) .catch(err => { console.error(err) this.errors.save = true diff --git a/src/components/pages/playlists/PlaylistPlayer.vue b/src/components/pages/playlists/PlaylistPlayer.vue index 198780743e..e49ea518f3 100644 --- a/src/components/pages/playlists/PlaylistPlayer.vue +++ b/src/components/pages/playlists/PlaylistPlayer.vue @@ -1064,9 +1064,7 @@ export default { mounted() { this.$options.scrubbing = false - this.isHd = this.organisation - ? this.organisation.hd_by_default === 'true' - : false + this.isHd = Boolean(this.organisation.hd_by_default) if (this.entities) { this.entityList = Object.values(this.entities) } else { diff --git a/src/components/previews/PreviewPlayer.vue b/src/components/previews/PreviewPlayer.vue index 99d4b0b7a8..e1f8fc60a3 100644 --- a/src/components/previews/PreviewPlayer.vue +++ b/src/components/previews/PreviewPlayer.vue @@ -1058,9 +1058,7 @@ export default { const isMuted = localPreferences.getBoolPreference('player:muted') this.isRepeating = isRepeating this.isMuted = isMuted - this.isHd = this.organisation - ? this.organisation.hd_by_default === 'true' - : false + this.isHd = Boolean(this.organisation.hd_by_default) }, focus() { diff --git a/src/lib/auth.js b/src/lib/auth.js index 220ac519d2..8f7cc390b5 100644 --- a/src/lib/auth.js +++ b/src/lib/auth.js @@ -100,14 +100,6 @@ const auth = { } else { const user = res.body.user const organisation = res.body.organisation || {} - organisation.use_original_file_name = - organisation.use_original_file_name ? 'true' : 'false' - organisation.timesheets_locked = organisation.timesheets_locked - ? 'true' - : 'false' - organisation.hd_by_default = organisation.hd_by_default - ? 'true' - : 'false' store.commit(SET_ORGANISATION, organisation) store.commit(USER_LOGIN, user) callback(null) diff --git a/src/store/api/people.js b/src/store/api/people.js index 350979f702..0dbe8b6ad1 100644 --- a/src/store/api/people.js +++ b/src/store/api/people.js @@ -2,36 +2,17 @@ import client from '@/store/api/client' import { buildQueryString } from '@/lib/query' export default { - getOrganisation() { - return client.pget('/api/data/organisations').then(organisations => { - let organisation = { - name: 'Kitsu', - hours_by_day: 8, - has_avatar: false, - use_original_file_name: false, - timesheets_locked: false, - chat_token_slack: '', - chat_webhook_mattermost: '', - chat_token_discord: '' - } - if (organisations.length > 0) organisation = organisations[0] - organisation.use_original_file_name = organisation.use_original_file_name - ? 'true' - : 'false' - organisation.timesheets_locked = organisation.timesheets_locked - ? 'true' - : 'false' - Promise.resolve(organisation) - }) + getOrganisations() { + return client.pget('/api/data/organisations') }, updateOrganisation(organisation) { const data = { name: organisation.name, hours_by_day: organisation.hours_by_day, - timesheets_locked: organisation.timesheets_locked === 'true', - use_original_file_name: organisation.use_original_file_name === 'true', - hd_by_default: organisation.hd_by_default === 'true', + timesheets_locked: organisation.timesheets_locked, + use_original_file_name: organisation.use_original_file_name, + hd_by_default: organisation.hd_by_default, chat_token_slack: organisation.chat_token_slack, chat_webhook_mattermost: organisation.chat_webhook_mattermost, chat_token_discord: organisation.chat_token_discord, diff --git a/src/store/modules/people.js b/src/store/modules/people.js index 3026d83e17..3838530965 100644 --- a/src/store/modules/people.js +++ b/src/store/modules/people.js @@ -116,8 +116,9 @@ const initialState = { name: 'Kitsu', hours_by_day: 8, has_avatar: false, - use_original_file_name: 'false', - timesheets_locked: 'false' + hd_by_default: false, + timesheets_locked: false, + use_original_file_name: false }, people: [], @@ -218,8 +219,8 @@ const getters = { const actions = { async getOrganisation({ commit }) { - const organisation = await peopleApi.getOrganisation() - commit(SET_ORGANISATION, organisation) + const organisations = await peopleApi.getOrganisations() + commit(SET_ORGANISATION, organisations[0]) }, async saveOrganisation({ commit }, form) {