2022-03-07 20:02:53 -05:00
|
|
|
import { get, set } from 'lodash'
|
|
|
|
import ModifiedIndicator from './modified_indicator.vue'
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
ModifiedIndicator
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
path: String,
|
|
|
|
disabled: Boolean,
|
2022-03-14 09:31:24 +02:00
|
|
|
min: Number,
|
2023-03-18 20:48:36 +03:00
|
|
|
step: Number,
|
|
|
|
truncate: Number,
|
2022-03-29 00:02:02 +03:00
|
|
|
expert: [Number, String]
|
2022-03-07 20:02:53 -05:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
pathDefault () {
|
|
|
|
const [firstSegment, ...rest] = this.path.split('.')
|
|
|
|
return [firstSegment + 'DefaultValue', ...rest].join('.')
|
|
|
|
},
|
2023-03-18 20:48:36 +03:00
|
|
|
parent () {
|
|
|
|
return this.$parent.$parent
|
|
|
|
},
|
2022-03-07 20:02:53 -05:00
|
|
|
state () {
|
2023-03-18 20:48:36 +03:00
|
|
|
const value = get(this.parent, this.path)
|
2022-03-07 20:02:53 -05:00
|
|
|
if (value === undefined) {
|
|
|
|
return this.defaultState
|
|
|
|
} else {
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
},
|
|
|
|
defaultState () {
|
2023-03-18 20:48:36 +03:00
|
|
|
return get(this.parent, this.pathDefault)
|
2022-03-07 20:02:53 -05:00
|
|
|
},
|
|
|
|
isChanged () {
|
|
|
|
return this.state !== this.defaultState
|
2022-03-14 09:31:24 +02:00
|
|
|
},
|
|
|
|
matchesExpertLevel () {
|
2023-03-18 20:48:36 +03:00
|
|
|
return (this.expert || 0) <= this.parent.expertLevel
|
2022-03-07 20:02:53 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2023-03-18 20:48:36 +03:00
|
|
|
truncateValue (value) {
|
|
|
|
if (!this.truncate) {
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
|
|
|
|
return Math.trunc(value / this.truncate) * this.truncate
|
|
|
|
},
|
2022-03-07 20:02:53 -05:00
|
|
|
update (e) {
|
2023-03-18 20:48:36 +03:00
|
|
|
set(this.parent, this.path, this.truncateValue(parseFloat(e.target.value)))
|
2022-06-05 17:10:44 +03:00
|
|
|
},
|
|
|
|
reset () {
|
2023-03-18 20:48:36 +03:00
|
|
|
set(this.parent, this.path, this.defaultState)
|
2022-03-07 20:02:53 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|