aboutsummaryrefslogtreecommitdiff
path: root/src/components/settings_modal/helpers/choice_setting.js
blob: a15f6bac0b466d7411d0f8df2dafcf8e9e88ccd2 (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
38
39
import { get, set } from 'lodash'
import Select from 'src/components/select/select.vue'
import ModifiedIndicator from './modified_indicator.vue'
export default {
  components: {
    Select,
    ModifiedIndicator
  },
  props: [
    'path',
    'disabled',
    'options'
  ],
  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, e)
    }
  }
}