From 4339a3a9610c38e6dcd7f814ac3be0cd692e2bfc Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Sun, 26 Jul 2020 01:26:34 +0300 Subject: [PATCH] Add input for new type `['atom', 'boolean']` --- src/store/modules/normalizers.js | 9 +++- src/views/settings/components/Inputs.vue | 5 ++- .../inputComponents/LinkFormatterInput.vue | 43 ++++++++++++++----- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/store/modules/normalizers.js b/src/store/modules/normalizers.js index 8991353a..00a5968b 100644 --- a/src/store/modules/normalizers.js +++ b/src/store/modules/normalizers.js @@ -28,7 +28,7 @@ const getCurrentValue = (type, value, path) => { } const getValueWithoutKey = (key, [type, value]) => { - if (type === 'atom' && value.length > 1) { + if (prependWithСolon(type, value)) { return `:${value}` } else if (key === ':backends') { const index = value.findIndex(el => el === ':ex_syslogger') @@ -132,6 +132,11 @@ const parseProxyUrl = value => { return { socks5: false, host: null, port: null } } +const prependWithСolon = (type, value) => { + return (type === 'atom' && value.length > 0) || + (Array.isArray(type) && type.includes('atom') && typeof value === 'string') +} + export const processNested = (valueForState, valueForUpdatedSettings, group, parentKey, parents, settings, updatedSettings) => { const [{ key, type }, ...otherParents] = parents const path = [group, parentKey, ...parents.reverse().map(parent => parent.key).slice(0, -1)] @@ -216,7 +221,7 @@ const wrapValues = (settings, currentState) => { setting === ':replace' ) { return { 'tuple': [setting, wrapValues(value, currentState)] } - } else if (type === 'atom' && value.length > 0) { + } else if (prependWithСolon(type, value)) { return { 'tuple': [setting, `:${value}`] } } else if (type.includes('tuple') && (type.includes('string') || type.includes('atom'))) { return typeof value === 'string' diff --git a/src/views/settings/components/Inputs.vue b/src/views/settings/components/Inputs.vue index a1dd2216..8bbd8121 100644 --- a/src/views/settings/components/Inputs.vue +++ b/src/views/settings/components/Inputs.vue @@ -105,7 +105,7 @@ - + @@ -216,6 +216,9 @@ export default { } }, computed: { + booleanCombinedInput() { + return Array.isArray(this.setting.type) && this.setting.type.includes('boolean') + }, canBeDeleted() { const { group, key } = this.settingGroup return _.get(this.$store.state.settings.db, [group, key]) && diff --git a/src/views/settings/components/inputComponents/LinkFormatterInput.vue b/src/views/settings/components/inputComponents/LinkFormatterInput.vue index fd3a24b5..38ec2e50 100644 --- a/src/views/settings/components/inputComponents/LinkFormatterInput.vue +++ b/src/views/settings/components/inputComponents/LinkFormatterInput.vue @@ -1,12 +1,27 @@ @@ -34,19 +49,25 @@ export default { } } }, - methods: { - autoLinkerBooleanValue(key) { + computed: { + autoLinkerAtomValue() { + return this.data[this.setting.key] && + this.data[this.setting.key][0] === ':' ? this.data[this.setting.key].substr(1) : this.data[this.setting.key] + }, + autoLinkerBooleanValue() { const value = this.data[this.setting.key] return typeof value === 'string' || typeof value === 'number' }, - autoLinkerIntegerValue(key) { + autoLinkerIntegerValue() { const value = this.data[this.setting.key] return value || 0 }, - autoLinkerStringValue(key) { + autoLinkerStringValue() { const value = this.data[this.setting.key] return value || '' - }, + } + }, + methods: { processTwoTypeValue(value, input) { if (value === true) { const data = input === ':truncate' ? 0 : ''