From e502e3f3343217658dab31103d44fcddbdc43aee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Mon, 11 May 2020 23:03:16 +0200 Subject: [PATCH] added feature to lock barview fixed bug, that you can send negative amount. --- src/components/baruser/CreditLists.vue | 2 +- src/components/baruser/SearchBar.vue | 35 +++++++++++++++-- src/plugins/routes.js | 6 ++- src/store/modules/barUsers.js | 54 +++++++++++++++++++++++++- src/views/MainView.vue | 11 +++--- 5 files changed, 96 insertions(+), 12 deletions(-) diff --git a/src/components/baruser/CreditLists.vue b/src/components/baruser/CreditLists.vue index b312a2d..eab1831 100644 --- a/src/components/baruser/CreditLists.vue +++ b/src/components/baruser/CreditLists.vue @@ -275,7 +275,7 @@ export default { addAmountMore(user) { this.addAmount({ username: user.username, - amount: user.value * 100, + amount: Math.abs(user.value * 100), user: user }) setTimeout(() => { diff --git a/src/components/baruser/SearchBar.vue b/src/components/baruser/SearchBar.vue index b37ece2..db5e54c 100644 --- a/src/components/baruser/SearchBar.vue +++ b/src/components/baruser/SearchBar.vue @@ -20,11 +20,28 @@ Hinzufügen + Sperren + Entsperren {{ menuIcon }} + + + + Entsperre Baransicht + + + + + + Abbrechen + Entsperren + + + + @@ -40,11 +57,14 @@ export default { user: null, filter: '', search_person: mdiAccountSearch, - menuIcon: mdiMenu + menuIcon: mdiMenu, + overlay: false, + password: '' } }, created() { this.getAllUsers() + this.getLocked() }, methods: { ...mapActions({ @@ -52,7 +72,10 @@ export default { addCreditList: 'barUsers/addCreditList', setFilter: 'barUsers/setFilter', activateMenu: 'barUsers/activateMenu', - deactivateMenu: 'barUsers/deactivateMenu' + deactivateMenu: 'barUsers/deactivateMenu', + lock: 'barUsers/setLocked', + unlock: 'barUsers/unlock', + getLocked: 'barUsers/getLocked' }), addUser() { this.addCreditList(this.user) @@ -61,13 +84,19 @@ export default { clickMenu() { if (this.menu) this.deactivateMenu() else this.activateMenu() + }, + doUnlock() { + this.unlock(this.password) + this.password = '' + this.overlay = false } }, computed: { ...mapGetters({ allUsers: 'barUsers/allUsers', loading: 'barUsers/allUsersLoading', - menu: 'barUsers/menu' + menu: 'barUsers/menu', + locked: 'barUsers/locked' }) }, watch: { diff --git a/src/plugins/routes.js b/src/plugins/routes.js index 547b80f..fed4a7a 100644 --- a/src/plugins/routes.js +++ b/src/plugins/routes.js @@ -54,10 +54,12 @@ const url = { deleteTransactJobs: main + 'user/deleteTransactJob', storno: main + 'user/storno', getAllStatus: main + 'getAllStatus', - getStatus: main + 'getStatus' + getStatus: main + 'getStatus', + valid: main + 'valid' }, barU: { - storno: main + 'bar/storno' + storno: main + 'bar/storno', + lock: main + 'bar/lock' }, gastro: { setDrink: main + 'gastro/setDrink', diff --git a/src/store/modules/barUsers.js b/src/store/modules/barUsers.js index cacf3ed..7717847 100644 --- a/src/store/modules/barUsers.js +++ b/src/store/modules/barUsers.js @@ -8,7 +8,8 @@ const state = { usersLoading: false, allUsersLoading: false, message: [], - menu: false + menu: false, + locked: false } const mutations = { @@ -116,6 +117,9 @@ const mutations = { }, setMenu: (state, value) => { state.menu = value + }, + setLocked: (satet, value) => { + state.locked = value } } @@ -227,6 +231,51 @@ const actions = { } commit('updateMessage', { date: data.date, loading: false }) }, + async getLocked({ commit, rootState, dispatch }) { + try { + const response = await axios.get(url.barU.lock, { + headers: { Token: rootState.login.user.accessToken } + }) + console.log(response.data.value) + commit('setLocked', response.data.value) + } catch (e) { + if (e.response) + if (e.response.status === 401) dispatch('logout', null, { root: true }) + } + }, + async setLocked({ commit, rootState, dispatch }) { + try { + const response = await axios.post( + url.barU.lock, + { value: true }, + { headers: { Token: rootState.login.user.accessToken } } + ) + commit('setLocked', response.data.value) + } catch (e) { + if (e.response) + if (e.response.status === 401) dispatch('logout', null, { root: true }) + } + }, + async unlock({ commit, rootState, dispatch }, password) { + try { + const valid = await axios.post( + url.user.valid, + { password: password }, + { headers: { Token: rootState.login.user.accessToken } } + ) + if (valid.data.ok === 'ok') { + const response = await axios.post( + url.barU.lock, + { value: false }, + { headers: { Token: rootState.login.user.accessToken } } + ) + commit('setLocked', response.data.value) + } + } catch (e) { + if (e.response) + if (e.response.status === 401) dispatch('logout', null, { root: true }) + } + }, setFilter({ commit }, data) { commit('setFilter', data) }, @@ -259,6 +308,9 @@ const getters = { }, menu: state => { return state.menu + }, + locked: state => { + return state.locked } } diff --git a/src/views/MainView.vue b/src/views/MainView.vue index 5540f2a..aeb4aae 100644 --- a/src/views/MainView.vue +++ b/src/views/MainView.vue @@ -18,7 +18,7 @@ {{user.firstname}} {{user.lastname}} - + {{person}} @@ -32,7 +32,7 @@ Bar - + {{king}} @@ -40,7 +40,7 @@ Vorstand - + {{gastro}} @@ -48,7 +48,7 @@ Gastro - + {{attach_money}} @@ -107,7 +107,8 @@ export default { isManagement: 'isManagement', isLoggedIn: 'isLoggedIn', isExtern: 'isExtern', - user: 'user' + user: 'user', + lockedBar: 'barUsers/locked' }) } }