summaryrefslogtreecommitdiffstats
path: root/webapp/src/store
diff options
context:
space:
mode:
authorUdo Walter2018-08-07 05:25:44 +0200
committerUdo Walter2018-08-07 05:25:44 +0200
commit8f64402237a74ddb380b7e9650fa5897505a665f (patch)
tree692971f50fa7d442bf6fa3be959e72f588626774 /webapp/src/store
parentmerge (diff)
downloadbas-8f64402237a74ddb380b7e9650fa5897505a665f.tar.gz
bas-8f64402237a74ddb380b7e9650fa5897505a665f.tar.xz
bas-8f64402237a74ddb380b7e9650fa5897505a665f.zip
[groups] add ability to show all nested children and not just direkt children + bug fixes
Diffstat (limited to 'webapp/src/store')
-rw-r--r--webapp/src/store/groups.js41
1 files changed, 25 insertions, 16 deletions
diff --git a/webapp/src/store/groups.js b/webapp/src/store/groups.js
index 84dbc7a..524fdc4 100644
--- a/webapp/src/store/groups.js
+++ b/webapp/src/store/groups.js
@@ -7,7 +7,6 @@ export default {
clientList: [],
tabChain: [],
activeTab: 0,
- showAll: false,
dialog: {
show: false,
info: {}
@@ -17,7 +16,7 @@ export default {
setGroupList: (state, list) => { state.groupList = list },
setClientList: (state, list) => { state.clientList = list },
setActiveTab: (state, index) => { state.activeTab = index },
- setShowAll: (state, value) => { state.showAll = value },
+ setShowAll: (state, { index, value }) => { state.tabChain[index].tabShowAll = value },
deleteFromTabChain: (state, { index, count }) => { state.tabChain.splice(index, count) },
setTab: (state, { index, item }) => {
if (state.tabChain.length > index + 1 && (state.tabChain[index].tabType !== item.tabType || state.tabChain[index].id !== item.id)) {
@@ -37,40 +36,50 @@ export default {
context.commit('setClientList', res[1].data.map(x => ({ id: x.id, name: x.name || x.id })))
})
},
- loadHome (context, placeholder) {
- if (placeholder) context.commit('setTab', { index: 0, item: { tabType: 'home', groups: [], clients: [] } })
- var apiFunction = context.state.showAll ? 'getAll' : 'getTopLevel'
- Promise.all([axios.get('/api/groups/' + apiFunction), axios.get('/api/clients/' + apiFunction)]).then(res => {
- context.commit('setTab', { index: 0, item: { tabType: 'home', groups: res[0].data, clients: res[1].data } })
- })
- },
- loadGroup (context, { id, tabIndex, switchTab, reload, placeholder }) {
+ loadGroup (context, { id, name, tabIndex, switchTab, reload, placeholderName }) {
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 => {
+ const showAll = context.state.tabChain.length > tabIndex &&
+ context.state.tabChain[tabIndex].id === id &&
+ context.state.tabChain[tabIndex].tabShowAll
+ if (context.state.tabChain.length <= tabIndex || context.state.tabChain[tabIndex].id !== id) {
+ context.commit('setTab', { index: tabIndex, item: { id, name, tabType: 'group', tabShowAll: showAll, subgroups: [], clients: [] } })
+ }
+ if (switchTab) context.commit('setActiveTab', tabIndex)
+ axios.get('/api/groups/getGroup?id=' + id + (showAll ? '&all=true' : '')).then(res => {
res.data.tabType = 'group'
+ res.data.tabShowAll = showAll
context.commit('setTab', { index: tabIndex, item: res.data })
- if (switchTab) context.commit('setActiveTab', tabIndex)
+ }).catch(err => {
+ console.log(err)
+ if (switchTab) context.commit('setActiveTab', tabIndex - 1)
+ context.commit('deleteFromTabChain', { index: tabIndex, count: context.state.tabChain.length - tabIndex })
})
}
},
- loadClient (context, { tabType, id, tabIndex, switchTab, reload }) {
+ loadClient (context, { id, name, tabIndex, switchTab, reload }) {
if (!reload && context.state.tabChain.length > tabIndex && context.state.tabChain[tabIndex].id === id) {
if (switchTab) context.commit('setActiveTab', tabIndex)
} else {
+ if (context.state.tabChain.length <= tabIndex || context.state.tabChain[tabIndex].id !== id) {
+ context.commit('setTab', { index: tabIndex, item: { id, name, tabType: 'client' } })
+ }
+ if (switchTab) context.commit('setActiveTab', tabIndex)
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)
+ }).catch(err => {
+ console.log(err)
+ if (switchTab) context.commit('setActiveTab', tabIndex - 1)
+ context.commit('deleteFromTabChain', { index: tabIndex, count: context.state.tabChain.length - 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, reload: true })
+ if (item.tabType === 'group') context.dispatch('loadGroup', { id: item.id, tabIndex: index, reload: true, tabShowAll: item.tabShowAll })
else if (item.tabType === 'client') context.dispatch('loadClient', { id: item.id, tabIndex: index, reload: true })
})
},