Generalize IntegerSetting into NumberSetting, add Integer/Float wrappers
This commit is contained in:
parent
3403f6a1ed
commit
493120b545
16
src/components/settings_modal/helpers/float_setting.vue
Normal file
16
src/components/settings_modal/helpers/float_setting.vue
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<template>
|
||||||
|
<NumberSetting
|
||||||
|
v-bind="$attrs"
|
||||||
|
>
|
||||||
|
<slot />
|
||||||
|
</NumberSetting>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import NumberSetting from './number_setting.vue'
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
NumberSetting
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
@ -1,27 +1,17 @@
|
|||||||
<template>
|
<template>
|
||||||
<span
|
<NumberSetting
|
||||||
v-if="matchesExpertLevel"
|
v-bind="$attrs"
|
||||||
class="IntegerSetting"
|
truncate="1"
|
||||||
>
|
>
|
||||||
<label :for="path">
|
<slot />
|
||||||
<slot />
|
</NumberSetting>
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
:id="path"
|
|
||||||
class="number-input"
|
|
||||||
type="number"
|
|
||||||
step="1"
|
|
||||||
:disabled="disabled"
|
|
||||||
:min="min || 0"
|
|
||||||
:value="state"
|
|
||||||
@change="update"
|
|
||||||
>
|
|
||||||
{{ ' ' }}
|
|
||||||
<ModifiedIndicator
|
|
||||||
:changed="isChanged"
|
|
||||||
:onclick="reset"
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script src="./integer_setting.js"></script>
|
<script>
|
||||||
|
import NumberSetting from './number_setting.vue'
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
NumberSetting
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
@ -8,6 +8,8 @@ export default {
|
|||||||
path: String,
|
path: String,
|
||||||
disabled: Boolean,
|
disabled: Boolean,
|
||||||
min: Number,
|
min: Number,
|
||||||
|
step: Number,
|
||||||
|
truncate: Number,
|
||||||
expert: [Number, String]
|
expert: [Number, String]
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -15,8 +17,11 @@ export default {
|
|||||||
const [firstSegment, ...rest] = this.path.split('.')
|
const [firstSegment, ...rest] = this.path.split('.')
|
||||||
return [firstSegment + 'DefaultValue', ...rest].join('.')
|
return [firstSegment + 'DefaultValue', ...rest].join('.')
|
||||||
},
|
},
|
||||||
|
parent () {
|
||||||
|
return this.$parent.$parent
|
||||||
|
},
|
||||||
state () {
|
state () {
|
||||||
const value = get(this.$parent, this.path)
|
const value = get(this.parent, this.path)
|
||||||
if (value === undefined) {
|
if (value === undefined) {
|
||||||
return this.defaultState
|
return this.defaultState
|
||||||
} else {
|
} else {
|
||||||
@ -24,21 +29,28 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
defaultState () {
|
defaultState () {
|
||||||
return get(this.$parent, this.pathDefault)
|
return get(this.parent, this.pathDefault)
|
||||||
},
|
},
|
||||||
isChanged () {
|
isChanged () {
|
||||||
return this.state !== this.defaultState
|
return this.state !== this.defaultState
|
||||||
},
|
},
|
||||||
matchesExpertLevel () {
|
matchesExpertLevel () {
|
||||||
return (this.expert || 0) <= this.$parent.expertLevel
|
return (this.expert || 0) <= this.parent.expertLevel
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
truncateValue (value) {
|
||||||
|
if (!this.truncate) {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
return Math.trunc(value / this.truncate) * this.truncate
|
||||||
|
},
|
||||||
update (e) {
|
update (e) {
|
||||||
set(this.$parent, this.path, parseInt(e.target.value))
|
set(this.parent, this.path, this.truncateValue(parseFloat(e.target.value)))
|
||||||
},
|
},
|
||||||
reset () {
|
reset () {
|
||||||
set(this.$parent, this.path, this.defaultState)
|
set(this.parent, this.path, this.defaultState)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
27
src/components/settings_modal/helpers/number_setting.vue
Normal file
27
src/components/settings_modal/helpers/number_setting.vue
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<template>
|
||||||
|
<span
|
||||||
|
v-if="matchesExpertLevel"
|
||||||
|
class="NumberSetting"
|
||||||
|
>
|
||||||
|
<label :for="path">
|
||||||
|
<slot />
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
:id="path"
|
||||||
|
class="number-input"
|
||||||
|
type="number"
|
||||||
|
:step="step || 1"
|
||||||
|
:disabled="disabled"
|
||||||
|
:min="min || 0"
|
||||||
|
:value="state"
|
||||||
|
@change="update"
|
||||||
|
>
|
||||||
|
{{ ' ' }}
|
||||||
|
<ModifiedIndicator
|
||||||
|
:changed="isChanged"
|
||||||
|
:onclick="reset"
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script src="./number_setting.js"></script>
|
@ -2,6 +2,7 @@ import BooleanSetting from '../helpers/boolean_setting.vue'
|
|||||||
import ChoiceSetting from '../helpers/choice_setting.vue'
|
import ChoiceSetting from '../helpers/choice_setting.vue'
|
||||||
import ScopeSelector from 'src/components/scope_selector/scope_selector.vue'
|
import ScopeSelector from 'src/components/scope_selector/scope_selector.vue'
|
||||||
import IntegerSetting from '../helpers/integer_setting.vue'
|
import IntegerSetting from '../helpers/integer_setting.vue'
|
||||||
|
import FloatSetting from '../helpers/float_setting.vue'
|
||||||
import SizeSetting, { defaultHorizontalUnits } from '../helpers/size_setting.vue'
|
import SizeSetting, { defaultHorizontalUnits } from '../helpers/size_setting.vue'
|
||||||
import InterfaceLanguageSwitcher from 'src/components/interface_language_switcher/interface_language_switcher.vue'
|
import InterfaceLanguageSwitcher from 'src/components/interface_language_switcher/interface_language_switcher.vue'
|
||||||
|
|
||||||
@ -62,6 +63,7 @@ const GeneralTab = {
|
|||||||
BooleanSetting,
|
BooleanSetting,
|
||||||
ChoiceSetting,
|
ChoiceSetting,
|
||||||
IntegerSetting,
|
IntegerSetting,
|
||||||
|
FloatSetting,
|
||||||
SizeSetting,
|
SizeSetting,
|
||||||
InterfaceLanguageSwitcher,
|
InterfaceLanguageSwitcher,
|
||||||
ScopeSelector,
|
ScopeSelector,
|
||||||
|
@ -272,13 +272,13 @@
|
|||||||
</BooleanSetting>
|
</BooleanSetting>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<IntegerSetting
|
<FloatSetting
|
||||||
v-if="user"
|
v-if="user"
|
||||||
path="emojiReactionsScale"
|
path="emojiReactionsScale"
|
||||||
expert="1"
|
expert="1"
|
||||||
>
|
>
|
||||||
{{ $t('settings.emoji_reactions_scale') }}
|
{{ $t('settings.emoji_reactions_scale') }}
|
||||||
</IntegerSetting>
|
</FloatSetting>
|
||||||
</li>
|
</li>
|
||||||
<h3>{{ $t('settings.attachments') }}</h3>
|
<h3>{{ $t('settings.attachments') }}</h3>
|
||||||
<li>
|
<li>
|
||||||
|
Loading…
Reference in New Issue
Block a user