summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/api/clients.js21
-rw-r--r--server/api/groups.js62
-rw-r--r--webapp/src/components/GroupModule.vue42
-rw-r--r--webapp/src/components/GroupModuleClientList.vue10
-rw-r--r--webapp/src/components/GroupModuleClientView.vue13
-rw-r--r--webapp/src/components/GroupModuleDialog.vue4
-rw-r--r--webapp/src/components/GroupModuleGroupList.vue10
-rw-r--r--webapp/src/components/GroupModuleGroupView.vue45
-rw-r--r--webapp/src/components/GroupModuleHomeView.vue66
-rw-r--r--webapp/src/store/groups.js41
10 files changed, 142 insertions, 172 deletions
diff --git a/server/api/clients.js b/server/api/clients.js
index 862a1a2..3e257e2 100644
--- a/server/api/clients.js
+++ b/server/api/clients.js
@@ -10,20 +10,6 @@ module.exports.get = {
})
},
- // get all groups
- getAll: function (req, res) {
- db.client.findAll().then(list => {
- res.send(list)
- })
- },
-
- // get all clients that have no groups
- getTopLevel: function (req, res) {
- db.client.findAll({ where: { '$groups.id$': null }, include: ['groups'] }).then(clients => {
- res.send(clients)
- })
- },
-
// get name, description, ip, mac and uuid of a client (by id)
getClient: function (req, res) {
db.client.findOne({ where: { id: req.query.id }, include: ['groups'] }).then(client => {
@@ -37,14 +23,13 @@ module.exports.get = {
module.exports.post = {
// create client or update information of a client (returns id)
save: function (req, res) {
- const id = req.body.id > 0 ? req.body.id : null
- if (id) {
- db.client.findOne({ where: { id } }).then(client => {
+ if (req.body.id > 0) {
+ db.client.findOne({ where: { id: req.body.id } }).then(client => {
if (client) {
var promises = []
if (req.body.info) promises.push(client.update(req.body.info))
if (req.body.groupIds) promises.push(client.setGroups(req.body.groupIds))
- Promise.all(promises).then(() => { res.send({ id }) })
+ Promise.all(promises).then(() => { res.send({ id: req.body.id }) })
} else { res.status(404).end() }
})
} else {
diff --git a/server/api/groups.js b/server/api/groups.js
index 64f49fc..e8efd4f 100644
--- a/server/api/groups.js
+++ b/server/api/groups.js
@@ -2,6 +2,27 @@
var path = require('path')
var db = require(path.join(__appdir, 'lib', 'sequelize'))
+function includeAllChilds (group, groupIdChain = []) {
+ const newIdChain = [...groupIdChain, group.id]
+ return new Promise((resolve, reject) => {
+ group.getSubgroups({ include: ['subgroups', 'clients'] }).then(subgroups => {
+ const subgroupPromises = []
+ subgroups.forEach(subgroup => {
+ if (!groupIdChain.includes(subgroup.id)) {
+ subgroupPromises.push(includeAllChilds(subgroup, newIdChain))
+ }
+ })
+ Promise.all(subgroupPromises).then(result => {
+ result.forEach(resolvedSubgroup => {
+ resolvedSubgroup.subgroups.forEach(x => { if (!group.subgroups.includes(x)) group.subgroups.push(x) })
+ resolvedSubgroup.clients.forEach(x => { if (!group.clients.includes(x)) group.clients.push(x) })
+ })
+ resolve(group)
+ })
+ })
+ })
+}
+
// GET Requests
module.exports.get = {
// get a list containing id and name of all groups
@@ -11,26 +32,24 @@ module.exports.get = {
})
},
- // get all groups
- getAll: function (req, res) {
- db.group.findAll().then(list => {
- res.send(list)
- })
- },
-
- // get all groups that have no parents
- getTopLevel: function (req, res) {
- db.group.findAll({ where: { '$parents.id$': null }, include: ['parents'] }).then(groups => {
- res.send(groups)
- })
- },
-
// get name, description, parents, subgroups and clients of a group (by id)
getGroup: function (req, res) {
- db.group.findOne({ where: { id: req.query.id }, include: ['parents', 'subgroups', 'clients'] }).then(group => {
- if (group) res.send(group)
- else res.status(404).end()
- })
+ const all = req.query.all === 'true'
+ if (req.query.id > 0) {
+ db.group.findOne({ where: { id: req.query.id }, include: ['parents', 'subgroups', 'clients'] }).then(group => {
+ if (group) {
+ if (all) includeAllChilds(group).then(x => res.send(x))
+ else res.send(group)
+ } else {
+ res.status(404).end()
+ }
+ })
+ } else {
+ Promise.all([db.group.findAll(all ? {} : { where: { '$parents.id$': null }, include: ['parents'] }),
+ db.client.findAll(all ? {} : { where: { '$groups.id$': null }, include: ['groups'] })]).then(result => {
+ res.send({ id: 0, subgroups: result[0], clients: result[1] })
+ })
+ }
}
}
@@ -38,14 +57,13 @@ module.exports.get = {
module.exports.post = {
// create group or update information of a group (returns id)
save: function (req, res) {
- const id = req.body.id > 0 ? req.body.id : null
- if (id) {
- db.group.findOne({ where: { id } }).then(group => {
+ if (req.body.id > 0) {
+ db.group.findOne({ where: { id: req.body.id } }).then(group => {
if (group) {
var promises = []
if (req.body.info) promises.push(group.update(req.body.info))
if (req.body.parentIds) promises.push(group.setParents(req.body.parentIds))
- Promise.all(promises).then(() => { res.send({id}) })
+ Promise.all(promises).then(() => { res.send({ id: req.body.id }) })
} else { res.status(404).end() }
})
} else {
diff --git a/webapp/src/components/GroupModule.vue b/webapp/src/components/GroupModule.vue
index f873e68..bc0c64b 100644
--- a/webapp/src/components/GroupModule.vue
+++ b/webapp/src/components/GroupModule.vue
@@ -14,18 +14,17 @@
<v-card>
<v-tabs :value="activeTab" @input="setActiveTab" :dark="tabsDark" :color="tabsColor" :slider-color="tabsSliderColor">
<template v-for="(item, index) in tabChain">
- <v-icon v-if="item.tabType !== 'home'" :key="'arrow' + index">keyboard_arrow_right</v-icon>
+ <v-icon v-if="item.id > 0 || item.id === 'create'" :key="'arrow' + index">keyboard_arrow_right</v-icon>
<v-tab ripple :key="'tab' + index">
- <v-icon v-if="item.tabType === 'home'">home</v-icon>
+ <v-icon v-if="item.tabType === 'group' && item.id === 0">home</v-icon>
<v-icon v-if="item.tabType === 'client'" style="margin-right: 10px">computer</v-icon>
- <template v-if="item.tabType !== 'home'">{{ item.name || item.id || ' . . . . . . . . . . ' }}</template>
+ <template v-if="item.id > 0 || item.id === 'create'">{{ item.name ? item.name : item.id !== 'create' ? item.id : ' . . . . . . . . . . ' }}</template>
</v-tab>
</template>
</v-tabs>
</v-card>
<v-tabs-items :value="activeTab" @input="setActiveTab" touchless style="padding-bottom: 20px">
<v-tab-item v-for="(item, index) in tabChain" :key="index">
- <group-module-home-view v-if="item.tabType === 'home'" :home="item" />
<group-module-group-view v-if="item.tabType === 'group'" :group="item" :tabIndex="index" />
<group-module-client-view v-if="item.tabType === 'client'" :client="item" :tabIndex="index" />
</v-tab-item>
@@ -37,7 +36,6 @@
</template>
<script>
-import GroupModuleHomeView from '@/components/GroupModuleHomeView'
import GroupModuleGroupView from '@/components/GroupModuleGroupView'
import GroupModuleClientView from '@/components/GroupModuleClientView'
import GroupModuleDialog from '@/components/GroupModuleDialog'
@@ -47,13 +45,11 @@ export default {
name: 'GroupModule',
routes () {
return [
- { name: 'home', path: 'home' },
{ name: 'group', path: ':id' },
{ name: 'client', path: 'client/:id' }
]
},
components: {
- GroupModuleHomeView,
GroupModuleGroupView,
GroupModuleClientView,
GroupModuleDialog
@@ -69,10 +65,10 @@ export default {
watch: {
activeTab (index) {
const item = this.tabChain[index]
- if (item.tabType !== this.$route.name.replace('GroupModule.', '') || String(item.id) !== String(this.$route.params.id)) {
+ if (item.tabType !== this.$route.name.replace('GroupModule.', '') || String(item.id) !== this.$route.params.id) {
this.$router.push({
name: 'GroupModule.' + item.tabType,
- params: { id: (item.id || item.tabType === 'home') ? item.id : 'create', noReload: true }
+ params: { id: item.id !== undefined ? item.id : 'create', noReload: true }
})
}
}
@@ -82,7 +78,7 @@ export default {
loadItem (routeName, id) {
const type = routeName.replace('GroupModule.', '')
if (id === 'create') {
- this.setTab({ index: 1, item: { tabType: type } })
+ this.setTab({ index: 1, item: { id: 'create', tabType: type } })
this.setActiveTab(1)
} else {
const action = type === 'group' ? 'loadGroup' : type === 'client' ? 'loadClient' : null
@@ -92,24 +88,26 @@ export default {
},
created () {
if (this.groupList.length === 0 || this.clientList.length === 0) this.$store.dispatch('groups/loadLists')
- if (this.tabChain.length === 0) this.$store.dispatch('groups/loadHome', true)
- this.loadItem(this.$route.name, this.$route.params.id)
+ if (this.tabChain.length === 0) this.$store.dispatch('groups/loadGroup', { id: 0, tabIndex: 0 })
+ if (this.$route.params.id !== '0') this.loadItem(this.$route.name, this.$route.params.id)
this.$router.replace({
name: 'GroupModule.' + this.tabChain[this.activeTab].tabType,
params: { id: this.tabChain[this.activeTab].id, noReload: true }
})
},
beforeRouteUpdate (to, from, next) {
- const typeFromRoute = to.name.replace('GroupModule.', '')
- var tabIndex
- this.tabChain.some((item, index) => {
- if (item.tabType === typeFromRoute && String(item.id) === String(to.params.id)) {
- tabIndex = index
- return true
- } else { return false }
- })
- if (!to.params.noReload && tabIndex === undefined) this.loadItem(to.name, to.params.id)
- else if (tabIndex !== undefined) this.setActiveTab(tabIndex)
+ if (!to.params.noReload) {
+ var tabIndex
+ for (var i = 0; i < this.tabChain.length; i++) {
+ if (this.tabChain[i].tabType === to.name.replace('GroupModule.', '') && String(this.tabChain[i].id) === to.params.id) {
+ tabIndex = i
+ break
+ }
+ }
+ console.log(tabIndex)
+ if (tabIndex === undefined) this.loadItem(to.name, to.params.id)
+ else this.setActiveTab(tabIndex)
+ }
next()
}
}
diff --git a/webapp/src/components/GroupModuleClientList.vue b/webapp/src/components/GroupModuleClientList.vue
index 3aed123..f64563c 100644
--- a/webapp/src/components/GroupModuleClientList.vue
+++ b/webapp/src/components/GroupModuleClientList.vue
@@ -30,7 +30,7 @@
<v-card>
<component-search-table v-model="selected" :headers="headers" :items="clients" select-all>
<template slot="items" slot-scope="row">
- <tr :style="row.color" @click="row.data.selected = !row.data.selected" @dblclick="loadClient(row.data.item.id)">
+ <tr :style="row.color" @click="row.data.selected = !row.data.selected" @dblclick="loadClient(row.data.item)">
<td class="narrow-td">
<v-checkbox
color="primary"
@@ -44,7 +44,7 @@
<td>{{ row.data.item.mac }}</td>
<td>{{ row.data.item.uuid }}</td>
<td class="narrow-td">
- <v-btn class="next-arrow" icon @click.stop="loadClient(row.data.item.id)"><v-icon>keyboard_arrow_right</v-icon></v-btn>
+ <v-btn class="next-arrow" icon @click.stop="loadClient(row.data.item)"><v-icon>keyboard_arrow_right</v-icon></v-btn>
</td>
</tr>
</template>
@@ -99,11 +99,11 @@ export default {
},
methods: {
...mapMutations('groups', ['setActiveTab', 'setTab', 'setDialog']),
- loadClient (id) {
- this.$store.dispatch('groups/loadClient', { id, tabIndex: this.tabIndex + 1, switchTab: true })
+ loadClient (item) {
+ this.$store.dispatch('groups/loadClient', { id: item.id, name: item.name, tabIndex: this.tabIndex + 1, switchTab: true })
},
newClient () {
- this.setTab({ index: 1, item: { tabType: 'client' } })
+ this.setTab({ index: 1, item: { id: 'create', tabType: 'client' } })
this.setActiveTab(1)
},
deleteSelected () {
diff --git a/webapp/src/components/GroupModuleClientView.vue b/webapp/src/components/GroupModuleClientView.vue
index 370eb48..31548b4 100644
--- a/webapp/src/components/GroupModuleClientView.vue
+++ b/webapp/src/components/GroupModuleClientView.vue
@@ -131,9 +131,6 @@ export default {
groupIds: []
}
},
- created () {
- if (!this.client.id) this.editInfo()
- },
watch: {
client (newValue, oldValue) {
if (!newValue.id) this.editInfo()
@@ -152,9 +149,10 @@ export default {
},
cancelEdit () {
this.editMode = false
- if (this.client.id) return
- this.$store.commit('groups/deleteFromTabChain', { index: this.tabIndex, count: 1 })
- this.$store.commit('groups/setActiveTab', this.tabIndex - 1)
+ if (this.client.id === 'create') {
+ this.$store.commit('groups/deleteFromTabChain', { index: this.tabIndex, count: 1 })
+ this.$store.commit('groups/setActiveTab', this.tabIndex - 1)
+ }
},
saveInfo () {
this.$store.dispatch('groups/saveClient', {
@@ -172,6 +170,9 @@ export default {
params: { id, noReload: true }
})
}
+ },
+ created () {
+ if (this.client.id === 'create') this.editInfo()
}
}
</script>
diff --git a/webapp/src/components/GroupModuleDialog.vue b/webapp/src/components/GroupModuleDialog.vue
index 924d35f..67cf2c9 100644
--- a/webapp/src/components/GroupModuleDialog.vue
+++ b/webapp/src/components/GroupModuleDialog.vue
@@ -61,7 +61,7 @@
<v-icon left>create</v-icon>{{ $t('new') }}
</v-btn>
</v-card-title>
- <v-card-text v-if="action === 'add'" class="table-container">
+ <v-card-text style="height: 616px" v-if="action === 'add'" class="table-container">
<v-divider></v-divider>
<component-search-table v-model="selected" :headers="headers" :items="items" select-all>
<template slot="items" slot-scope="row">
@@ -160,7 +160,7 @@ export default {
},
newItem () {
this.setDialog({ show: false })
- var item = { tabType: this.dialog.info.type }
+ var item = { id: 'create', tabType: this.dialog.info.type }
if (this.dialog.info.type === 'group') item.parents = [this.tabChain[this.dialog.info.tabIndex]]
else if (this.dialog.info.type === 'client') item.groups = [this.tabChain[this.dialog.info.tabIndex]]
this.setTab({ index: this.dialog.info.tabIndex + 1, item })
diff --git a/webapp/src/components/GroupModuleGroupList.vue b/webapp/src/components/GroupModuleGroupList.vue
index 1669aa9..1984ef8 100644
--- a/webapp/src/components/GroupModuleGroupList.vue
+++ b/webapp/src/components/GroupModuleGroupList.vue
@@ -26,7 +26,7 @@
<v-card>
<component-search-table v-model="selected" :headers="headers" :items="groups" select-all>
<template slot="items" slot-scope="row">
- <tr :style="row.color" @click="row.data.selected = !row.data.selected" @dblclick="loadGroup(row.data.item.id)">
+ <tr :style="row.color" @click="row.data.selected = !row.data.selected" @dblclick="loadGroup(row.data.item)">
<td class="narrow-td">
<v-checkbox
color="primary"
@@ -38,7 +38,7 @@
<td>{{ row.data.item.name }}</td>
<td>{{ row.data.item.description }}</td>
<td class="narrow-td">
- <v-btn class="next-arrow" icon @click.stop="loadGroup(row.data.item.id)"><v-icon>keyboard_arrow_right</v-icon></v-btn>
+ <v-btn class="next-arrow" icon @click.stop="loadGroup(row.data.item)"><v-icon>keyboard_arrow_right</v-icon></v-btn>
</td>
</tr>
</template>
@@ -91,11 +91,11 @@ export default {
},
methods: {
...mapMutations('groups', ['setActiveTab', 'setTab', 'setDialog']),
- loadGroup (id) {
- this.$store.dispatch('groups/loadGroup', { id, tabIndex: this.tabIndex + 1, switchTab: true })
+ loadGroup (item) {
+ this.$store.dispatch('groups/loadGroup', { id: item.id, name: item.name, tabIndex: this.tabIndex + 1, switchTab: true })
},
newGroup () {
- this.setTab({ index: 1, item: { tabType: 'group' } })
+ this.setTab({ index: 1, item: { id: 'create', tabType: 'group' } })
this.setActiveTab(1)
},
deleteSelected () {
diff --git a/webapp/src/components/GroupModuleGroupView.vue b/webapp/src/components/GroupModuleGroupView.vue
index b9b81f2..cf38ba4 100644
--- a/webapp/src/components/GroupModuleGroupView.vue
+++ b/webapp/src/components/GroupModuleGroupView.vue
@@ -2,6 +2,8 @@
{
"en": {
"info": "Info",
+ "showall": "Show All",
+ "groups": "Groups",
"subgroups": "Subgroups",
"clients": "Clients",
"name": "Name",
@@ -10,6 +12,8 @@
},
"de": {
"info": "Info",
+ "showall": "Show All",
+ "groups": "Groups",
"subgroups": "Untergruppen",
"clients": "Clienten",
"name": "Name",
@@ -21,8 +25,8 @@
<template>
<div>
- <v-subheader>Info</v-subheader>
- <v-card>
+ <v-subheader v-if="group.id !== 0">Info</v-subheader>
+ <v-card v-if="group.id !== 0">
<v-card-text>
<v-layout wrap>
<v-flex lg4 md6 xs12 order-lg1 order-xs2>
@@ -88,8 +92,19 @@
</v-layout>
</v-card-text>
</v-card>
- <template v-if="group.id">
- <v-subheader>{{ $t('subgroups') }}</v-subheader>
+ <template v-if="group.id !== 'create'">
+ <v-layout>
+ <v-spacer></v-spacer>
+ <div><v-switch
+ :input-value="group.tabShowAll"
+ @change="setShowAll"
+ class="show-toggle"
+ :label="$t('showall')"
+ hide-details
+ color="primary"
+ ></v-switch></div>
+ </v-layout>
+ <v-subheader>{{ group.id > 0 ? $t('subgroups') : $t('groups') }}</v-subheader>
<group-module-group-list :tabIndex="tabIndex" :groupId="group.id" :groups="group.subgroups" />
<v-subheader>{{ $t('clients') }}</v-subheader>
<group-module-client-list :tabIndex="tabIndex" :groupId="group.id" :clients="group.clients" />
@@ -118,9 +133,6 @@ export default {
parentIds: []
}
},
- created () {
- if (!this.group.id) this.editInfo()
- },
watch: {
group (newValue, oldValue) {
if (!newValue.id) this.editInfo()
@@ -128,6 +140,10 @@ export default {
}
},
methods: {
+ setShowAll (value) {
+ this.$store.commit('groups/setShowAll', { index: this.tabIndex, value })
+ this.$store.dispatch('groups/loadGroup', { id: this.group.id, tabIndex: this.tabIndex, reload: true })
+ },
removeParent (id) {
this.parentIds.splice(this.parentIds.indexOf(id), 1)
},
@@ -139,9 +155,10 @@ export default {
},
cancelEdit () {
this.editMode = false
- if (this.group.id) return
- this.$store.commit('groups/deleteFromTabChain', { index: this.tabIndex, count: 1 })
- this.$store.commit('groups/setActiveTab', this.tabIndex - 1)
+ if (this.group.id === 'create') {
+ this.$store.commit('groups/deleteFromTabChain', { index: this.tabIndex, count: 1 })
+ this.$store.commit('groups/setActiveTab', this.tabIndex - 1)
+ }
},
saveInfo () {
this.$store.dispatch('groups/saveGroup', {
@@ -159,6 +176,9 @@ export default {
params: { id, noReload: true }
})
}
+ },
+ created () {
+ if (this.group.id === 'create') this.editInfo()
}
}
</script>
@@ -182,4 +202,9 @@ export default {
.info-text {
margin-left: 34px;
}
+.show-toggle {
+ margin-top: 20px;
+ margin-right: 20px;
+ margin-bottom: -20px;
+}
</style>
diff --git a/webapp/src/components/GroupModuleHomeView.vue b/webapp/src/components/GroupModuleHomeView.vue
deleted file mode 100644
index 94eb12f..0000000
--- a/webapp/src/components/GroupModuleHomeView.vue
+++ /dev/null
@@ -1,66 +0,0 @@
-<i18n>
-{
- "en": {
- "showall": "Show All",
- "groups": "Groups",
- "clients": "Clients"
- },
- "de": {
- "showall": "Alle anzeigen",
- "groups": "Gruppen",
- "clients": "Clienten"
- }
-}
-</i18n>
-
-<template>
- <div>
- <v-layout>
- <v-spacer></v-spacer>
- <div><v-switch class="show-toggle" :label="$t('showall')" hide-details color="primary" :input-value="showAll" @change="setShowAll"></v-switch></div>
- </v-layout>
- <v-subheader>{{ $t('groups') }}</v-subheader>
- <group-module-group-list :tabIndex="0" :groups="home.groups" />
- <v-subheader>{{ $t('clients') }}</v-subheader>
- <group-module-client-list :tabIndex="0" :clients="home.clients" />
- </div>
-</template>
-
-<script>
-import GroupModuleGroupList from '@/components/GroupModuleGroupList'
-import GroupModuleClientList from '@/components/GroupModuleClientList'
-import { mapState, mapMutations } from 'vuex'
-
-export default {
- name: 'GroupModuleHomeView',
- props: ['home'],
- components: {
- GroupModuleGroupList,
- GroupModuleClientList
- },
- data () {
- return {
- }
- },
- computed: {
- ...mapState('groups', ['showAll'])
- },
- watch: {
- showAll () {
- this.$store.dispatch('groups/loadHome')
- }
- },
- methods: {
- ...mapMutations('groups', ['setShowAll'])
- }
-}
-</script>
-
-<!-- Add "scoped" attribute to limit CSS to this component only -->
-<style scoped>
-.show-toggle {
- margin-top: 20px;
- margin-right: 20px;
- margin-bottom: -20px;
-}
-</style>
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 })
})
},