From 79a33eb08a36b9540d7fc58f2e1eefb56a1aaf6e Mon Sep 17 00:00:00 2001 From: Udo Walter Date: Tue, 26 Feb 2019 03:28:51 +0000 Subject: [webapp/configurator] add ability to assign configs to groups/clients [server] increase request size limit to 50mb --- server/api/configurator.js | 33 ++++++++- server/app.js | 2 +- server/models/config.js | 4 +- webapp/src/components/ConfiguratorModuleAssign.vue | 84 +++++++++++++++------- webapp/src/components/GroupModuleClientList.vue | 6 +- webapp/src/components/GroupModuleDialog.vue | 16 ++--- webapp/src/components/GroupModuleGroupView.vue | 2 +- 7 files changed, 104 insertions(+), 43 deletions(-) diff --git a/server/api/configurator.js b/server/api/configurator.js index 9ed349d..4ae1f35 100644 --- a/server/api/configurator.js +++ b/server/api/configurator.js @@ -19,7 +19,7 @@ router.getAsync('/entries', async (req, res) => { }) router.getAsync('/configs/:id/entries', async (req, res) => { - var config = await db.config.findOne({ + const config = await db.config.findOne({ where: { id: req.params.id }, include: ['entries'], order: [[db.config.associations.entries, db.config.associations.entries.through, 'sortValue', 'ASC']] @@ -28,6 +28,18 @@ router.getAsync('/configs/:id/entries', async (req, res) => { else res.status(404).end() }) +router.getAsync('/configs/:id/groups', async (req, res) => { + const config = await db.config.findOne({ where: { id: req.params.id }, include: ['groups'] }) + if (config) res.status(200).send(config.groups) + else res.status(404).end() +}) + +router.getAsync('/configs/:id/clients', async (req, res) => { + const config = await db.config.findOne({ where: { id: req.params.id }, include: ['clients'] }) + if (config) res.status(200).send(config.clients) + else res.status(404).end() +}) + // ############################################################################ // ########################## POST requests ################################# @@ -77,6 +89,25 @@ router.postAsync(['/entries', '/entries/:id'], async (req, res) => { } }) +// ############################################################################ +// ########################## POST requests ################################# + +router.putAsync('/configs/:id/groups', async (req, res) => { + const config = await db.config.findOne({ where: { id: req.params.id } }) + if (config) { + await config.setGroups(req.body.ids) + res.status(200).end() + } else { res.status(404).end() } +}) + +router.putAsync('/configs/:id/clients', async (req, res) => { + const config = await db.config.findOne({ where: { id: req.params.id } }) + if (config) { + await config.setClients(req.body.ids) + res.status(200).end() + } else { res.status(404).end() } +}) + // ############################################################################ // ########################## DELETE requests ############################### diff --git a/server/app.js b/server/app.js index d026337..23f1584 100644 --- a/server/app.js +++ b/server/app.js @@ -16,7 +16,7 @@ require('./lib/permissions/index.js') // ########################### setup middleware ############################### app.use(compression()) -app.use(express.json()) +app.use(express.json({ limit: '50mb' })) app.use(express.urlencoded({ extended: false })) var logger = require('morgan') diff --git a/server/models/config.js b/server/models/config.js index aee8892..ae728f6 100644 --- a/server/models/config.js +++ b/server/models/config.js @@ -22,8 +22,8 @@ module.exports = (sequelize, DataTypes) => { keyBind: DataTypes.STRING }, { timestamps: false, freezeTableName: true }) config.belongsToMany(models.entry, { as: 'entries', through: ConfigXEntry, foreignKey: 'configId', otherKey: 'entryId' }) - config.hasMany(models.group) - config.hasMany(models.client) + config.hasMany(models.group, { as: 'groups' }) + config.hasMany(models.client, { as: 'clients' }) } return config } diff --git a/webapp/src/components/ConfiguratorModuleAssign.vue b/webapp/src/components/ConfiguratorModuleAssign.vue index 8c9ba83..af49d45 100644 --- a/webapp/src/components/ConfiguratorModuleAssign.vue +++ b/webapp/src/components/ConfiguratorModuleAssign.vue @@ -5,14 +5,22 @@ "description": "Description", "ip": "IP Address", "title": "Assign groups and clients", - "assign": "Assign" + "assign": "Assign", + "groups": "Groups", + "clients": "Clients", + "success": "Assignment successful.", + "config": "Config" }, "de": { "name": "Name", "description": "Beschreibung", "ip": "IP Adresse", - "title": "Gruppen und Clienten zuweisen", - "assign": "Zuweisen" + "title": "Gruppen und Clients zuweisen", + "assign": "Zuweisen", + "groups": "Gruppen", + "clients": "Clients", + "success": "Zuweisung erfolgreich.", + "config": "Konfiguration" } } @@ -20,17 +28,30 @@ @@ -46,6 +67,7 @@ export default { }, data () { return { + tabs: 0, selectedGroups: [], selectedClients: [] } @@ -70,12 +92,16 @@ export default { dialog: { immediate: true, deep: true, - handler (value) { - if (value.type === 'entry' && value.show) { - this.name = value.info.name || '' - this.script = value.info.script || '' - this.interval.id = setInterval(this.refreshEditor, 50) - this.interval.counter = 0 + async handler (value) { + if (value.show && value.type === 'assign') { + this.selectedGroups = [] + this.selectedClients = [] + const [ groupsResponse, clientsResponse ] = await Promise.all([ + this.$http.get(`/api/configurator/configs/${value.info.id}/groups`), + this.$http.get(`/api/configurator/configs/${value.info.id}/clients`) + ]) + this.selectedGroups = groupsResponse.data + this.selectedClients = clientsResponse.data } } } @@ -84,20 +110,14 @@ export default { setDialog (data) { this.$store.commit('configurator/setDialog', data) }, - async saveEntry () { - let url = '/api/configurator/entries' - if (this.dialog.info.id !== undefined) url += '/' + this.dialog.info.id - await this.$http.post(url, { - name: this.name, - script: this.script - }) - this.$store.dispatch('configurator/loadData') + async saveAssignment () { + let url = '/api/configurator/configs/' + this.dialog.info.id + await Promise.all([ + this.$http.put(url + '/groups', { ids: this.selectedGroups.map(x => x.id) }), + this.$http.put(url + '/clients', { ids: this.selectedClients.map(x => x.id) }) + ]) + this.$snackbar({ color: 'success', text: this.$t('success') }) this.setDialog({ show: false }) - }, - refreshEditor () { - this.interval.counter++ - if (this.$refs.editor) this.$refs.editor.codemirror.refresh() - if (this.interval.counter >= 15) clearInterval(this.interval.id) } } } @@ -109,7 +129,17 @@ export default { z-index: 1; display: flex; flex-direction: column; - align-items: flex-start; + align-items: stretch; + margin: 0; + padding: 0; +} + +.dialog-title >>> .v-tabs .v-tabs__item { + text-transform: none; +} + +.dialog-title-text { + padding: 16px 16px 0 16px; } .dialog-content { diff --git a/webapp/src/components/GroupModuleClientList.vue b/webapp/src/components/GroupModuleClientList.vue index bc2e59a..88d1332 100644 --- a/webapp/src/components/GroupModuleClientList.vue +++ b/webapp/src/components/GroupModuleClientList.vue @@ -17,9 +17,9 @@ "ip": "IP Adresse", "mac": "MAC Adresse", "uuid": "UUID", - "removeClients": "Entferne einen Clienten | Entferne {0} Clienten", - "addClients": "Füge Clienten hinzu", - "deleteClients": "Lösche einen Clienten | Lösche {0} Clienten", + "removeClients": "Entferne einen Client | Entferne {0} Clients", + "addClients": "Füge Clients hinzu", + "deleteClients": "Lösche einen Clients | Lösche {0} Clients", "createClient": "Client erstellen" } } diff --git a/webapp/src/components/GroupModuleDialog.vue b/webapp/src/components/GroupModuleDialog.vue index 4328830..8eb3079 100644 --- a/webapp/src/components/GroupModuleDialog.vue +++ b/webapp/src/components/GroupModuleDialog.vue @@ -47,38 +47,38 @@ "title": { "delete": { "group": "Diese Gruppe löschen? | Diese {0} Gruppen löschen?", - "client": "Diesen Clienten löschen? | Diese {0} Clienten löschen?" + "client": "Diesen Client löschen? | Diese {0} Clients löschen?" }, "remove": { "group": "Diese Untergruppe entfernen? | Diese {0} Untergruppen entfernen?", - "client": "Diesen Clienten entfernen? | Diese {0} Clienten entfernen?" + "client": "Diesen Client entfernen? | Diese {0} Clients entfernen?" }, "add": { "group": "Gruppen hinzufügen | Diese Gruppe hinzufügen? | Diese {0} Gruppen hinzufügen?", - "client": "Clienten hinzufügen | Diesen Clienten hinzufügen? | Diese {0} Clienten hinzufügen?" + "client": "Clients hinzufügen | Diesen Client hinzufügen? | Diese {0} Clients hinzufügen?" }, "select": { "group": "Gruppen auswählen", - "clienten": "Clienten auswählen" + "client": "Clients auswählen" } }, "success": { "delete": { - "client": "Client erfolgreich gelöscht | {0} Clienten erfolgreich gelöscht", + "client": "Client erfolgreich gelöscht | {0} Clients erfolgreich gelöscht", "group": "Gruppe erfolgreich gelöscht | {0} Gruppen erfolgreich gelöscht" }, "remove": { - "client": "Client erfolgreich entfernt | {0} Clienten erfolgreich entfernt", + "client": "Client erfolgreich entfernt | {0} Clients erfolgreich entfernt", "group": "Gruppe erfolgreich entfernt | {0} Gruppen erfolgreich entfernt" }, "add": { - "client": "Client erfolgreich hinzugefügt | {0} Clienten erfolgreich hinzugefügt", + "client": "Client erfolgreich hinzugefügt | {0} Clients erfolgreich hinzugefügt", "group": "Gruppe erfolgreich hinzugefügt | {0} Gruppen erfolgreich hinzugefügt" } }, "deletePermanently": { "group": "Gruppe dauerhaft löschen | Gruppen dauerhaft löschen", - "client": "Client dauerhaft löschen | Clienten dauerhaft löschen" + "client": "Client dauerhaft löschen | Clients dauerhaft löschen" }, "new": "Neu", "id": "ID", diff --git a/webapp/src/components/GroupModuleGroupView.vue b/webapp/src/components/GroupModuleGroupView.vue index 59d57d1..deda78b 100644 --- a/webapp/src/components/GroupModuleGroupView.vue +++ b/webapp/src/components/GroupModuleGroupView.vue @@ -21,7 +21,7 @@ "showall": "Show All", "groups": "Groups", "subgroups": "Untergruppen", - "clients": "Clienten", + "clients": "Clients", "name": "Name", "description": "Beschreibung", "ipranges": "IP Bereiche", -- cgit v1.2.3-55-g7522