summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/api/clients.js99
-rw-r--r--server/api/configurator.js125
-rw-r--r--server/api/groups.js177
-rw-r--r--server/app.js6
-rw-r--r--server/lib/grouputil.js21
-rw-r--r--server/package-lock.json5
-rw-r--r--server/package.json1
-rw-r--r--webapp/src/components/ComponentSearchTable.vue6
-rw-r--r--webapp/src/components/ConfiguratorModuleConfig.vue16
-rw-r--r--webapp/src/components/ConfiguratorModuleDelete.vue2
-rw-r--r--webapp/src/components/ConfiguratorModuleEntry.vue4
-rw-r--r--webapp/src/components/GroupModule.vue2
-rw-r--r--webapp/src/components/GroupModuleClientView.vue10
-rw-r--r--webapp/src/components/GroupModuleGroupView.vue10
-rw-r--r--webapp/src/main.js3
-rw-r--r--webapp/src/store/groups.js33
-rw-r--r--webapp/src/store/registration.js2
17 files changed, 291 insertions, 231 deletions
diff --git a/server/api/clients.js b/server/api/clients.js
index 147314d..35c2648 100644
--- a/server/api/clients.js
+++ b/server/api/clients.js
@@ -3,50 +3,63 @@ var path = require('path')
var db = require(path.join(__appdir, 'lib', 'sequelize'))
var io = require(path.join(__appdir, 'lib', 'socketio'))
const backendHelper = require(path.join(__appdir, 'lib', 'external-backends', 'backendhelper'))
+var express = require('express')
+const { decorateApp } = require('@awaitjs/express');
+var router = decorateApp(express.Router())
-// GET Requests
-module.exports.get = {
- getList: function (req, res) {
- db.client.findAll({ attributes: ['id', 'name'], order: [['name', 'ASC']] }).then(list => {
- res.send(list)
- })
- },
-
- // 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 => {
- if (client) res.send(client)
- else res.status(404).end()
- })
- }
-}
-
-// POST Requests
-module.exports.post = {
- // create client or update information of a client (returns id)
- save: function (req, res) {
- 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: req.body.id }) })
- } else { res.status(404).end() }
- })
- } else {
- db.client.create(req.body.info).then(client => {
- io.in('broadcast newClient').emit('notifications newAlert', { type: 'info', text: 'New client!' })
- if (req.body.groupIds) client.setGroups(req.body.groupIds).then(() => { res.send({ id: client.id }) })
- })
- }
- },
+// ############################################################################
+// ########################### GET requests #################################
+
+router.getAsync('', async (req, res) => {
+ const clients = await db.client.findAll({ order: [['name', 'ASC']] })
+ res.send(clients)
+})
- // delete clients
- delete: async function (req, res) {
+router.getAsync('/:id', async (req, res) => {
+ const client = await db.client.findOne({ where: { id: req.params.id }, include: ['groups'] })
+ console.log(req.params.id)
+ if (client) res.status(200).send(client)
+ else res.status(404).end()
+})
+
+// ############################################################################
+// ########################## POST requests #################################
+
+router.postAsync(['', '/:id'], async (req, res) => {
+ if (req.query.delete !== undefined && req.query.delete !== 'false') {
await backendHelper.deleteClients(req.body.ids)
- db.client.destroy({ where: { id: req.body.ids } }).then(count => {
- res.send({ count })
- })
+ const count = await db.client.destroy({ where: { id: req.body.ids } })
+ res.status(200).send({ count })
+ } else {
+ let client
+ if (req.params.id === undefined) {
+ client = await db.client.create(req.body.data)
+ io.in('broadcast newClient').emit('notifications newAlert', { type: 'info', text: 'New client!' })
+ }
+ else {
+ client = await db.client.findOne({ where: { id: req.params.id } })
+ console.log('asd')
+ if (client) await client.update(req.body.data)
+ }
+ if (client) {
+ await client.setGroups(req.body.groupIds)
+ res.status(200).send({ id: client.id })
+ } else {
+ res.status(404).end()
+ }
}
-}
+})
+
+// ############################################################################
+// ########################## DELETE requests ###############################
+
+router.delete('/:id', async (req, res) => {
+ const count = await db.client.destroy({ where: { id: req.params.id } })
+ if (count) res.status(200).end()
+ else res.status(404).end()
+})
+
+// ############################################################################
+// ############################################################################
+
+module.exports.router = router
diff --git a/server/api/configurator.js b/server/api/configurator.js
index 250471b..d0e4531 100644
--- a/server/api/configurator.js
+++ b/server/api/configurator.js
@@ -1,79 +1,98 @@
/* global __appdir */
var path = require('path')
var db = require(path.join(__appdir, 'lib', 'sequelize'))
+var Sequelize = require('sequelize')
var express = require('express')
-var router = express.Router()
+const { decorateApp } = require('@awaitjs/express');
+var router = decorateApp(express.Router())
-router.get('/configs', (req, res) => {
- db.config.findAll().then(configs => {
- res.send(configs)
- })
+// ############################################################################
+// ########################### GET requests #################################
+
+router.getAsync('/configs', async (req, res) => {
+ const configs = await db.config.findAll({ order: [['name', 'ASC']] })
+ res.status(200).send(configs)
})
-router.get('/entries', (req, res) => {
- db.entry.findAll().then(entries => {
- res.send(entries)
- })
+router.getAsync('/entries', async (req, res) => {
+ const entries = await db.entry.findAll({ order: [['name', 'ASC']] })
+ res.status(200).send(entries)
})
-router.get('/configs/:id/entries', async (req, res) => {
- var config = await db.config.findOne({ where: { id: req.params.id } })
- var entries = await config.getEntries({ order: [[['entries'], 'sortValue', 'ASC']] })
- res.send(entries)
+router.getAsync('/configs/:id/entries', async (req, res) => {
+ var config = await db.config.findOne({
+ where: { id: req.params.id }, include: ['entries'],
+ order: [[db.config.associations.entries, db.config.associations.entries.through, 'sortValue', 'ASC']]
+ })
+ if (config) res.status(200).send(config.entries)
+ else res.status(404).end()
})
-router.post(['/configs', '/configs/:id'], async (req, res) => {
- var item = {
- name: req.body.name,
- description: req.body.description,
- defaultEntry: req.body.defaultEntry,
- timeout: req.body.timeout > 0 ? req.body.timeout : null,
- script: req.body.script
- }
+// ############################################################################
+// ########################## POST requests #################################
- var config = null
- if (req.params.id > 0) {
- config = await db.config.findOne({ where: { id: req.params.id } })
- if (config) await config.update(item)
+router.postAsync(['/configs', '/configs/:id'], async (req, res) => {
+ if (req.query.delete !== undefined && req.query.delete !== 'false') {
+ const count = await db.config.destroy({ where: { id: req.body.ids } })
+ res.status(200).send({ count })
} else {
- config = await db.config.create(item)
- }
-
- if (config) {
- await config.setEntries([])
- if (req.body.entries.length > 0) {
- var promises = []
- req.body.entries.forEach((entry, index) => {
- promises.push(config.addEntry(entry.id, { through: { sortValue: index, customName: entry.customName, keyBind: entry.keyBind } }))
- })
- await Promise.all(promises)
+ let config
+ if (req.params.id === undefined) config = await db.config.create(req.body.data)
+ else {
+ config = await db.config.findOne({ where: { id: req.params.id } })
+ if (config) await config.update(req.body.data)
+ }
+ if (config) {
+ await config.setEntries([])
+ if (req.body.entries.length > 0) {
+ const promises = []
+ req.body.entries.forEach((entry, index) => {
+ promises.push(config.addEntry(entry.id, { through: { sortValue: index, customName: entry.customName, keyBind: entry.keyBind } }))
+ })
+ await Promise.all(promises)
+ }
+ res.status(200).send({ id: config.id })
+ } else {
+ res.status(404).end()
}
- res.send({ id: config.id })
}
- res.end()
})
-router.post(['/entries', '/entries/:id'], async (req, res) => {
- var item = { name: req.body.name, script: req.body.script }
- var entry = null
- if (req.params.id > 0) {
- entry = await db.entry.findOne({ where: { id: req.params.id } })
- if (entry) await entry.update(item)
+router.postAsync(['/entries', '/entries/:id'], async (req, res) => {
+ if (req.query.delete !== undefined && req.query.delete !== 'false') {
+ const count = await db.entry.destroy({ where: { id: req.body.ids } })
+ res.status(200).send({ count })
} else {
- entry = await db.entry.create(item)
- }
- if (entry) {
- res.send({ id: entry.id })
+ let entry
+ if (req.params.id === undefined) entry = await db.entry.create(req.body.data)
+ else {
+ entry = await db.entry.findOne({ where: { id: req.params.id } })
+ if (entry) await entry.update(req.body.data)
+ }
+ if (entry) {
+ res.status(200).send({ id: entry.id })
+ } else {
+ res.status(404).end()
+ }
}
- res.end()
})
-router.post('/delete/configs', (req, res) => {
- db.config.destroy({ where: { id: req.body.ids } }).then(count => { res.send({ count }) })
+// ############################################################################
+// ########################## DELETE requests ###############################
+
+router.deleteAsync('/configs/:id', async (req, res) => {
+ const count = await db.config.destroy({ where: { id: req.params.id } })
+ if (count) res.status(200).end()
+ else res.status(404).end()
})
-router.post('/delete/entries', (req, res) => {
- db.entry.destroy({ where: { id: req.body.ids } }).then(count => { res.send({ count }) })
+router.deleteAsync('/entries/:id', async (req, res) => {
+ const count = await db.entry.destroy({ where: { id: req.params.id } })
+ if (count) res.status(200).end()
+ else res.status(404).end()
})
+// ############################################################################
+// ############################################################################
+
module.exports.router = router
diff --git a/server/api/groups.js b/server/api/groups.js
index ddaed18..f1825cc 100644
--- a/server/api/groups.js
+++ b/server/api/groups.js
@@ -1,111 +1,102 @@
/* global __appdir */
var path = require('path')
var db = require(path.join(__appdir, 'lib', 'sequelize'))
+var groupUtil = require(path.join(__appdir, 'lib', 'grouputil'))
+var express = require('express')
+const { decorateApp } = require('@awaitjs/express');
+var router = decorateApp(express.Router())
-async function getAllChildren (groups, knownGroupIds = []) {
- groups = groups.filter(subgroup => !knownGroupIds.includes(subgroup.id))
- var groupIds = groups.map(g => g.id)
- knownGroupIds = [...knownGroupIds, ...groupIds]
- var [subgroups, clients] = await Promise.all([
- db.group.findAll({ where: { '$parents.id$': groupIds }, include: ['parents'] }),
- db.client.findAll({ where: { '$groups.id$': groupIds }, include: ['groups'] })
- ])
- if (subgroups.length > 0) {
- var subChildren = await getAllChildren(subgroups, knownGroupIds)
- subgroups = [...subgroups, ...subChildren.subgroups]
- clients = [...clients, ...subChildren.clients]
+// ############################################################################
+// ########################### GET requests #################################
+
+router.getAsync('', async (req, res) => {
+ const groups = await db.group.findAll({ order: [['name', 'ASC']] })
+ res.send(groups)
+})
+
+router.getAsync('/:id', async (req, res) => {
+ const all = req.query.all !== undefined && req.query.all !== 'false'
+ if (req.params.id > 0) {
+ const group = await db.group.findOne({ where: { id: req.params.id }, include: ['parents', 'subgroups', 'clients'] })
+ if (group) {
+ if (all) res.status(200).send({ ...group.get({ plain: true }), ...await groupUtil.getAllChildren([group]) })
+ else res.status(200).send(group)
+ } else {
+ res.status(404).end()
+ }
+ } else {
+ const [subgroups, clients] = await Promise.all([
+ db.group.findAll(all ? {} : { where: { '$parents.id$': null }, include: ['parents'] }),
+ db.client.findAll(all ? {} : { where: { '$groups.id$': null }, include: ['groups'] })
+ ])
+ res.send({ id: 0, subgroups, clients })
}
- return { subgroups, clients }
-}
+})
+
-// 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', 'description'], order: [['name', 'ASC']] }).then(list => {
- res.send(list)
- })
- },
+// ############################################################################
+// ########################## POST requests #################################
- // get name, description, parents, subgroups and clients of a group (by id)
- getGroup: function (req, res) {
- const all = req.query.all === 'true'
- if (req.query.id > 0) {
- db.group.findOne({ where: { id: req.query.id }, include: ['parents', 'subgroups', 'clients'] }).then(async group => {
- if (group) {
- if (all) res.send({ ...group.get({ plain: true }), ...await getAllChildren([group]) })
- else res.send(group)
- } else {
- res.status(404).end()
- }
- })
+router.postAsync(['', '/:id'], async (req, res) => {
+ if (req.query.delete !== undefined && req.query.delete !== 'false') {
+ const count = await db.group.destroy({ where: { id: req.body.ids } })
+ res.status(200).send({ count })
+ } else {
+ let group
+ if (req.params.id === undefined) group = await db.group.create(req.body.data)
+ else {
+ group = await db.group.findOne({ where: { id: req.params.id } })
+ if (group) await group.update(req.body.data)
+ }
+ if (group) {
+ await group.setParents(req.body.parentIds)
+ res.status(200).send({ id: group.id })
} 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] })
- })
+ res.status(404).end()
}
}
-}
+})
-// POST Requests
-module.exports.post = {
- // create group or update information of a group (returns id)
- save: function (req, res) {
- 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: req.body.id }) })
- } else { res.status(404).end() }
- })
+router.postAsync('/:id/subgroups', async (req, res) => {
+ const group = await db.group.findOne({ where: { id: req.params.id } })
+ if (group) {
+ if (req.query.delete !== undefined && req.query.delete !== 'false') {
+ const count = await group.removeSubgroups(req.body.ids)
+ res.status(200).send({ count })
} else {
- db.group.create(req.body.info).then(group => {
- if (req.body.parentIds) group.setParents(req.body.parentIds).then(() => { res.send({ id: group.id }) })
- })
+ const count = await group.addSubgroups(req.body.ids)
+ res.status(200).send({ count })
}
- },
+ } else {
+ res.status(404).end()
+ }
+})
- // delete groups
- delete: function (req, res) {
- db.group.destroy({ where: { id: req.body.ids } }).then(count => { res.send({ count }) })
- },
+router.postAsync('/:id/clients', async (req, res) => {
+ const group = await db.group.findOne({ where: { id: req.params.id } })
+ if (group) {
+ if (req.query.delete !== undefined && req.query.delete !== 'false') {
+ const count = await group.removeClients(req.body.ids)
+ res.status(200).send({ count })
+ } else {
+ const count = await group.addClients(req.body.ids)
+ res.status(200).send({ count })
+ }
+ } else {
+ res.status(404).end()
+ }
+})
- // remove subgroups from a group
- removeSubgroups: function (req, res) {
- db.group.findOne({ where: { id: req.body.id } }).then(group => {
- if (group) {
- group.removeSubgroups(req.body.ids).then(() => { res.end() })
- } else { res.status(404).end() }
- })
- },
+// ############################################################################
+// ########################## DELETE requests ###############################
- // remove clients from a group
- removeClients: function (req, res) {
- db.group.findOne({ where: { id: req.body.id } }).then(group => {
- if (group) {
- group.removeClients(req.body.ids).then(() => { res.end() })
- } else { res.status(404).end() }
- })
- },
+router.delete('/:id', async (req, res) => {
+ const count = await db.group.destroy({ where: { id: req.params.id } })
+ if (count) res.status(200).end()
+ else res.status(404).end()
+})
- // add subgroups to a group
- addSubgroups: function (req, res) {
- db.group.findOne({ where: { id: req.body.id } }).then(group => {
- if (group) {
- group.addSubgroups(req.body.ids).then(() => { res.end() })
- } else { res.status(404).end() }
- })
- },
+// ############################################################################
+// ############################################################################
- // add clients to a group
- addClients: function (req, res) {
- db.group.findOne({ where: { id: req.body.id } }).then(group => {
- if (group) {
- group.addClients(req.body.ids).then(() => { res.end() })
- } else { res.status(404).end() }
- })
- }
-}
+module.exports.router = router
diff --git a/server/app.js b/server/app.js
index 4e72fa5..d026337 100644
--- a/server/app.js
+++ b/server/app.js
@@ -1,12 +1,10 @@
+var path = require('path')
var createError = require('http-errors')
var express = require('express')
var cookieParser = require('cookie-parser')
var compression = require('compression')
var fileUpload = require('express-fileupload')
-var path = require('path')
-// var fs = require('fs')
-
var app = express()
global.__appdir = __dirname
@@ -45,6 +43,8 @@ app.use(function (req, res, next) {
// error handler
app.use(function (err, req, res, next) {
+ console.log(err)
+
// set locals, only providing error in development
res.locals.message = err.message
res.locals.error = req.app.get('env') === 'development' ? err : {}
diff --git a/server/lib/grouputil.js b/server/lib/grouputil.js
new file mode 100644
index 0000000..311eb7e
--- /dev/null
+++ b/server/lib/grouputil.js
@@ -0,0 +1,21 @@
+/* global __appdir */
+var path = require('path')
+var db = require(path.join(__appdir, 'lib', 'sequelize'))
+
+async function getAllChildren (groups, knownGroupIds = []) {
+ groups = groups.filter(subgroup => !knownGroupIds.includes(subgroup.id))
+ var groupIds = groups.map(g => g.id)
+ knownGroupIds = [...knownGroupIds, ...groupIds]
+ var [subgroups, clients] = await Promise.all([
+ db.group.findAll({ where: { '$parents.id$': groupIds }, include: ['parents'] }),
+ db.client.findAll({ where: { '$groups.id$': groupIds }, include: ['groups'] })
+ ])
+ if (subgroups.length > 0) {
+ var subChildren = await getAllChildren(subgroups, knownGroupIds)
+ subgroups = [...subgroups, ...subChildren.subgroups]
+ clients = [...clients, ...subChildren.clients]
+ }
+ return { subgroups, clients }
+}
+
+module.exports.getAllChildren = getAllChildren \ No newline at end of file
diff --git a/server/package-lock.json b/server/package-lock.json
index 14fe543..25133c1 100644
--- a/server/package-lock.json
+++ b/server/package-lock.json
@@ -4,6 +4,11 @@
"lockfileVersion": 1,
"requires": true,
"dependencies": {
+ "@awaitjs/express": {
+ "version": "0.1.4",
+ "resolved": "https://registry.npmjs.org/@awaitjs/express/-/express-0.1.4.tgz",
+ "integrity": "sha512-ueg4Nh3dr+/Djm8tequ9lwwT6a3QsjFzxQ2Mh3rAdF3FTe5FV4L/5ip42bVOB5aBIcFsrOU18eG4TX+OWXLS8g=="
+ },
"@babel/code-frame": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0.tgz",
diff --git a/server/package.json b/server/package.json
index 78ed4e6..9f46c0c 100644
--- a/server/package.json
+++ b/server/package.json
@@ -7,6 +7,7 @@
"start": "node ./bin/www"
},
"dependencies": {
+ "@awaitjs/express": "^0.1.4",
"axios": "^0.18.0",
"compression": "^1.7.3",
"cookie-parser": "^1.4.3",
diff --git a/webapp/src/components/ComponentSearchTable.vue b/webapp/src/components/ComponentSearchTable.vue
index 23aa071..e9101dc 100644
--- a/webapp/src/components/ComponentSearchTable.vue
+++ b/webapp/src/components/ComponentSearchTable.vue
@@ -36,10 +36,12 @@
class="rows-per-page-select body-1"
v-model="pagination.rowsPerPage"
:items="rowsPerPageItems.concat({ text: $t('all'), value: -1 })"
- offset-y
color="primary"
hide-details
- content-class="search-table-rows-per-page-select-content"
+ :menu-props="{
+ offsetY: '',
+ contentClass: 'search-table-rows-per-page-select-content'
+ }"
></v-select>
</v-flex>
<v-flex md4 sm6 xs12 offset-md0 offset-sm1 offset-xs0 order-md3 order-sm2 order-xs2
diff --git a/webapp/src/components/ConfiguratorModuleConfig.vue b/webapp/src/components/ConfiguratorModuleConfig.vue
index b8bb793..4381ab8 100644
--- a/webapp/src/components/ConfiguratorModuleConfig.vue
+++ b/webapp/src/components/ConfiguratorModuleConfig.vue
@@ -167,12 +167,16 @@ export default {
this.items.splice(this.items.indexOf(item), 1)
},
async saveConfig () {
- await axios.post('/api/configurator/configs/' + this.dialog.info.id, {
- name: this.name,
- description: this.description,
- defaultEntry: this.defaultEntry,
- timeout: this.timeout,
- script: this.script,
+ let url = '/api/configurator/configs'
+ if (this.dialog.info.id !== undefined) url += '/' + this.dialog.info.id
+ await axios.post(url, {
+ data: {
+ name: this.name,
+ description: this.description,
+ defaultEntry: this.defaultEntry,
+ timeout: this.timeout,
+ script: this.script
+ },
entries: this.items.map(x => ({
id: x.entry.id,
customName: x.customName,
diff --git a/webapp/src/components/ConfiguratorModuleDelete.vue b/webapp/src/components/ConfiguratorModuleDelete.vue
index dc9fe72..d630524 100644
--- a/webapp/src/components/ConfiguratorModuleDelete.vue
+++ b/webapp/src/components/ConfiguratorModuleDelete.vue
@@ -44,7 +44,7 @@ export default {
this.$store.commit('configurator/setDialog', data)
},
async deleteItems () {
- await axios.post('/api/configurator/delete/' + this.dialog.info.itemType, {
+ await axios.post('/api/configurator/' + this.dialog.info.itemType + '/?delete', {
ids: this.dialog.info.selected.map(x => x.id)
})
this.$store.dispatch('configurator/loadData')
diff --git a/webapp/src/components/ConfiguratorModuleEntry.vue b/webapp/src/components/ConfiguratorModuleEntry.vue
index 3bb03a3..01e2fd1 100644
--- a/webapp/src/components/ConfiguratorModuleEntry.vue
+++ b/webapp/src/components/ConfiguratorModuleEntry.vue
@@ -72,7 +72,9 @@ export default {
this.$store.commit('configurator/setDialog', data)
},
async saveEntry () {
- await axios.post('/api/configurator/entries/' + this.dialog.info.id, {
+ let url = '/api/configurator/entries'
+ if (this.dialog.info.id !== undefined) url += '/' + this.dialog.info.id
+ await axios.post(url, {
name: this.name,
script: this.script
})
diff --git a/webapp/src/components/GroupModule.vue b/webapp/src/components/GroupModule.vue
index 17531db..cc34350 100644
--- a/webapp/src/components/GroupModule.vue
+++ b/webapp/src/components/GroupModule.vue
@@ -12,7 +12,7 @@
<v-layout>
<v-flex class="tabs-wrapper" xl10 offset-xl1 lg12>
<v-card class="tabbar-card">
- <v-tabs :value="activeTab" @input="setActiveTab" :dark="tabsDark" :color="tabsColor" :slider-color="tabsSliderColor">
+ <v-tabs :value="activeTab" @change="setActiveTab" :dark="tabsDark" :color="tabsColor" :slider-color="tabsSliderColor">
<template v-for="(item, index) in tabChain">
<v-icon v-if="item.id > 0 || item.id === 'create'" :key="'arrow' + index">keyboard_arrow_right</v-icon>
<v-tab ripple :key="'tab' + index">
diff --git a/webapp/src/components/GroupModuleClientView.vue b/webapp/src/components/GroupModuleClientView.vue
index cd8af9c..03c3b77 100644
--- a/webapp/src/components/GroupModuleClientView.vue
+++ b/webapp/src/components/GroupModuleClientView.vue
@@ -43,7 +43,7 @@
class="info-input"
:items="$store.state.groups.groupList"
v-model="groupIds"
- offset-y
+ :menu-props="{ offsetY: '' }"
:label="$t('groups')"
color="primary"
multiple
@@ -66,7 +66,7 @@
</div>
</v-flex>
<v-flex>
- <v-select v-if="editMode" class="info-input" prepend-icon="list" clearable item-text="name" item-value="id" offset-y :label="$t('config')" color="primary" v-model="info.configId" :items="configList"></v-select>
+ <v-select v-if="editMode" class="info-input" prepend-icon="list" clearable item-text="name" item-value="id" :menu-props="{ offsetY: '' }" :label="$t('config')" color="primary" v-model="info.configId" :items="configList"></v-select>
<div v-else class="info-input">
<div class="body-2 info-heading"><v-icon>list</v-icon><span>{{ $t('config') }}</span></div>
<div class="info-text">{{ configName || '-' }}</div>
@@ -88,7 +88,7 @@
</v-btn>
<div v-else>
<v-btn color="primary" flat @click="cancelEdit" class="info-buttons">{{ $t('cancel') }}</v-btn>
- <v-btn color="primary" @click="saveInfo" class="info-buttons">
+ <v-btn color="primary" @click="saveData" class="info-buttons">
<v-icon left>save</v-icon>{{ $t('save') }}
</v-btn>
</div>
@@ -176,11 +176,11 @@ export default {
this.$store.commit('groups/setActiveTab', this.tabIndex - 1)
}
},
- saveInfo () {
+ saveData () {
this.info.configId = this.info.configId === undefined ? null : this.info.configId
this.$store.dispatch('groups/saveClient', {
id: this.client.id,
- info: this.info,
+ data: this.info,
groupIds: this.groupIds,
tabIndex: this.tabIndex,
callback: this.updateUrl
diff --git a/webapp/src/components/GroupModuleGroupView.vue b/webapp/src/components/GroupModuleGroupView.vue
index 6764bef..383bfec 100644
--- a/webapp/src/components/GroupModuleGroupView.vue
+++ b/webapp/src/components/GroupModuleGroupView.vue
@@ -47,7 +47,7 @@
class="info-input"
:items="$store.state.groups.groupList"
v-model="parentIds"
- offset-y
+ :menu-props="{ offsetY: '' }"
:label="$t('parents')"
color="primary"
multiple
@@ -70,7 +70,7 @@
</div>
</v-flex>
<v-flex>
- <v-select v-if="editMode" class="info-input" prepend-icon="list" clearable item-text="name" item-value="id" offset-y :label="$t('config')" color="primary" v-model="info.configId" :items="configList"></v-select>
+ <v-select v-if="editMode" class="info-input" prepend-icon="list" clearable item-text="name" item-value="id" :menu-props="{ offsetY: '' }" :label="$t('config')" color="primary" v-model="info.configId" :items="configList"></v-select>
<div v-else class="info-input">
<div class="body-2 info-heading"><v-icon>list</v-icon><span>{{ $t('config') }}</span></div>
<div class="info-text">{{ configName || '-' }}</div>
@@ -92,7 +92,7 @@
</v-btn>
<div v-else>
<v-btn color="primary" flat @click="cancelEdit" class="info-buttons">{{ $t('cancel') }}</v-btn>
- <v-btn color="primary" @click="saveInfo" class="info-buttons">
+ <v-btn color="primary" @click="saveData" class="info-buttons">
<v-icon left>save</v-icon>{{ $t('save') }}
</v-btn>
</div>
@@ -179,11 +179,11 @@ export default {
this.$store.commit('groups/setActiveTab', this.tabIndex - 1)
}
},
- saveInfo () {
+ saveData () {
this.info.configId = this.info.configId === undefined ? null : this.info.configId
this.$store.dispatch('groups/saveGroup', {
id: this.group.id,
- info: this.info,
+ data: this.info,
parentIds: this.parentIds,
tabIndex: this.tabIndex,
callback: this.updateUrl
diff --git a/webapp/src/main.js b/webapp/src/main.js
index d8a46a0..d7ee839 100644
--- a/webapp/src/main.js
+++ b/webapp/src/main.js
@@ -62,7 +62,8 @@ axios.interceptors.response.use(null, error => {
})
const socket = io({
- autoConnect: false
+ autoConnect: false,
+ transports: ['websocket']
})
socket.on('error', err => {
diff --git a/webapp/src/store/groups.js b/webapp/src/store/groups.js
index 7905fe4..8f50978 100644
--- a/webapp/src/store/groups.js
+++ b/webapp/src/store/groups.js
@@ -50,7 +50,7 @@ export default {
})
},
loadLists (context) {
- Promise.all([axios.get('/api/groups/getList'), axios.get('/api/clients/getList')]).then(res => {
+ Promise.all([axios.get('/api/groups'), axios.get('/api/clients')]).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 })))
})
@@ -67,7 +67,7 @@ export default {
}
context.commit('setTabLoading', tabIndex)
if (switchTab) context.commit('setActiveTab', tabIndex)
- axios.get('/api/groups/getGroup?id=' + id + (showAll ? '&all=true' : '')).then(res => {
+ axios.get('/api/groups/' + id + (showAll ? '?all' : '')).then(res => {
res.data.tabType = 'group'
res.data.tabShowAll = showAll
context.commit('setTab', { index: tabIndex, item: res.data })
@@ -86,7 +86,7 @@ export default {
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 => {
+ axios.get('/api/clients/' + id).then(res => {
res.data.tabType = 'client'
context.commit('setTab', { index: tabIndex, item: res.data })
}).catch(err => {
@@ -103,12 +103,12 @@ export default {
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 => {
+ saveGroup (context, { id, data, parentIds, tabIndex, callback }) {
+ const url = id === 'create' ? '/api/groups' : '/api/groups/' + id
+ axios.post(url, { data, parentIds }).then(res => {
if (res.data.id) {
- console.log(res.data.id)
if (callback) callback(res.data.id)
- context.commit('setTab', { index: tabIndex, item: { id: res.data.id, name: info.name, tabType: 'group' } })
+ context.commit('setTab', { index: tabIndex, item: { id: res.data.id, name: data.name, tabType: 'group', subgroups: [], clients: [] } })
if (parentIds && tabIndex > 1 && !parentIds.includes(context.state.tabChain[tabIndex - 1].id)) {
context.commit('deleteFromTabChain', { index: 1, count: tabIndex - 1 })
context.commit('setActiveTab', 1)
@@ -117,11 +117,12 @@ export default {
}
})
},
- saveClient (context, { id, info, groupIds, tabIndex, callback }) {
- axios.post('/api/clients/save', { id, info, groupIds }).then(res => {
+ saveClient (context, { id, data, groupIds, tabIndex, callback }) {
+ const url = id === 'create' ? '/api/clients' : '/api/clients/' + id
+ axios.post(url, { data, groupIds }).then(res => {
if (res.data.id) {
if (callback) callback(res.data.id)
- context.commit('setTab', { index: tabIndex, item: { id: res.data.id, name: info.name, tabType: 'client' } })
+ context.commit('setTab', { index: tabIndex, item: { id: res.data.id, name: data.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)
@@ -132,7 +133,7 @@ export default {
},
deleteGroups (context, { selected, callback }) {
const ids = selected.map(x => x.id)
- axios.post('/api/groups/delete', { ids }).then(() => {
+ 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)) {
@@ -147,7 +148,7 @@ export default {
},
deleteClients (context, { selected, callback }) {
const ids = selected.map(x => x.id)
- axios.post('/api/clients/delete', { ids }).then(() => {
+ 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 })
@@ -158,7 +159,7 @@ export default {
removeSubroups (context, { tabIndex, selected, callback }) {
const id = context.state.tabChain[tabIndex].id
const ids = selected.map(x => x.id)
- axios.post('/api/groups/removeSubgroups', { id, ids }).then(() => {
+ axios.post('/api/groups/' + id + '/subgroups/?delete', { ids }).then(() => {
if (context.state.tabChain.length > tabIndex + 1 &&
context.state.tabChain[tabIndex + 1].tabType === 'group' &&
ids.includes(context.state.tabChain[tabIndex + 1].id)) {
@@ -171,7 +172,7 @@ export default {
removeClients (context, { tabIndex, selected, callback }) {
const id = context.state.tabChain[tabIndex].id
const ids = selected.map(x => x.id)
- axios.post('/api/groups/removeClients', { id, ids }).then(() => {
+ axios.post('/api/groups/' + id + '/clients/?delete', { ids }).then(() => {
if (context.state.tabChain.length > tabIndex + 1 &&
context.state.tabChain[tabIndex + 1].tabType === 'client' &&
ids.includes(context.state.tabChain[tabIndex + 1].id)) {
@@ -184,7 +185,7 @@ export default {
addSubgroups (context, { tabIndex, selected, callback }) {
const id = context.state.tabChain[tabIndex].id
const ids = selected.map(x => x.id)
- axios.post('/api/groups/addSubgroups', { id, ids }).then(() => {
+ axios.post('/api/groups/' + id + '/subgroups', { ids }).then(() => {
context.dispatch('reload')
if (callback) callback()
})
@@ -192,7 +193,7 @@ export default {
addClients (context, { tabIndex, selected, callback }) {
const id = context.state.tabChain[tabIndex].id
const ids = selected.map(x => x.id)
- axios.post('/api/groups/addClients', { id, ids }).then(() => {
+ axios.post('/api/groups/' + id + '/clients', { ids }).then(() => {
context.dispatch('reload')
if (callback) callback()
})
diff --git a/webapp/src/store/registration.js b/webapp/src/store/registration.js
index 388558d..8d1882f 100644
--- a/webapp/src/store/registration.js
+++ b/webapp/src/store/registration.js
@@ -27,7 +27,7 @@ export default {
})
},
loadGroupList (context) {
- axios.get('/api/groups/getList').then(result => {
+ axios.get('/api/groups').then(result => {
context.commit('setGroupList', result.data)
})
},