summaryrefslogtreecommitdiffstats
path: root/webapp/src/store/groups.js
diff options
context:
space:
mode:
Diffstat (limited to 'webapp/src/store/groups.js')
-rw-r--r--webapp/src/store/groups.js178
1 files changed, 144 insertions, 34 deletions
diff --git a/webapp/src/store/groups.js b/webapp/src/store/groups.js
index 49c567a..ddb1df8 100644
--- a/webapp/src/store/groups.js
+++ b/webapp/src/store/groups.js
@@ -3,48 +3,158 @@ import axios from 'axios'
export default {
namespaced: true,
state: {
- groupChain: [],
+ groupList: [],
+ clientList: [],
+ tabChain: [],
activeTab: 0,
- editGroupDialog: false,
- editGroup: null
+ showAll: false,
+ dialog: {
+ show: false,
+ info: {}
+ }
},
mutations: {
- updateActiveTab (state, tabIndex) {
- state.activeTab = tabIndex
- },
- setGroupInChain (state, { tabIndex, group }) {
- if (state.groupChain.length <= tabIndex || state.groupChain[tabIndex].id !== group.id) {
- state.groupChain = state.groupChain.slice(0, tabIndex)
- state.groupChain.push(group)
+ setGroupList: (state, list) => { state.groupList = list },
+ setClientList: (state, list) => { state.clientList = list },
+ setActiveTab: (state, index) => { state.activeTab = index },
+ setShowAll: (state, value) => { state.showAll = 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)) {
+ state.tabChain = state.tabChain.slice(0, index + 1)
}
+ state.tabChain.splice(index, 1, item)
},
- openEditGroupDialog (state, group) {
- state.editGroupDialog = true
- state.editGroup = group
- },
- closeEditGroupDialog (state) {
- state.editGroupDialog = false
- state.editGroup = null
+ setDialog (state, { show, info, selected }) {
+ if (info !== undefined) state.dialog.info = info
+ if (show !== undefined) state.dialog.show = show
}
},
actions: {
- loadGroupInChain (context, { id, name, tabIndex, switchTab }) {
- var getSubGroups = axios.get('/api/groups?action=getSubGroups&id=' + id)
- var getClients = axios.get('/api/groups?action=getClients&id=' + id)
- axios.all([getSubGroups, getClients]).then(axios.spread((groupRespsonse, clientResponse) => {
- var group = { id: id, name: name, subGroups: groupRespsonse.data, clients: clientResponse.data }
- context.commit('setGroupInChain', { group: group, tabIndex: tabIndex })
- if (switchTab) context.commit('updateActiveTab', tabIndex)
- }))
- },
- editGroup (context, { id, name }) {
- axios.get('/api/groups?action=getParents&id=' + id).then(res => {
- context.commit('openEditGroupDialog', { id: id, name: name, parents: res.data })
- })
- },
- saveGroup (context) {
- axios.post('/api/groups?action=update&id=' + context.state.editGroup.id).then(res => {
- context.commit('closeEditGroupDialog')
+ loadLists (context) {
+ Promise.all([axios.get('/api/groups/getList'), axios.get('/api/clients/getList')]).then(res => {
+ context.commit('setGroupList', res[0].data.map(x => ({ id: x.id, name: x.name || x.id })))
+ context.commit('setClientList', res[1].data.map(x => ({ id: x.id, name: x.name || x.id })))
+ })
+ },
+ loadHome (context) {
+ 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 }) {
+ 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, { 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, reload: true })
+ else if (item.tabType === 'client') context.dispatch('loadClient', { id: item.id, tabIndex: index, reload: true })
+ })
+ },
+ saveGroup (context, { id, info, parentIds, tabIndex, callback }) {
+ axios.post('/api/groups/save', { id, info, parentIds }).then(res => {
+ if (callback) callback(res.data.id)
+ 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)
+ }
+ context.dispatch('reload')
+ })
+ },
+ saveClient (context, { id, info, groupIds, tabIndex, callback }) {
+ axios.post('/api/clients/save', { id, info, groupIds }).then(res => {
+ if (callback) callback(res.data.id)
+ 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)
+ }
+ context.dispatch('reload')
+ })
+ },
+ deleteGroups (context, { selected }) {
+ const ids = selected.map(x => x.id)
+ axios.post('/api/groups/delete', { ids }).then(() => {
+ var i = 1
+ while (i < context.state.tabChain.length) {
+ if (context.state.tabChain[i].tabType === 'group' && ids.includes(context.state.tabChain[i].id)) {
+ context.commit('deleteFromTabChain', { index: i, count: context.state.tabChain.length - i })
+ break
+ }
+ i++
+ }
+ context.dispatch('reload')
+ })
+ },
+ deleteClients (context, { selected }) {
+ const ids = selected.map(x => x.id)
+ axios.post('/api/clients/delete', { ids }).then(() => {
+ const index = context.state.tabChain.length - 1
+ const item = context.state.tabChain[index]
+ if (item.tabType === 'client' && ids.includes(item.id)) context.commit('deleteFromTabChain', { index, count: 1 })
+ context.dispatch('reload')
+ })
+ },
+ removeSubroups (context, { tabIndex, selected }) {
+ const id = context.state.tabChain[tabIndex].id
+ const ids = selected.map(x => x.id)
+ axios.post('/api/groups/removeSubgroups', { id, ids }).then(() => {
+ if (context.state.tabChain.length > tabIndex + 1 &&
+ context.state.tabChain[tabIndex + 1].tabType === 'group' &&
+ ids.includes(context.state.tabChain[tabIndex + 1].id)) {
+ context.commit('deleteFromTabChain', { index: tabIndex + 1, count: context.state.tabChain.length - (tabIndex + 1) })
+ }
+ context.dispatch('reload')
+ })
+ },
+ removeClients (context, { tabIndex, selected }) {
+ const id = context.state.tabChain[tabIndex].id
+ const ids = selected.map(x => x.id)
+ axios.post('/api/groups/removeClients', { id, ids }).then(() => {
+ if (context.state.tabChain.length > tabIndex + 1 &&
+ context.state.tabChain[tabIndex + 1].tabType === 'client' &&
+ ids.includes(context.state.tabChain[tabIndex + 1].id)) {
+ context.commit('deleteFromTabChain', { index: tabIndex + 1, count: 1 })
+ }
+ context.dispatch('reload')
+ })
+ },
+ addSubgroups (context, { tabIndex, selected }) {
+ const id = context.state.tabChain[tabIndex].id
+ const ids = selected.map(x => x.id)
+ axios.post('/api/groups/addSubgroups', { id, ids }).then(() => {
+ context.dispatch('reload')
+ })
+ },
+ addClients (context, { tabIndex, selected }) {
+ const id = context.state.tabChain[tabIndex].id
+ const ids = selected.map(x => x.id)
+ axios.post('/api/groups/addClients', { id, ids }).then(() => {
+ context.dispatch('reload')
})
}
}