From 4752614c0105b864d00e97179b4b77ccbad89e2d Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Wed, 16 Oct 2019 19:16:14 +0000 Subject: [webapp/clients] Add the choice to select backends when deleting clients [group/clients] Checkbox list of the clients in the permanently delete dialog [server/backendhelper] Only deletes from the selected backends (array with backendids) --- server/api/clients.js | 2 +- server/lib/external-backends/backendhelper.js | 10 ++++++++-- webapp/src/components/GroupModuleDialog.vue | 25 +++++++++++++++++++++++-- webapp/src/store/groups.js | 5 +++-- 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/server/api/clients.js b/server/api/clients.js index a6d151a..d72207b 100644 --- a/server/api/clients.js +++ b/server/api/clients.js @@ -29,7 +29,7 @@ router.getAsync('/:id', async (req, res) => { router.postAsync(['', '/:id'], async (req, res) => { if (req.query.delete !== undefined && req.query.delete !== 'false') { if (!Array.isArray(req.body.ids)) return HttpResponse.invalidBodyValue('ids', 'an array').send(res) - await backendHelper.deleteClients(req.body.ids) + await backendHelper.deleteClients(req.body.ids, req.body.backendIds) const count = await db.client.destroy({ where: { id: req.body.ids } }) HttpResponse.successBatch('deleted', 'client', count).send(res) } else { diff --git a/server/lib/external-backends/backendhelper.js b/server/lib/external-backends/backendhelper.js index 7e682d1..485b5f6 100644 --- a/server/lib/external-backends/backendhelper.js +++ b/server/lib/external-backends/backendhelper.js @@ -116,9 +116,15 @@ async function updateClient (client) { return result } -async function deleteClients (clientids) { +async function deleteClients (clientids, backendIds) { // Get all backends and call deleteClient for each instance. - const backends = await db.backend.findAll({ where: { '$clientMappings.clientid$': clientids }, include: ['clientMappings'] }) + const backends = await db.backend.findAll({ + where: { + id: { [db.Op.in]: backendIds }, + '$clientMappings.clientid$': clientids + }, + include: ['clientMappings'] + }) backends.forEach(backend => { const ba = new ExternalBackends() diff --git a/webapp/src/components/GroupModuleDialog.vue b/webapp/src/components/GroupModuleDialog.vue index e9bb65d..41b98b5 100644 --- a/webapp/src/components/GroupModuleDialog.vue +++ b/webapp/src/components/GroupModuleDialog.vue @@ -45,7 +45,8 @@ "name": "Name", "description": "Description", "ip": "IP Address", - "wake": "Wake up" + "wake": "Wake up", + "deleteInBackends": "Select the backends, where the clients will get deleted:" }, "de": { "title": { @@ -92,7 +93,8 @@ "name": "Name", "description": "Beschreibung", "ip": "IP Adresse", - "wake": "Aufwecken" + "wake": "Aufwecken", + "deleteInBackends": "Wähle die Backends, aus denen die Clients gelöscht werden:" } } @@ -138,6 +140,19 @@ >
[{{ item.id }}] {{ item.name }}
+
+
{{ $t('deleteInBackends') }}
+ +
@@ -183,6 +198,7 @@ export default { }, computed: { ...mapState('groups', ['dialog', 'tabChain']), + ...mapState('backends', ['backends']), headers () { const lastColumn = this.dialog.info.type === 'client' ? 'ip' : 'description' return [ @@ -227,6 +243,7 @@ export default { if (this.dialog.info.action === 'select') this.selected = this.dialog.info.selected else this.selected = [] if (this.$refs.cardtext) this.$nextTick(() => this.$refs.cardtext.dispatchEvent(new Event('scroll'))) + if (this.dialog.info.type === 'client') this.$store.dispatch('backends/loadData') } } } @@ -262,6 +279,7 @@ export default { }) } if (this.action === 'add') data.selected = this.selected + if (this.action === 'delete') data.backends = this.backends this.$store.dispatch('groups/' + actionMap[this.action][this.dialog.info.type], data) this.setDialog({ show: false }) }, @@ -297,4 +315,7 @@ export default { .selected-list { padding: 30px; } +.select-backends { + margin-top: 20px; +} diff --git a/webapp/src/store/groups.js b/webapp/src/store/groups.js index 2785468..7948e31 100644 --- a/webapp/src/store/groups.js +++ b/webapp/src/store/groups.js @@ -193,9 +193,10 @@ export default { if (callback) callback() }) }, - deleteClients (context, { selected, callback }) { + deleteClients (context, { selected, callback, backends }) { const ids = selected.map(x => x.id) - axios.post('/api/clients/?delete', { ids }).then(() => { + const backendIds = backends.filter(x => x.selected).map(x => x.id) + axios.post('/api/clients/?delete', { ids, backendIds }).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 }) -- cgit v1.2.3-55-g7522