aboutsummaryrefslogtreecommitdiff
path: root/src/components/settings_modal/helpers/number_setting.js
diff options
context:
space:
mode:
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)
}
}
}