From 82648439b945cc5d049886f7e79c2f0dd9d14ff9 Mon Sep 17 00:00:00 2001 From: Udo Walter Date: Mon, 26 Nov 2018 19:12:31 +0000 Subject: [webapp+server] Add first implementation of a websocket to alert webclients of events and to synchronize notification across multiple webapp instances of the same user --- webapp/src/store/groups.js | 18 ++++++++++++------ webapp/src/store/notifications.js | 7 +++++-- 2 files changed, 17 insertions(+), 8 deletions(-) (limited to 'webapp/src/store') diff --git a/webapp/src/store/groups.js b/webapp/src/store/groups.js index 1bbded9..adc78f8 100644 --- a/webapp/src/store/groups.js +++ b/webapp/src/store/groups.js @@ -130,7 +130,7 @@ export default { } }) }, - deleteGroups (context, { selected }) { + deleteGroups (context, { selected, callback }) { const ids = selected.map(x => x.id) axios.post('/api/groups/delete', { ids }).then(() => { var i = 1 @@ -142,18 +142,20 @@ export default { i++ } context.dispatch('reload') + if (callback) callback() }) }, - deleteClients (context, { selected }) { + deleteClients (context, { selected, callback }) { const ids = selected.map(x => x.id) 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 }) context.dispatch('reload') + if (callback) callback() }) }, - removeSubroups (context, { tabIndex, selected }) { + 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(() => { @@ -163,9 +165,10 @@ export default { context.commit('deleteFromTabChain', { index: tabIndex + 1, count: context.state.tabChain.length - (tabIndex + 1) }) } context.dispatch('reload') + if (callback) callback() }) }, - removeClients (context, { tabIndex, selected }) { + 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(() => { @@ -175,20 +178,23 @@ export default { context.commit('deleteFromTabChain', { index: tabIndex + 1, count: 1 }) } context.dispatch('reload') + if (callback) callback() }) }, - addSubgroups (context, { tabIndex, selected }) { + 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(() => { context.dispatch('reload') + if (callback) callback() }) }, - addClients (context, { tabIndex, selected }) { + 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(() => { context.dispatch('reload') + if (callback) callback() }) } } diff --git a/webapp/src/store/notifications.js b/webapp/src/store/notifications.js index 9f41d07..4687b78 100644 --- a/webapp/src/store/notifications.js +++ b/webapp/src/store/notifications.js @@ -23,10 +23,13 @@ export default { state.newAlertCount++ state.alerts.unshift(data) }, - removeAlert (state, a) { + removeAlert (state, id) { + const a = state.alerts.find(el => el.id === id) a.show = false setTimeout(function () { - state.alerts.splice(state.alerts.indexOf(a), 1) + var index = state.alerts.indexOf(a) + state.alerts.splice(index, 1) + if (index < state.newAlertCount && index >= 0) state.newAlertCount-- }, 200) }, resetNewAlertCount (state) { -- cgit v1.2.3-55-g7522