import axios from 'axios' export default { namespaced: true, state: { backends: [], dialog: false, deleteDialog: false, selected: [], backendId: '' }, mutations: { setDialog (state, value) { state.dialog = value.show state.deleteDialog = value.del }, setSelected (state, value) { state.selected = value }, setBackends (state, value) { state.backends = value }, editBackend (state, value) { state.backendId = value state.dialog = true state.deleteDialog = false } }, 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/deleteBackends', { id: filteredArray }).then(response => { context.dispatch('loadData') context.commit('setSelected', []) }) }, loadData (context) { axios.get('/api/backends/getBackendList').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) }) } } }