Add input for settings with type tuple and boolean, wrapping and parsing these settings

This commit is contained in:
Angelina Filippova 2020-12-08 22:22:27 +03:00
parent add720534d
commit f50e787fa9
3 changed files with 64 additions and 20 deletions

View file

@ -57,10 +57,18 @@ export const parseNonTuples = (key, value) => {
// REFACTOR // REFACTOR
export const parseTuples = (tuples, key) => { export const parseTuples = (tuples, key) => {
return tuples.reduce((accum, item) => { return tuples.reduce((accum, item) => {
if (key === ':rate_limit') { if (key === ':rate_limit' ||
accum[item.tuple[0]] = Array.isArray(item.tuple[1]) (key === 'Pleroma.Web.Endpoint.MetricsExporter' && item.tuple[0] === ':auth')) {
? item.tuple[1].map(el => el.tuple) const getValue = () => {
: item.tuple[1].tuple if (typeof item.tuple[1] === 'boolean') {
return item.tuple[1]
} else if (Array.isArray(item.tuple[1])) {
return item.tuple[1].map(el => el.tuple)
} else {
return item.tuple[1].tuple
}
}
accum[item.tuple[0]] = getValue()
} else if (item.tuple[0] === ':mascots') { } else if (item.tuple[0] === ':mascots') {
accum[item.tuple[0]] = item.tuple[1].reduce((acc, mascot) => { accum[item.tuple[0]] = item.tuple[1].reduce((acc, mascot) => {
return [...acc, { [mascot.tuple[0]]: { ...mascot.tuple[1], id: `f${(~~(Math.random() * 1e8)).toString(16)}` }}] return [...acc, { [mascot.tuple[0]]: { ...mascot.tuple[1], id: `f${(~~(Math.random() * 1e8)).toString(16)}` }}]
@ -237,8 +245,9 @@ const wrapValues = (settings, currentState) => {
return { 'tuple': [setting, wrapValues(value, currentState)] } return { 'tuple': [setting, wrapValues(value, currentState)] }
} else if (prependWithСolon(type, value)) { } else if (prependWithСolon(type, value)) {
return { 'tuple': [setting, `:${value}`] } return { 'tuple': [setting, `:${value}`] }
} else if (type.includes('tuple') && (type.includes('string') || type.includes('atom'))) { } else if (type.includes('tuple') &&
return typeof value === 'string' (type.includes('string') || type.includes('atom') || type.includes('boolean'))) {
return typeof value === 'string' || typeof value === 'boolean'
? { 'tuple': [setting, value] } ? { 'tuple': [setting, value] }
: { 'tuple': [setting, { 'tuple': value }] } : { 'tuple': [setting, { 'tuple': value }] }
} else if (type === 'reversed_tuple') { } else if (type === 'reversed_tuple') {

View file

@ -1,28 +1,39 @@
<template> <template>
<div> <div>
<div v-if="setting.type.includes('string')" :data-search="setting.key || setting.group"> <div v-if="setting.type.includes('string')" :data-search="setting.key || setting.group">
<el-switch :value="autoLinkerBooleanValue" @change="processTwoTypeValue($event, setting.key)"/> <el-switch :value="booleanValue" @change="processTwoTypeValue($event, setting.key)"/>
<el-input <el-input
v-if="autoLinkerBooleanValue" v-if="booleanValue"
:value="autoLinkerStringValue" :value="stringValue"
@input="processTwoTypeValue($event, setting.key)"/> @input="processTwoTypeValue($event, setting.key)"/>
</div> </div>
<div v-if="setting.type.includes('integer')" :data-search="setting.key || setting.group"> <div v-if="setting.type.includes('integer')" :data-search="setting.key || setting.group">
<el-switch :value="autoLinkerBooleanValue" @change="processTwoTypeValue($event, setting.key)"/> <el-switch :value="booleanValue" @change="processTwoTypeValue($event, setting.key)"/>
<el-input-number <el-input-number
v-if="autoLinkerBooleanValue" v-if="booleanValue"
:value="autoLinkerIntegerValue" :value="integerValue"
@input="processTwoTypeValue($event, setting.key)"/> @input="processTwoTypeValue($event, setting.key)"/>
</div> </div>
<div v-if="setting.type.includes('atom')" :data-search="setting.key || setting.group"> <div v-if="setting.type.includes('atom')" :data-search="setting.key || setting.group">
<el-switch :value="autoLinkerBooleanValue" @change="processTwoTypeValue($event, setting.key)"/> <el-switch :value="booleanValue" @change="processTwoTypeValue($event, setting.key)"/>
<el-input <el-input
v-if="autoLinkerBooleanValue" v-if="booleanValue"
:value="autoLinkerAtomValue" :value="atomValue"
@input="processTwoTypeValue($event, setting.key)"> @input="processTwoTypeValue($event, setting.key)">
<template slot="prepend">:</template> <template slot="prepend">:</template>
</el-input> </el-input>
</div> </div>
<div v-if="setting.type.includes('tuple')" :data-search="setting.key || setting.group">
<el-switch :value="booleanValue" @change="processTupleTwoTypeValue($event, setting.key)"/>
<div v-if="booleanValue" class="tuple-input-container">
<el-input
v-for="(item, index) in tupleValue"
:value="item"
:key="index"
class="tuple-input"
@input="processTupleTwoTypeValue($event, setting.key, index)"/>
</div>
</div>
</div> </div>
</template> </template>
@ -50,24 +61,39 @@ export default {
} }
}, },
computed: { computed: {
autoLinkerAtomValue() { atomValue() {
return this.data[this.setting.key] && return this.data[this.setting.key] &&
this.data[this.setting.key][0] === ':' ? this.data[this.setting.key].substr(1) : this.data[this.setting.key] this.data[this.setting.key][0] === ':' ? this.data[this.setting.key].substr(1) : this.data[this.setting.key]
}, },
autoLinkerBooleanValue() { booleanValue() {
const value = this.data[this.setting.key] const value = this.data[this.setting.key]
return typeof value === 'string' || typeof value === 'number' return typeof value !== 'boolean'
}, },
autoLinkerIntegerValue() { integerValue() {
const value = this.data[this.setting.key] const value = this.data[this.setting.key]
return value || 0 return value || 0
}, },
autoLinkerStringValue() { stringValue() {
const value = this.data[this.setting.key] const value = this.data[this.setting.key]
return value || '' return value || ''
},
tupleValue() {
const value = this.data[this.setting.key]
return value || ['', '', '']
} }
}, },
methods: { methods: {
processTupleTwoTypeValue(value, input, _index) {
if (value === false) {
this.updateSetting(value, this.settingGroup.group, this.settingGroup.key, input, this.setting.type)
} else if (value === true) {
this.updateSetting(['', '', ''], this.settingGroup.group, this.settingGroup.key, input, this.setting.type)
} else {
const data = [...this.tupleValue]
data[_index] = value
this.updateSetting(data, this.settingGroup.group, this.settingGroup.key, input, this.setting.type)
}
},
processTwoTypeValue(value, input) { processTwoTypeValue(value, input) {
if (value === true) { if (value === true) {
const data = input === ':truncate' ? 0 : '' const data = input === ':truncate' ? 0 : ''

View file

@ -352,6 +352,15 @@
line-height: 20px; line-height: 20px;
margin-right: 15px margin-right: 15px
} }
.tuple-input {
margin-right: 15px;
}
.tuple-input:last-child {
margin-right: 0;
}
.tuple-input-container {
display: flex;
}
.upload-container { .upload-container {
display: flex; display: flex;
align-items: baseline; align-items: baseline;