summaryrefslogtreecommitdiffstats
path: root/webapp/src/store/groups.js
diff options
context:
space:
mode:
authorUdo Walter2018-08-02 01:42:30 +0200
committerUdo Walter2018-08-02 01:42:30 +0200
commitb311735e97bedd764f2e6d43afe8d24bb4fb67a1 (patch)
treebcaf99471f341dde57e31a20634341756b45ef0c /webapp/src/store/groups.js
parent[groups] add client edit functionality (diff)
downloadbas-b311735e97bedd764f2e6d43afe8d24bb4fb67a1.tar.gz
bas-b311735e97bedd764f2e6d43afe8d24bb4fb67a1.tar.xz
bas-b311735e97bedd764f2e6d43afe8d24bb4fb67a1.zip
[groups] add create functionality
Diffstat (limited to 'webapp/src/store/groups.js')
-rw-r--r--webapp/src/store/groups.js60
1 files changed, 29 insertions, 31 deletions
diff --git a/webapp/src/store/groups.js b/webapp/src/store/groups.js
index 5df5609..aad77f4 100644
--- a/webapp/src/store/groups.js
+++ b/webapp/src/store/groups.js
@@ -1,4 +1,3 @@
-import Vue from 'vue'
import axios from 'axios'
export default {
@@ -7,7 +6,8 @@ export default {
groupList: [],
clientList: [],
tabChain: [],
- activeTab: 0
+ activeTab: 0,
+ showAll: false
},
mutations: {
setGroupList: (state, list) => { state.groupList = list },
@@ -15,22 +15,10 @@ export default {
setActiveTab: (state, index) => { state.activeTab = index },
deleteFromTabChain: (state, { index, count }) => { state.tabChain.splice(index, count) },
setTab: (state, { index, item }) => {
- if (state.tabChain.length > index && state.tabChain[index].id === item.id) {
- Object.keys(item).forEach(key => {
- Vue.set(state.tabChain[index], key, item[key])
- })
- } else {
- state.tabChain = state.tabChain.slice(0, index)
- state.tabChain.push(item)
+ if (state.tabChain.length > index + 1 && (state.tabChain[index].tabType !== item.tabType || state.tabChain[index].id !== item.id)) {
+ state.tabChain = state.tabChain.slice(0, index + 1)
}
- },
- resetStore (state) {
- state.groupList = []
- state.clientList = []
- state.home = null
- state.groupChain = []
- state.client = null
- state.activeTab = 0
+ state.tabChain.splice(index, 1, item)
}
},
actions: {
@@ -45,30 +33,39 @@ export default {
context.commit('setTab', { index: 0, item: { tabType: 'home', groups: res[0].data, clients: res[1].data } })
})
},
- loadGroup (context, { id, tabIndex, switchTab }) {
- axios.get('/api/groups/getGroup?id=' + id).then(res => {
- res.data.tabType = 'group'
- context.commit('setTab', { index: tabIndex, item: res.data })
+ loadGroup (context, { id, tabIndex, switchTab, reload }) {
+ if (!reload && context.state.tabChain.length > tabIndex && context.state.tabChain[tabIndex].id === id) {
if (switchTab) context.commit('setActiveTab', tabIndex)
- })
+ } else {
+ axios.get('/api/groups/getGroup?id=' + id).then(res => {
+ res.data.tabType = 'group'
+ context.commit('setTab', { index: tabIndex, item: res.data })
+ if (switchTab) context.commit('setActiveTab', tabIndex)
+ })
+ }
},
- loadClient (context, { id, tabIndex, switchTab }) {
- axios.get('/api/clients/getClient?id=' + id).then(res => {
- res.data.tabType = 'client'
- context.commit('setTab', { index: tabIndex, item: res.data })
+ loadClient (context, { tabType, id, tabIndex, switchTab, reload }) {
+ if (!reload && context.state.tabChain.length > tabIndex && context.state.tabChain[tabIndex].id === id) {
if (switchTab) context.commit('setActiveTab', tabIndex)
- })
+ } else {
+ axios.get('/api/clients/getClient?id=' + id).then(res => {
+ res.data.tabType = 'client'
+ context.commit('setTab', { index: tabIndex, item: res.data })
+ if (switchTab) context.commit('setActiveTab', tabIndex)
+ })
+ }
},
reload (context) {
context.dispatch('loadLists')
context.state.tabChain.forEach((item, index) => {
if (item.tabType === 'home') context.dispatch('loadHome')
- else if (item.tabType === 'group') context.dispatch('loadGroup', { id: item.id, tabIndex: index })
- else if (item.tabType === 'client') context.dispatch('loadClient', { id: item.id, tabIndex: index })
+ else if (item.tabType === 'group') context.dispatch('loadGroup', { id: item.id, tabIndex: index, reload: true })
+ else if (item.tabType === 'client') context.dispatch('loadClient', { id: item.id, tabIndex: index, reload: true })
})
},
saveGroup (context, { id, info, parentIds, tabIndex }) {
- axios.post('/api/groups/saveInfo', { id, info, parentIds }).then(res => {
+ axios.post('/api/groups/updateOrCreate', { id, info, parentIds }).then(res => {
+ if (!id) context.commit('setTab', { index: tabIndex, item: { id: res.data.id, name: info.name, tabType: 'group' } })
if (parentIds && tabIndex > 1 && !parentIds.includes(context.state.tabChain[tabIndex - 1].id)) {
context.commit('deleteFromTabChain', { index: 1, count: tabIndex - 1 })
context.commit('setActiveTab', 1)
@@ -77,7 +74,8 @@ export default {
})
},
saveClient (context, { id, info, groupIds, tabIndex }) {
- axios.post('/api/clients/saveInfo', { id, info, groupIds }).then(res => {
+ axios.post('/api/clients/updateOrCreate', { id, info, groupIds }).then(res => {
+ if (!id) context.commit('setTab', { index: tabIndex, item: { id: res.data.id, name: info.name, tabType: 'client' } })
if (groupIds && tabIndex > 1 && !groupIds.includes(context.state.tabChain[tabIndex - 1].id)) {
context.commit('deleteFromTabChain', { index: 1, count: tabIndex - 1 })
context.commit('setActiveTab', 1)