get some default when config not exist. fix #4 #7

This commit is contained in:
Jonathan Baecker 2020-05-08 15:33:51 +02:00
parent 80b3bceb0e
commit 24d139f6b1

View File

@ -1,7 +1,7 @@
export const state = () => ({ export const state = () => ({
configGui: null, configGui: null,
netChoices: [], netChoices: [],
configPlayout: null, configPlayout: [],
currentUser: null, currentUser: null,
configUser: null configUser: null
}) })
@ -37,17 +37,37 @@ export const actions = {
}) })
commit('UPDATE_NET_CHOICES', choices) commit('UPDATE_NET_CHOICES', choices)
} }
if (response.data) { if (response.data && response.data[0]) {
if (response.data[0].extra_extensions) {
response.data[0].extra_extensions = response.data[0].extra_extensions.split(' ') response.data[0].extra_extensions = response.data[0].extra_extensions.split(' ')
} else {
response.data[0].extra_extensions = []
}
commit('UPDATE_GUI_CONFIG', response.data[0]) commit('UPDATE_GUI_CONFIG', response.data[0])
} else {
commit('UPDATE_GUI_CONFIG', {
id: 0,
channel: '',
player_url: '',
playout_config: '',
net_interface: '',
media_disk: '',
extra_extensions: []
})
} }
}, },
async setGuiConfig ({ commit, state }, obj) { async setGuiConfig ({ commit, state }, obj) {
const stringObj = JSON.parse(JSON.stringify(obj)) const stringObj = JSON.parse(JSON.stringify(obj))
stringObj.extra_extensions = obj.extra_extensions.join(' ') stringObj.extra_extensions = obj.extra_extensions.join(' ')
const update = await this.$axios.put('api/player/guisettings/1/', stringObj) let response
return update
if (state.configPlayout.length === 0) {
response = await this.$axios.post('api/player/guisettings/', stringObj)
} else {
response = await this.$axios.put(`api/player/guisettings/${obj.id}/`, stringObj)
}
return response
}, },
async getPlayoutConfig ({ commit, state }) { async getPlayoutConfig ({ commit, state }) {