Reduce options and labels for Pleroma authenticator input

This commit is contained in:
Angelina Filippova 2020-04-25 22:07:48 +03:00
parent 09f219c201
commit e488e3f852
2 changed files with 35 additions and 13 deletions

View file

@ -55,7 +55,7 @@
:data-search="setting.key || setting.group" :data-search="setting.key || setting.group"
@change="update($event, settingGroup.group, settingGroup.key, settingParent, setting.key, setting.type, nested)"/> @change="update($event, settingGroup.group, settingGroup.key, settingParent, setting.key, setting.type, nested)"/>
<el-select <el-select
v-if="setting.type === 'module' || (setting.type.includes('atom') && setting.type.includes('dropdown'))" v-if="setting.key !== 'Pleroma.Web.Auth.Authenticator' && (setting.type === 'module' || (setting.type.includes('atom') && setting.type.includes('dropdown')))"
:value="inputValue === false ? 'false' : inputValue" :value="inputValue === false ? 'false' : inputValue"
:data-search="setting.key || setting.group" :data-search="setting.key || setting.group"
clearable clearable
@ -67,7 +67,7 @@
:key="index"/> :key="index"/>
</el-select> </el-select>
<el-select <el-select
v-if="!setting.key === ':rewrite_policy' && renderMultipleSelect(setting.type)" v-if="renderMultipleSelect(setting.type) && setting.key !== ':rewrite_policy'"
:value="inputValue" :value="inputValue"
:data-search="setting.key || setting.group" :data-search="setting.key || setting.group"
multiple multiple
@ -104,7 +104,7 @@
<prune-input v-if="setting.key === ':prune'" :data="data[setting.key]" :setting-group="settingGroup" :setting="setting"/> <prune-input v-if="setting.key === ':prune'" :data="data[setting.key]" :setting-group="settingGroup" :setting="setting"/>
<rate-limit-input v-if="settingGroup.key === ':rate_limit'" :data="data" :setting-group="settingGroup" :setting="setting"/> <rate-limit-input v-if="settingGroup.key === ':rate_limit'" :data="data" :setting-group="settingGroup" :setting="setting"/>
<reg-invites-input v-if="[':registrations_open', ':invites_enabled'].includes(setting.key)" :data="data" :setting-group="settingGroup" :setting="setting"/> <reg-invites-input v-if="[':registrations_open', ':invites_enabled'].includes(setting.key)" :data="data" :setting-group="settingGroup" :setting="setting"/>
<rewrite-policy-input v-if="setting.key === ':rewrite_policy'" :data="data[setting.key]" :setting-group="settingGroup" :setting="setting"/> <rewrite-policy-input v-if="reducedSelects" :data="data" :setting-group="settingGroup" :setting="setting"/>
<!--------------------> <!-------------------->
<el-tooltip v-if="canBeDeleted && isTablet" :content="$t('settings.removeFromDB')" placement="bottom-end" class="delete-setting-button-container"> <el-tooltip v-if="canBeDeleted && isTablet" :content="$t('settings.removeFromDB')" placement="bottom-end" class="delete-setting-button-container">
<el-button icon="el-icon-delete" circle size="mini" class="delete-setting-button" @click="removeSetting"/> <el-button icon="el-icon-delete" circle size="mini" class="delete-setting-button" @click="removeSetting"/>
@ -253,6 +253,9 @@ export default {
keywordData() { keywordData() {
return Array.isArray(this.data) ? this.data : [] return Array.isArray(this.data) ? this.data : []
}, },
reducedSelects() {
return [':rewrite_policy', 'Pleroma.Web.Auth.Authenticator'].includes(this.setting.key)
},
settings() { settings() {
return this.$store.state.settings.settings return this.$store.state.settings.settings
}, },

View file

@ -1,7 +1,7 @@
<template> <template>
<div class="input"> <div class="input">
<el-select <el-select
v-if="isMobile" v-if="renderMultipleSelect(setting.type)"
:value="rewritePolicyValue" :value="rewritePolicyValue"
:data-search="setting.key" :data-search="setting.key"
multiple multiple
@ -11,15 +11,17 @@
<el-option v-for="(option, index) in rewritePolicyOptions(setting.suggestions)" :key="index" :value="option.value" :label="option.label" /> <el-option v-for="(option, index) in rewritePolicyOptions(setting.suggestions)" :key="index" :value="option.value" :label="option.label" />
</el-select> </el-select>
<el-select <el-select
v-else v-if="setting.type === 'module' || (setting.type.includes('atom') && setting.type.includes('dropdown'))"
:value="rewritePolicyValue" :value="data.value"
:data-search="setting.key" :data-search="setting.key || setting.group"
multiple clearable
filterable
allow-create
class="input" class="input"
@change="updateSetting($event, settingGroup.group, settingGroup.key, setting.key, setting.type)"> @change="updateSetting($event, settingGroup.group, settingGroup.key, setting.key, setting.type)">
<el-option v-for="(option, index) in setting.suggestions" :key="index" :value="option"/> <el-option
v-for="(option, index) in authenticatorOptions(setting.suggestions)"
:value="option.value"
:label="option.label"
:key="index"/>
</el-select> </el-select>
</div> </div>
</template> </template>
@ -29,7 +31,7 @@ export default {
name: 'RewritePolicyInput', name: 'RewritePolicyInput',
props: { props: {
data: { data: {
type: [String, Array], type: [Array, Object],
default: function() { default: function() {
return {} return {}
} }
@ -52,10 +54,27 @@ export default {
return this.$store.state.app.device === 'mobile' return this.$store.state.app.device === 'mobile'
}, },
rewritePolicyValue() { rewritePolicyValue() {
return typeof this.data === 'string' ? [this.data] : this.data return typeof this.data[this.setting.key] === 'string' ? [this.data[this.setting.key]] : this.data[this.setting.key]
} }
}, },
methods: { methods: {
authenticatorOptions(suggestions) {
return suggestions.map(element => {
const label = element.split('Pleroma.Web.Auth.')[1]
? element.split('Pleroma.Web.Auth.')[1]
: element
return { value: element, label }
})
},
renderMultipleSelect(type) {
return Array.isArray(type) && this.setting.key !== ':backends' && this.setting.key !== ':args' && (
type.includes('module') ||
(type.includes('list') && type.includes('string')) ||
(type.includes('list') && type.includes('atom')) ||
(type.includes('regex') && type.includes('string')) ||
this.setting.key === ':args'
)
},
rewritePolicyOptions(suggestions) { rewritePolicyOptions(suggestions) {
return suggestions.map(element => { return suggestions.map(element => {
const label = element.split('Pleroma.Web.ActivityPub.MRF.')[1] const label = element.split('Pleroma.Web.ActivityPub.MRF.')[1]