aboutsummaryrefslogtreecommitdiff
path: root/src/components/settings_modal/helpers/number_setting.js
diff options
context:
space:
mode:
authorHJ <30-hj@users.noreply.git.pleroma.social>2023-05-24 18:55:20 +0000
committerHJ <30-hj@users.noreply.git.pleroma.social>2023-05-24 18:55:20 +0000
commitc730c9b6d0fac2b79e0fa5900117c66d073e4a9d (patch)
treeb33e33e9da2225c05cce2f47f87c5bc54d01cdc1 /src/components/settings_modal/helpers/number_setting.js
parent4bf085b8feb81ad52bad6cb8979786df22baba9e (diff)
parentcbd22d52b8d0cacf01f71edcb799294b93754f60 (diff)
Merge branch 'improve_settings_reusability' into 'develop'
AdminFE functionality in PleromaFE See merge request pleroma/pleroma-fe!1800
Diffstat (limited to 'src/components/settings_modal/helpers/number_setting.js')
-rw-r--r--src/components/settings_modal/helpers/number_setting.js62
1 files changed, 15 insertions, 47 deletions
diff --git a/src/components/settings_modal/helpers/number_setting.js b/src/components/settings_modal/helpers/number_setting.js
index 73c39948..676a0d22 100644
--- a/src/components/settings_modal/helpers/number_setting.js
+++ b/src/components/settings_modal/helpers/number_setting.js
@@ -1,56 +1,24 @@
-import { get, set } from 'lodash'
-import ModifiedIndicator from './modified_indicator.vue'
+import Setting from './setting.js'
+
export default {
- components: {
- ModifiedIndicator
- },
+ ...Setting,
props: {
- path: String,
- disabled: Boolean,
- min: Number,
- step: Number,
- truncate: Number,
- expert: [Number, String]
- },
- computed: {
- pathDefault () {
- const [firstSegment, ...rest] = this.path.split('.')
- return [firstSegment + 'DefaultValue', ...rest].join('.')
- },
- parent () {
- return this.$parent.$parent
- },
- state () {
- const value = get(this.parent, this.path)
- if (value === undefined) {
- return this.defaultState
- } else {
- return value
- }
- },
- defaultState () {
- return get(this.parent, this.pathDefault)
- },
- isChanged () {
- return this.state !== this.defaultState
- },
- matchesExpertLevel () {
- return (this.expert || 0) <= this.parent.expertLevel
+ ...Setting.props,
+ truncate: {
+ type: Number,
+ required: false,
+ default: 1
}
},
methods: {
- truncateValue (value) {
- if (!this.truncate) {
- return value
+ ...Setting.methods,
+ getValue (e) {
+ if (!this.truncate === 1) {
+ return parseInt(e.target.value)
+ } else if (this.truncate > 1) {
+ return Math.trunc(e.target.value / this.truncate) * this.truncate
}
-
- return Math.trunc(value / this.truncate) * this.truncate
- },
- update (e) {
- set(this.parent, this.path, this.truncateValue(parseFloat(e.target.value)))
- },
- reset () {
- set(this.parent, this.path, this.defaultState)
+ return parseFloat(e.target.value)
}
}
}