summaryrefslogtreecommitdiffstats
path: root/webapp/src/store
diff options
context:
space:
mode:
authorChristian Hofmaier2018-08-05 01:48:06 +0200
committerChristian Hofmaier2018-08-05 01:48:06 +0200
commit0d653469ea504bd8f638d0534e20b69ce977d319 (patch)
tree54125f18c9400052b8fd3b9635c6f362b8647d9d /webapp/src/store
parent[permissions] add permission management (diff)
parent[webapp/groups] add generic table actions component for search and pagination... (diff)
downloadbas-0d653469ea504bd8f638d0534e20b69ce977d319.tar.gz
bas-0d653469ea504bd8f638d0534e20b69ce977d319.tar.xz
bas-0d653469ea504bd8f638d0534e20b69ce977d319.zip
merge
Diffstat (limited to 'webapp/src/store')
-rw-r--r--webapp/src/store/backends.js23
-rw-r--r--webapp/src/store/global.js8
-rw-r--r--webapp/src/store/groups.js178
-rw-r--r--webapp/src/store/index.js16
4 files changed, 165 insertions, 60 deletions
diff --git a/webapp/src/store/backends.js b/webapp/src/store/backends.js
index bc99669..4eca8ec 100644
--- a/webapp/src/store/backends.js
+++ b/webapp/src/store/backends.js
@@ -5,14 +5,14 @@ export default {
state: {
backends: [],
dialog: false,
- deleteDialog: false,
+ edit: false,
selected: [],
- backendId: ''
+ backendId: '',
+ sync: false
},
mutations: {
setDialog (state, value) {
state.dialog = value.show
- state.deleteDialog = value.del
},
setSelected (state, value) {
state.selected = value
@@ -22,15 +22,24 @@ export default {
},
editBackend (state, value) {
state.backendId = value
- state.dialog = true
- state.deleteDialog = false
+ state.edit = true
+ },
+ setEdit (state, value) {
+ state.edit = value
+ },
+ setSync (state, value) {
+ state.sync = value
+ },
+ editSync (state, value) {
+ state.backendId = value
+ state.sync = true
}
},
actions: {
deleteSelectedBackends (context) {
// Filter selected array to get a list of ids.
const filteredArray = context.state.selected.map(x => x.id)
- axios.post('/api/backends/deleteBackends', {
+ axios.post('/api/backends/delete', {
id: filteredArray
}).then(response => {
context.dispatch('loadData')
@@ -38,7 +47,7 @@ export default {
})
},
loadData (context) {
- axios.get('/api/backends/getBackendList').then(response => {
+ axios.get('/api/backends/getList').then(response => {
// Needed for initializing the diffrent dynamic loading buttons.
var tmpItems = response.data
tmpItems.forEach(function (item) {
diff --git a/webapp/src/store/global.js b/webapp/src/store/global.js
index a636cd6..bf31ce9 100644
--- a/webapp/src/store/global.js
+++ b/webapp/src/store/global.js
@@ -1,4 +1,4 @@
-function loadSetting(name, defaultValue) {
+function loadSetting (name, defaultValue) {
const value = localStorage.getItem('settings.' + name)
switch (typeof defaultValue) {
case 'boolean':
@@ -17,9 +17,10 @@ export default {
dark: loadSetting('dark', true),
coloredTabs: loadSetting('coloredTabs', false),
clipped: loadSetting('clipped', true),
- mini: loadSetting('mini', true),
+ mini: loadSetting('mini', true)
},
- snackbars: []
+ snackbars: [],
+ loginRedirect: null
},
getters: {
tabsDark: state => state.settings.dark || state.settings.coloredTabs,
@@ -31,6 +32,7 @@ export default {
}
},
mutations: {
+ setLoginRedirect: (state, value) => { state.loginRedirect = value },
saveSetting (state, { name, value }) { if (name in state.settings) state.settings[name] = value; localStorage.setItem('settings.' + name, value) },
shiftSnackbars (state) {
state.snackbars.shift()
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')
})
}
}
diff --git a/webapp/src/store/index.js b/webapp/src/store/index.js
deleted file mode 100644
index b351957..0000000
--- a/webapp/src/store/index.js
+++ /dev/null
@@ -1,16 +0,0 @@
-import Vue from 'vue'
-import Vuex from 'vuex'
-import globalStore from '@/store/global'
-import groups from '@/store/groups'
-import backends from '@/store/backends'
-import permissions from '@/store/permissions'
-
-Vue.use(Vuex)
-
-globalStore.modules = {
- groups,
- backends,
- permissions
-}
-
-export default new Vuex.Store(globalStore)