summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/api/clients.js16
-rw-r--r--server/api/groups.js42
-rw-r--r--server/migrations/20180717132233-create-group.js2
-rw-r--r--server/migrations/20180717132333-create-client.js2
-rw-r--r--server/migrations/20180717202333-create-group_x_group.js4
-rw-r--r--server/migrations/20180717202533-create-group_x_client.js4
-rw-r--r--server/models/client.js4
-rw-r--r--server/models/group.js7
-rw-r--r--webapp/src/components/GroupModule.vue36
-rw-r--r--webapp/src/components/GroupModuleClientList.vue10
-rw-r--r--webapp/src/components/GroupModuleGroupList.vue14
-rw-r--r--webapp/src/components/GroupModuleGroupView.vue48
-rw-r--r--webapp/src/components/GroupModuleHomeView.vue42
-rw-r--r--webapp/src/store/groups.js127
14 files changed, 169 insertions, 189 deletions
diff --git a/server/api/clients.js b/server/api/clients.js
index d494fd0..8daab55 100644
--- a/server/api/clients.js
+++ b/server/api/clients.js
@@ -10,11 +10,17 @@ module.exports.get = {
})
},
- getGroups: function (req, res) {
- db.client.findOne({ where: { id: req.query.id } }).then(client => {
- client.getGroups().then(groups => {
- res.send(groups)
- })
+ // 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 => {
+ res.send(client)
})
}
}
diff --git a/server/api/groups.js b/server/api/groups.js
index fa2c1ca..5916585 100644
--- a/server/api/groups.js
+++ b/server/api/groups.js
@@ -4,42 +4,42 @@ var db = require(path.join(__appdir, 'lib', 'sequelize'))
// GET Requests
module.exports.get = {
+ // get a list containing id and name of all groups
getList: function (req, res) {
db.group.findAll({ attributes: ['id', 'name'] }).then(list => {
res.send(list)
})
},
- getParents: function (req, res) {
- const id = req.query.id > 0 ? req.query.id : null
- db.group.findOne({ where: { id: id }, include: ['parents'] }).then(group => {
- group.getParents().then(parents => {
- res.send(parents)
- })
+ // 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)
})
},
- getSubGroups: function (req, res) {
- const id = req.query.id > 0 ? req.query.id : null
- db.group.findAll({ where: { '$parents.id$': id }, include: ['parents'] }).then(subgroups => {
- res.send(subgroups)
- })
- },
-
- getClients: function (req, res) {
- const id = req.query.id > 0 ? req.query.id : null
- db.client.findAll({ where: { '$groups.id$': id }, include: ['groups'] }).then(clients => {
- res.send(clients)
+ // 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 => {
+ res.send(group)
})
}
}
// POST Requests
module.exports.post = {
- update: function (req, res) {
+ // create group or update information of a group (returns id)
+ saveInfo: function (req, res) {
const id = req.body.id > 0 ? req.body.id : null
- if (!id) res.end()
- db.group.update({ name: req.body.name }, { where: { id: id } })
- res.end()
+ if (id) {
+ db.group.findOne({ where: { id: id } }).then(group => {
+ Promise.all([
+ group.update({ name: req.body.name, description: req.body.description }),
+ group.setParents(req.body.parentIds)
+ ]).then(() => { res.send({id}) })
+ })
+ } else {
+ res.end()
+ }
}
}
diff --git a/server/migrations/20180717132233-create-group.js b/server/migrations/20180717132233-create-group.js
index 71258dd..49088dd 100644
--- a/server/migrations/20180717132233-create-group.js
+++ b/server/migrations/20180717132233-create-group.js
@@ -12,7 +12,7 @@ module.exports = {
type: Sequelize.STRING
},
description: {
- type: Sequelize.STRING
+ type: Sequelize.STRING(2048)
}
})
},
diff --git a/server/migrations/20180717132333-create-client.js b/server/migrations/20180717132333-create-client.js
index 955f2f9..d374b22 100644
--- a/server/migrations/20180717132333-create-client.js
+++ b/server/migrations/20180717132333-create-client.js
@@ -12,7 +12,7 @@ module.exports = {
type: Sequelize.STRING
},
description: {
- type: Sequelize.STRING
+ type: Sequelize.STRING(2048)
},
ip: {
type: Sequelize.STRING
diff --git a/server/migrations/20180717202333-create-group_x_group.js b/server/migrations/20180717202333-create-group_x_group.js
index a40278d..298c2fb 100644
--- a/server/migrations/20180717202333-create-group_x_group.js
+++ b/server/migrations/20180717202333-create-group_x_group.js
@@ -6,7 +6,7 @@ module.exports = {
primaryKey: true,
allowNull: false,
type: Sequelize.INTEGER,
- onDelete: "cascade",
+ onDelete: 'cascade',
references: {
model: 'groups',
key: 'id'
@@ -16,7 +16,7 @@ module.exports = {
primaryKey: true,
allowNull: false,
type: Sequelize.INTEGER,
- onDelete: "cascade",
+ onDelete: 'cascade',
references: {
model: 'groups',
key: 'id'
diff --git a/server/migrations/20180717202533-create-group_x_client.js b/server/migrations/20180717202533-create-group_x_client.js
index 2330cdb..7564618 100644
--- a/server/migrations/20180717202533-create-group_x_client.js
+++ b/server/migrations/20180717202533-create-group_x_client.js
@@ -6,7 +6,7 @@ module.exports = {
primaryKey: true,
allowNull: false,
type: Sequelize.INTEGER,
- onDelete: "cascade",
+ onDelete: 'cascade',
references: {
model: 'groups',
key: 'id'
@@ -16,7 +16,7 @@ module.exports = {
primaryKey: true,
allowNull: false,
type: Sequelize.INTEGER,
- onDelete: "cascade",
+ onDelete: 'cascade',
references: {
model: 'clients',
key: 'id'
diff --git a/server/models/client.js b/server/models/client.js
index 483d1e6..5789788 100644
--- a/server/models/client.js
+++ b/server/models/client.js
@@ -8,7 +8,7 @@ module.exports = (sequelize, DataTypes) => {
type: DataTypes.INTEGER
},
name: DataTypes.STRING,
- description: DataTypes.STRING,
+ description: DataTypes.STRING(2048),
ip: DataTypes.STRING,
mac: DataTypes.STRING,
uuid: DataTypes.STRING
@@ -17,7 +17,7 @@ module.exports = (sequelize, DataTypes) => {
})
client.associate = function (models) {
var GroupXClient = sequelize.define('group_x_client', {}, { timestamps: false, freezeTableName: true })
- client.belongsToMany(models.group, { as: 'groups', through: GroupXClient, foreignKey: 'clientId', otherKey: 'groupId'})
+ client.belongsToMany(models.group, { as: 'groups', through: GroupXClient, foreignKey: 'clientId', otherKey: 'groupId' })
}
return client
}
diff --git a/server/models/group.js b/server/models/group.js
index e988497..62a5665 100644
--- a/server/models/group.js
+++ b/server/models/group.js
@@ -8,13 +8,16 @@ module.exports = (sequelize, DataTypes) => {
type: DataTypes.INTEGER
},
name: DataTypes.STRING,
- description: DataTypes.STRING
+ description: DataTypes.STRING(2048)
}, {
timestamps: false
})
group.associate = function (models) {
var GroupXGroup = sequelize.define('group_x_group', {}, { timestamps: false, freezeTableName: true })
- group.belongsToMany(group, { as: 'parents', through: GroupXGroup, foreignKey: 'childId', otherKey: 'parentId'})
+ var GroupXClient = sequelize.define('group_x_client', {}, { timestamps: false, freezeTableName: true })
+ group.belongsToMany(group, { as: 'parents', through: GroupXGroup, foreignKey: 'childId', otherKey: 'parentId' })
+ group.belongsToMany(group, { as: 'subgroups', through: GroupXGroup, foreignKey: 'parentId', otherKey: 'childId' })
+ group.belongsToMany(models.client, { as: 'clients', through: GroupXClient, foreignKey: 'groupId', otherKey: 'clientId' })
}
return group
}
diff --git a/webapp/src/components/GroupModule.vue b/webapp/src/components/GroupModule.vue
index b690628..a1a445c 100644
--- a/webapp/src/components/GroupModule.vue
+++ b/webapp/src/components/GroupModule.vue
@@ -14,24 +14,21 @@
<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.id > 0" :key="2*index">keyboard_arrow_right</v-icon>
- <v-tab :key="2*index+1" ripple>
- <v-icon v-if="item.id === 0">home</v-icon>
- <template v-else>
- <v-icon v-if="item.isClient" style="margin-right: 10px">computer</v-icon>
- {{ item.name ? item.name : item.id }}
- </template>
+ <v-icon v-if="item.tabType !== 'home'" :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 === 'client'" style="margin-right: 10px">computer</v-icon>
+ <template v-if="item.tabType !== 'home'">{{ item.name ? item.name : item.id }}</template>
</v-tab>
</template>
</v-tabs>
</v-card>
<v-tabs-items :value="activeTab" @input="setActiveTab" touchless style="padding-bottom: 20px">
- <template v-for="(item, index) in tabChain">
- <v-tab-item :key="index">
- <group-module-group-view :tabIndex="index" v-if="!item.isClient" />
- <group-module-client-view v-else />
- </v-tab-item>
- </template>
+ <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" />
+ </v-tab-item>
</v-tabs-items>
</v-flex>
</v-layout>
@@ -39,6 +36,7 @@
</template>
<script>
+import GroupModuleHomeView from '@/components/GroupModuleHomeView'
import GroupModuleGroupView from '@/components/GroupModuleGroupView'
import GroupModuleClientView from '@/components/GroupModuleClientView'
import { mapState, mapGetters, mapMutations } from 'vuex'
@@ -46,6 +44,7 @@ import { mapState, mapGetters, mapMutations } from 'vuex'
export default {
name: 'GroupModule',
components: {
+ GroupModuleHomeView,
GroupModuleGroupView,
GroupModuleClientView
},
@@ -55,21 +54,14 @@ export default {
},
computed: {
...mapGetters(['tabsDark', 'tabsColor', 'tabsSliderColor']),
- ...mapState('groups', ['groupChain', 'client', 'activeTab']),
- tabChain () {
- if (this.client) return this.groupChain.concat({ isClient: true, ...this.client })
- else return this.groupChain
- }
+ ...mapState('groups', ['tabChain', 'client', 'activeTab'])
},
methods: {
...mapMutations('groups', ['setActiveTab'])
},
created () {
this.$store.dispatch('groups/loadLists')
- this.$store.dispatch('groups/loadRoot')
- },
- destroyed () {
- this.$store.commit('groups/resetStore')
+ this.$store.dispatch('groups/loadHome')
}
}
</script>
diff --git a/webapp/src/components/GroupModuleClientList.vue b/webapp/src/components/GroupModuleClientList.vue
index 8f9c306..20ae332 100644
--- a/webapp/src/components/GroupModuleClientList.vue
+++ b/webapp/src/components/GroupModuleClientList.vue
@@ -52,10 +52,9 @@
</template>
<script>
-
export default {
name: 'GroupModuleClientList',
- props: ['tabIndex'],
+ props: ['tabIndex', 'clients'],
data () {
return {
headers: [
@@ -69,14 +68,9 @@ export default {
selected: []
}
},
- computed: {
- clients () {
- return this.$store.state.groups.groupChain[this.tabIndex].clients
- }
- },
methods: {
loadClient (id) {
- this.$store.dispatch('groups/loadClientIntoTab', id)
+ this.$store.dispatch('groups/loadClient', { id, tabIndex: this.tabIndex + 1, switchTab: true })
}
}
}
diff --git a/webapp/src/components/GroupModuleGroupList.vue b/webapp/src/components/GroupModuleGroupList.vue
index 0abd2fa..da51995 100644
--- a/webapp/src/components/GroupModuleGroupList.vue
+++ b/webapp/src/components/GroupModuleGroupList.vue
@@ -51,14 +51,9 @@
</template>
<script>
-import GroupModuleGroupView from '@/components/GroupModuleGroupView'
-
export default {
name: 'GroupModuleGroupList',
- components: {
- GroupModuleGroupView
- },
- props: ['tabIndex'],
+ props: ['tabIndex', 'groups'],
data () {
return {
headers: [
@@ -70,14 +65,9 @@ export default {
selected: []
}
},
- computed: {
- groups () {
- return this.$store.state.groups.groupChain[this.tabIndex].subGroups
- }
- },
methods: {
loadGroup (id) {
- this.$store.dispatch('groups/loadGroupIntoTab', { id, tabIndex: this.tabIndex + 1 })
+ this.$store.dispatch('groups/loadGroup', { id, tabIndex: this.tabIndex + 1, switchTab: true })
}
}
}
diff --git a/webapp/src/components/GroupModuleGroupView.vue b/webapp/src/components/GroupModuleGroupView.vue
index 27476dd..740266e 100644
--- a/webapp/src/components/GroupModuleGroupView.vue
+++ b/webapp/src/components/GroupModuleGroupView.vue
@@ -15,7 +15,7 @@
<v-card-text>
<v-layout wrap>
<v-flex sm6 xs12 order-xs2 order-sm1>
- <v-text-field v-if="editMode" hide-details class="info-input" label="Name" box color="primary" v-model="info.name"></v-text-field>
+ <v-text-field v-if="editMode" hide-details class="info-input" label="Name" color="primary" v-model="info.name"></v-text-field>
<div v-else class="info-input">
<div class="body-2">Name</div>
{{ group.name || '-' }}
@@ -37,7 +37,7 @@
</v-layout>
<v-layout wrap>
<v-flex sm6 xs12>
- <v-textarea v-if="editMode" rows="1" auto-grow hide-details class="info-input" label="Description" box color="primary" v-model="info.description"></v-textarea>
+ <v-textarea v-if="editMode" rows="1" auto-grow hide-details class="info-input" label="Description" color="primary" v-model="info.description"></v-textarea>
<div v-else class="info-input">
<div class="body-2">Description</div>
<pre>{{ group.description || '-' }}</pre>
@@ -47,17 +47,16 @@
<v-autocomplete
v-if="editMode"
class="info-input"
- :items="groupList"
- v-model="info.parents"
+ :items="$store.state.groups.groupList"
+ v-model="info.parentIds"
hide-details
offset-y
label="Parents"
- box
color="primary"
multiple
>
<template slot="selection" slot-scope="data">
- <v-chip small :color="chipColor" :text-color="chipTextColor" :selected="data.selected" @input="removeParent(data.item.value)" close>
+ <v-chip small :selected="data.selected" @input="removeParent(data.item.id)" close>
{{ data.item.text }}
</v-chip>
</template>
@@ -77,9 +76,9 @@
</v-card>
</template>
<v-subheader>{{ tabIndex === 0 ? 'Groups' : 'Subgoups' }}</v-subheader>
- <group-module-group-list :tabIndex="tabIndex" />
+ <group-module-group-list :tabIndex="tabIndex" :groups="group.subgroups" />
<v-subheader>Clients</v-subheader>
- <group-module-client-list :tabIndex="tabIndex" />
+ <group-module-client-list :tabIndex="tabIndex" :clients="group.clients" />
</div>
</template>
@@ -89,7 +88,7 @@ import GroupModuleClientList from '@/components/GroupModuleClientList'
export default {
name: 'GroupModuleGroupView',
- props: ['tabIndex'],
+ props: ['tabIndex', 'group'],
components: {
GroupModuleGroupList,
GroupModuleClientList
@@ -100,44 +99,23 @@ export default {
info: {
name: '',
description: '',
- parents: []
+ parentIds: []
}
}
},
- watch: {
- groupId (v) {
- this.editMode = false
- }
- },
- computed: {
- groupList () {
- return this.$store.state.groups.groupList
- },
- group () {
- return this.$store.state.groups.groupChain[this.tabIndex]
- },
- groupId () {
- return this.group.id
- },
- chipColor () {
- return this.$store.state.settings.dark ? 'grey darken-1' : 'white'
- },
- chipTextColor () {
- return this.$store.state.settings.dark ? 'white' : 'black'
- }
- },
methods: {
removeParent (id) {
- this.info.parents.splice(this.info.parents.indexOf(id), 1)
+ this.info.parentIds.splice(this.info.parentIds.indexOf(id), 1)
},
editInfo () {
this.editMode = true
this.info.name = this.group.name
this.info.description = this.group.description
- this.info.parents = this.group.parents.map(x => x.id)
+ this.info.parentIds = this.group.parents.map(x => x.id)
},
saveInfo () {
-
+ this.$store.dispatch('groups/saveGroupInfo', { id: this.group.id, info: this.info, tabIndex: this.tabIndex })
+ this.editMode = false
}
}
}
diff --git a/webapp/src/components/GroupModuleHomeView.vue b/webapp/src/components/GroupModuleHomeView.vue
new file mode 100644
index 0000000..eb5b12c
--- /dev/null
+++ b/webapp/src/components/GroupModuleHomeView.vue
@@ -0,0 +1,42 @@
+<i18n>
+{
+ "en": {
+ },
+ "de": {
+ }
+}
+</i18n>
+
+<template>
+ <div>
+ <v-subheader>Groups</v-subheader>
+ <group-module-group-list :tabIndex="0" :groups="home.groups" />
+ <v-subheader>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'
+
+export default {
+ name: 'GroupModuleHomeView',
+ props: ['home'],
+ components: {
+ GroupModuleGroupList,
+ GroupModuleClientList
+ },
+ data () {
+ return {
+ }
+ }
+}
+</script>
+
+<!-- Add "scoped" attribute to limit CSS to this component only -->
+<style scoped>
+.info-input {
+ margin: 10px;
+}
+</style>
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')
})
}
}