summaryrefslogtreecommitdiffstats
path: root/webapp/src/store/groups.js
diff options
context:
space:
mode:
authorUdo Walter2018-08-01 22:17:33 +0200
committerUdo Walter2018-08-01 22:17:33 +0200
commitfaf1188d03e1302dd615a118bce73dd6197be8f1 (patch)
tree207d484a6d68f3d77bc49815ea92c13f4da057c3 /webapp/src/store/groups.js
parent[server/idoit] iDoIT api call returns now the object itself and the childs. (diff)
downloadbas-faf1188d03e1302dd615a118bce73dd6197be8f1.tar.gz
bas-faf1188d03e1302dd615a118bce73dd6197be8f1.tar.xz
bas-faf1188d03e1302dd615a118bce73dd6197be8f1.zip
[groups] add edit functionality to group infos
Diffstat (limited to 'webapp/src/store/groups.js')
-rw-r--r--webapp/src/store/groups.js127
1 files changed, 51 insertions, 76 deletions
diff --git a/webapp/src/store/groups.js b/webapp/src/store/groups.js
index 6c5a23c..45fa59b 100644
--- a/webapp/src/store/groups.js
+++ b/webapp/src/store/groups.js
@@ -6,42 +6,28 @@ export default {
state: {
groupList: [],
clientList: [],
- groupCache: {},
- clientCache: {},
- groupChain: [],
- client: null,
+ tabChain: [],
activeTab: 0
},
mutations: {
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(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]) })
- }
- },
- 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]) })
+ 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)
}
},
resetStore (state) {
state.groupList = []
state.clientList = []
- state.groupCache = {}
- state.clientCache = {}
+ state.home = null
state.groupChain = []
state.client = null
state.activeTab = 0
@@ -49,60 +35,49 @@ export default {
},
actions: {
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 })))
- }))
+ Promise.all([axios.get('/api/groups/getList'), axios.get('/api/clients/getList')]).then(res => {
+ context.commit('setGroupList', res[0].data.map(x => ({ value: x.id, text: x.name || x.id })))
+ context.commit('setClientList', res[1].data.map(x => ({ value: x.id, text: x.name || x.id })))
+ })
},
- 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 }])
- }))
+ loadHome (context) {
+ Promise.all([axios.get('/api/groups/getTopLevel'), axios.get('/api/clients/getTopLevel')]).then(res => {
+ context.commit('setTab', { index: 0, item: { tabType: 'home', groups: res[0].data, clients: res[1].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)
+ 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 })
+ if (switchTab) context.commit('setActiveTab', tabIndex)
})
},
- 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)
+ 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 })
+ if (switchTab) context.commit('setActiveTab', tabIndex)
+ })
+ },
+ reload (context) {
+ 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 })
+ })
+ },
+ saveGroupInfo (context, { id, info, tabIndex }) {
+ axios.post('/api/groups/saveInfo', {
+ id,
+ name: info.name,
+ description: info.description,
+ parentIds: info.parentIds
+ }).then(res => {
+ if (tabIndex > 1 && !(context.state.tabChain[tabIndex - 1].id in info.parentIds)) {
+ context.commit('deleteFromTabChain', { index: 1, count: tabIndex - 1 })
+ context.commit('setActiveTab', 1)
+ }
+ context.dispatch('reload')
})
}
}