summaryrefslogtreecommitdiffstats
path: root/webapp/src/store/groups.js
diff options
context:
space:
mode:
authorUdo Walter2018-07-31 04:20:37 +0200
committerUdo Walter2018-07-31 04:20:37 +0200
commitcb7711cc9f76fe4211538bad74de68c57cd07e83 (patch)
tree633568bcbc8737e97eb0e99eaefbf846422e6147 /webapp/src/store/groups.js
parent[webapp/external-backends] Dialog polishing. Thx Udo for fixing the scroll co... (diff)
downloadbas-cb7711cc9f76fe4211538bad74de68c57cd07e83.tar.gz
bas-cb7711cc9f76fe4211538bad74de68c57cd07e83.tar.xz
bas-cb7711cc9f76fe4211538bad74de68c57cd07e83.zip
[groups] add edit form for groups; add description to groups and clients
Diffstat (limited to 'webapp/src/store/groups.js')
-rw-r--r--webapp/src/store/groups.js114
1 files changed, 86 insertions, 28 deletions
diff --git a/webapp/src/store/groups.js b/webapp/src/store/groups.js
index 8ce7f6b..6c5a23c 100644
--- a/webapp/src/store/groups.js
+++ b/webapp/src/store/groups.js
@@ -1,50 +1,108 @@
+import Vue from 'vue'
import axios from 'axios'
export default {
namespaced: true,
state: {
+ groupList: [],
+ clientList: [],
+ groupCache: {},
+ clientCache: {},
groupChain: [],
- activeTab: 0,
- editGroupDialog: false,
- editGroup: null
+ client: null,
+ activeTab: 0
},
mutations: {
- updateActiveTab (state, tabIndex) {
- state.activeTab = tabIndex
- },
- setGroupInChain (state, { tabIndex, group }) {
- if (state.groupChain.length <= tabIndex || state.groupChain[tabIndex].id !== group.id) {
+ setGroupList: (state, list) => { state.groupList = list },
+ setClientList: (state, list) => { state.clientList = list },
+ setActiveTab: (state, tabIndex) => { state.activeTab = tabIndex },
+ setGroupChain: (state, chain) => { state.groupChain = chain },
+ setClient: (state, id) => { state.client = state.clientCache[id] },
+ setGroupInChain (state, { id, tabIndex }) {
+ if (state.groupChain.length <= tabIndex || state.groupChain[tabIndex].id !== id) {
+ state.client = null
state.groupChain = state.groupChain.slice(0, tabIndex)
- state.groupChain.push(group)
+ state.groupChain.push(state.groupCache[id])
+ }
+ },
+ cacheGroup (state, group) {
+ if ('id' in group) {
+ if (!(group.id in state.groupCache)) state.groupCache[group.id] = group
+ else Object.keys(group).forEach(key => { Vue.set(state.groupCache[group.id], key, group[key]) })
}
},
- openEditGroupDialog (state, group) {
- state.editGroupDialog = true
- state.editGroup = group
+ cacheClient (state, client) {
+ if ('id' in client) {
+ if (!(client.id in state.clientCache)) state.clientCache[client.id] = client
+ else Object.keys(client).forEach(key => { Vue.set(state.clientCache[client.id], key, client[key]) })
+ }
},
- closeEditGroupDialog (state) {
- state.editGroupDialog = false
- state.editGroup = null
+ resetStore (state) {
+ state.groupList = []
+ state.clientList = []
+ state.groupCache = {}
+ state.clientCache = {}
+ state.groupChain = []
+ state.client = null
+ state.activeTab = 0
}
},
actions: {
- loadGroupInChain (context, { id, name, tabIndex, switchTab }) {
- var getSubGroups = axios.get('/api/groups/getSubGroups?id=' + id)
- var getClients = axios.get('/api/groups/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)
+ loadLists (context) {
+ var getGroupList = axios.get('/api/groups/getList')
+ var getClientList = axios.get('/api/clients/getList')
+ axios.all([getGroupList, getClientList]).then(axios.spread((groupResponse, clientResponse) => {
+ context.commit('setGroupList', groupResponse.data.map(x => ({ value: x.id, text: x.name || x.id })))
+ context.commit('setClientList', clientResponse.data.map(x => ({ value: x.id, text: x.name || x.id })))
}))
},
- editGroup (context, { id, name }) {
- axios.get('/api/groups/getParents?id=' + id).then(res => {
- context.commit('openEditGroupDialog', { id: id, name: name, parents: res.data })
+ loadRoot (context) {
+ var getGroups = axios.get('/api/groups/getSubGroups?id=' + 0)
+ var getClients = axios.get('/api/groups/getClients?id=' + 0)
+ axios.all([getGroups, getClients]).then(axios.spread((groupResponse, clientResponse) => {
+ groupResponse.data.forEach(group => { context.commit('cacheGroup', group) })
+ clientResponse.data.forEach(client => { context.commit('cacheClient', client) })
+ context.commit('setGroupChain', [{ id: 0, subGroups: groupResponse.data, clients: clientResponse.data }])
+ }))
+ },
+ loadGroupIntoTab (context, { id, tabIndex }) {
+ var cached = null
+ if (context.state.groupCache[id].fullyCached) {
+ cached = new Promise(resolve => resolve())
+ } else {
+ var getParents = axios.get('/api/groups/getParents?id=' + id)
+ var getSubGroups = axios.get('/api/groups/getSubGroups?id=' + id)
+ var getClients = axios.get('/api/groups/getClients?id=' + id)
+ cached = axios.all([getParents, getSubGroups, getClients]).then(axios.spread((parentResponse, groupResponse, clientResponse) => {
+ parentResponse.data.forEach(group => { context.commit('cacheGroup', group) })
+ groupResponse.data.forEach(group => { context.commit('cacheGroup', group) })
+ clientResponse.data.forEach(client => { context.commit('cacheClient', client) })
+ context.commit('cacheGroup', {
+ id,
+ fullyCached: true,
+ parents: parentResponse.data.map(x => context.state.groupCache[x.id]),
+ subGroups: groupResponse.data.map(x => context.state.groupCache[x.id]),
+ clients: clientResponse.data.map(x => context.state.clientCache[x.id])
+ })
+ }))
+ }
+ cached.then(() => {
+ context.commit('setGroupInChain', { id, tabIndex })
+ context.commit('setActiveTab', tabIndex)
})
},
- saveGroup (context) {
- axios.post('/api/groups/update?id=' + context.state.editGroup.id).then(res => {
- context.commit('closeEditGroupDialog')
+ loadClientIntoTab (context, id) {
+ var cached = null
+ if (context.state.clientCache[id].fullyCached) {
+ cached = new Promise(resolve => resolve())
+ } else {
+ cached = axios.get('/api/clients/getGroups?id=' + id).then(response => {
+ context.commit('cacheClient', { id, fullyCached: true, groups: response.data.map(x => context.state.groupCache[x.id]) })
+ })
+ }
+ cached.then(() => {
+ context.commit('setClient', id)
+ context.commit('setActiveTab', context.state.groupChain.length)
})
}
}