storno at 5 min for the baruser in geruecht ##164

This commit is contained in:
Tim Gröger 2020-02-19 23:22:23 +01:00
parent 211bb99d07
commit 20fb2f56de
3 changed files with 45 additions and 17 deletions

View File

@ -24,18 +24,19 @@
</v-container> </v-container>
<v-navigation-drawer v-model="menu" right app clipped> <v-navigation-drawer v-model="menu" right app clipped>
<v-list-item-group> <v-list-item-group>
<div
<div v-for="message in messages" v-for="message in messages"
three-line three-line
:key="messages.indexOf(message)"> :key="messages.indexOf(message)"
<v-list-item v-if="!message.storno"> >
<v-list-item three-line>
<v-list-item-content> <v-list-item-content>
<v-list-item-title>{{ now(message.date) }}</v-list-item-title> <v-list-item-title>{{ now(message.date) }}</v-list-item-title>
<v-list-item-subtitle>{{ message.message }}</v-list-item-subtitle> <v-list-item-subtitle>{{ message.message }}</v-list-item-subtitle>
<v-list-item-subtitle class="red--text" v-if="message.storno">STORNIERT!!!</v-list-item-subtitle>
<v-list-item-action-text @click.stop="storno(message)" <v-list-item-action-text @click.stop="storno(message)"
>Klicken um zu Stornieren >Klicken um zu Stornieren
</v-list-item-action-text </v-list-item-action-text>
>
</v-list-item-content> </v-list-item-content>
</v-list-item> </v-list-item>
</div> </div>
@ -214,7 +215,8 @@ export default {
...mapActions({ ...mapActions({
addAmount: 'barUsers/addAmount', addAmount: 'barUsers/addAmount',
getUsers: 'barUsers/getUsers', getUsers: 'barUsers/getUsers',
deactivate: 'barUsers/deactivateMenu' deactivate: 'barUsers/deactivateMenu',
commitStorno: 'barUsers/storno'
}), }),
getColor(type) { getColor(type) {
return type === 'credit' ? 'title green--text' : 'title red--text' return type === 'credit' ? 'title green--text' : 'title red--text'
@ -231,9 +233,10 @@ export default {
}, },
storno(message) { storno(message) {
if (!message.error) { if (!message.error) {
console.log(message)
message.storno = true
if (!this.under5minutes(message.date)) this.dialog = true if (!this.under5minutes(message.date)) this.dialog = true
else {
this.commitStorno({username: message.user.username, amount: message.amount, date: message.date})
}
} }
} }
}, },
@ -267,7 +270,6 @@ export default {
var actual = new Date() var actual = new Date()
var zero = new Date(0) var zero = new Date(0)
var date = new Date(actual - now) var date = new Date(actual - now)
console.log(date)
if (date.getFullYear() === zero.getFullYear()) { if (date.getFullYear() === zero.getFullYear()) {
if (date.getMonth() === zero.getMonth()) { if (date.getMonth() === zero.getMonth()) {
if (date.getDate() === zero.getDate()) { if (date.getDate() === zero.getDate()) {
@ -301,13 +303,10 @@ export default {
}, },
watch: { watch: {
menu(newValue) { menu(newValue) {
console.log('menu', newValue)
if (!newValue) this.deactivate() if (!newValue) this.deactivate()
}, },
menu_from_store(newValue) { menu_from_store(newValue) {
console.log('for menu_from_store', newValue, this.menu)
if (newValue) this.menu = this.menu_from_store if (newValue) this.menu = this.menu_from_store
console.log('after menu_from_store', newValue, this.menu)
} }
} }
} }

View File

@ -1,7 +1,7 @@
//const main = 'https://192.168.5.128:5000/' //const main = 'https://192.168.5.128:5000/'
//const main = 'http://localhost:5000/' const main = 'http://localhost:5000/'
//const main = 'http://192.168.5.118:5000/' //const main = 'http://192.168.5.118:5000/'
const main = 'https://groeger-clan.duckdns.org:5000/' //const main = 'https://groeger-clan.duckdns.org:5000/'
const url = { const url = {
login: main + 'login', login: main + 'login',
@ -30,6 +30,9 @@ const url = {
user: { user: {
config: main + 'user/saveConfig', config: main + 'user/saveConfig',
job: main + 'user/job' job: main + 'user/job'
},
barU: {
storno: main + 'bar/storno'
} }
} }

View File

@ -96,6 +96,7 @@ const mutations = {
} }
state.message.unshift({ state.message.unshift({
message: message, message: message,
user: data.user,
error: data.error, error: data.error,
storno: false, storno: false,
visible: true, visible: true,
@ -104,6 +105,12 @@ const mutations = {
}) })
console.log(state.message) console.log(state.message)
}, },
updateMessage: (state, data) => {
var message = state.message.find(msg => {return msg.date - data.date === 0 ? true : false})
if (message) {
message.storno = true
}
},
setMenu: (state, value) => { setMenu: (state, value) => {
state.menu = value state.menu = value
} }
@ -179,6 +186,25 @@ const actions = {
} }
commit('setAllUsersLoading', false) commit('setAllUsersLoading', false)
}, },
async storno({ commit, rootState, dispatch }, data) {
commit('setUsersLoading', true)
try {
const response = await axios.post(
url.barU.storno,
{
userId: data.username,
amount: data.amount
},
{ headers: { Token: rootState.login.user.accessToken } }
)
commit('setUsers', { [response.data.username]: response.data })
commit('updateMessage', { date: data.date })
} catch (e) {
if (e.response)
if (e.response.status === 401) dispatch('logout', null, { root: true })
}
commit('setUsersLoading', false)
},
setFilter({ commit }, data) { setFilter({ commit }, data) {
commit('setFilter', data) commit('setFilter', data)
}, },