aboutsummaryrefslogtreecommitdiff
path: root/src/components/settings_modal/helpers/integer_setting.js
blob: fa6569ab65e630d95924042a804f3ddbec65949b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { get, set } from 'lodash'
import ModifiedIndicator from './modified_indicator.vue'
export default {
  components: {
    ModifiedIndicator
  },
  props: {
    path: String,
    disabled: Boolean,
    min: Number
  },
  computed: {
    pathDefault () {
      const [firstSegment, ...rest] = this.path.split('.')
      return [firstSegment + 'DefaultValue', ...rest].join('.')
    },
    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
    }
  },
  methods: {
    update (e) {
      set(this.$parent, this.path, parseInt(e.target.value))
    }
  }
}