summaryrefslogtreecommitdiffstats
path: root/webapp/src/store/backends.js
blob: d832b6ebf58f8cd91f8d21d6ac798ad2720e182c (plain) (blame)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import axios from 'axios'

export default {
  namespaced: true,
  state: {
    backends: [],
    dialog: false,
    edit: false,
    selected: [],
    backendId: '',
    sync: false
  },
  mutations: {
    setDialog (state, value) {
      state.dialog = value
    },
    setSelected (state, value) {
      state.selected = value
    },
    setBackends (state, value) {
      state.backends = value
    },
    editBackend (state, value) {
      state.backendId = value
      state.edit = true
    },
    setEdit (state, value) {
      state.edit = value
    },
    setSync (state, value) {
      state.sync = value
    },
    editSync (state, value) {
      state.backendId = value
      state.sync = true
    }
  },
  actions: {
    deleteSelectedBackends (context) {
      // Filter selected array to get a list of ids.
      const filteredArray = context.state.selected.map(x => x.id)
      axios.post('/api/backends/delete', {
        id: filteredArray
      }).then(response => {
        context.dispatch('loadData')
        context.commit('setSelected', [])
      })
    },
    loadData (context) {
      axios.get('/api/backends').then(response => {
        // Needed for initializing the diffrent dynamic loading buttons.
        var tmpItems = response.data
        tmpItems.forEach(function (item) {
          // Variable for the loading animation.
          item.loading = false
          // Variable for the test connection color
          item.connection = 'primary'
        })
        context.commit('setBackends', tmpItems)
      })
    }
  }
}