Backend Connection für Freigetränke Band und Dienste

Es wurde die Verbindung zur Schnittstelle aufgebaut. Freigetränke werden Dynamisch gehalten.
This commit is contained in:
Tim Gröger 2020-08-20 08:39:38 +02:00
parent 22c5ebce1b
commit 8ac74c9f64
4 changed files with 271 additions and 124 deletions

View File

@ -9,106 +9,30 @@
<v-icon>{{ menuIcon }}</v-icon>
</v-btn>
</v-card-title>
<v-card-subtitle v-if="(limit - amount) > 0">
Noch {{ ((limit - amount) / 100).toFixed(2) }}
<v-card-subtitle v-if="(limit - free_drink_list_history_job_credit) > 0">
Noch {{ ((limit - free_drink_list_history_job_credit) / 100).toFixed(2) }}
übrig!!
</v-card-subtitle>
<v-card-text>
<v-row v-if="!loading">
<v-col cols="12">
<v-row>
<v-col cols="6" xs="3" sm="4" class="drinkCol">
<v-btn
class="drinkBtn"
:disabled="locked"
:color="color"
@click="addAmount(140)"
>Bier</v-btn>
</v-col>
<v-col cols="6" xs="3" sm="4" class="drinkCol">
<v-col v-for="freeDrink in free_drink_list_config_job" :key="freeDrink.id" cols="6" xs="3" sm="4" class="drinkCol">
<v-btn
class="drinkBtn"
block
:disabled="locked"
:color="color"
@click="addAmount(200)"
>Cuba</v-btn>
</v-col>
<v-col cols="6" xs="3" sm="4" class="drinkCol">
<v-btn
class="drinkBtn"
block
:disabled="locked"
:color="color"
@click="addAmount(50)"
>Schnaps</v-btn>
</v-col>
<v-col cols="6" xs="3" sm="4" class="drinkCol">
<v-btn
class="drinkBtn"
block
:disabled="locked"
:color="color"
@click="addAmount(200)"
>Wein</v-btn>
</v-col>
<v-col cols="6" xs="3" sm="4" class="drinkCol">
<v-btn
class="drinkBtn"
block
:disabled="locked"
:color="color"
@click="addAmount(200)"
>Gin Tonic</v-btn>
</v-col>
<v-col cols="6" xs="3" sm="4" class="drinkCol">
<v-btn
class="drinkBtn"
block
:disabled="locked"
:color="color"
@click="addAmount(100)"
>Fritz</v-btn>
</v-col>
<v-col cols="6" xs="3" sm="4" class="drinkCol">
<v-btn
class="drinkBtn"
block
:disabled="locked"
:color="color"
@click="addAmount(100)"
>Saft</v-btn>
</v-col>
<v-col cols="6" xs="3" sm="4" class="drinkCol">
<v-btn
class="drinkBtn"
block
:disabled="locked"
:color="color"
@click="addAmount(30)"
>Wasser</v-btn>
@click="addAmount(freeDrink, freeDrinkTypeJob)"
>{{freeDrink.label}}</v-btn>
</v-col>
</v-row>
<v-row v-if="!loading">
<v-col cols="8">
<v-text-field
outlined
type="number"
label="Benutzerdefinierter Betrag"
:disabled="locked"
v-model="customValue"
></v-text-field>
</v-col>
<v-col cols="2">
<v-btn fab :color="color" :disabled="locked" @click="addAmount(customValue)">
<v-icon>{{ plus }}</v-icon>
</v-btn>
</v-col>
<v-col cols="2">
<v-row v-if="!loading" class="justify-end">
<v-col cols="3">
<v-list-item>
<v-list-item-content class="text-center">
<v-list-item-action-text :class="getColor()">
{{ (amount / 100).toFixed(2) }}
{{ (free_drink_list_history_job_credit / 100).toFixed(2) }}
</v-list-item-action-text>
</v-list-item-content>
@ -119,6 +43,41 @@
</v-row>
</v-card-text>
</v-card>
<v-card class="mx-auto" outlined>
<v-card-title>
<div class="title">Bandgetränke</div>
<v-btn class="menuBtn" @click.stop="isMenuShow = !isMenuShow" icon>
<v-icon>{{ menuIcon }}</v-icon>
</v-btn>
</v-card-title>
<v-card-text>
<v-row v-if="!loading">
<v-col cols="12">
<v-row>
<v-col v-for="freeDrink in free_drink_list_config_band" :key="freeDrink.id" cols="6" xs="3" sm="4" class="drinkCol">
<v-btn
class="drinkBtn"
block
:color="color_fix"
@click="addAmount(freeDrink, freeDrinkTypeBand)"
>{{freeDrink.label}}</v-btn>
</v-col>
</v-row>
<v-row v-if="!loading" class="justify-end">
<v-col cols="3">
<v-list-item>
<v-list-item-content class="text-center">
<v-list-item-action-text class="title">
{{ free_drink_list_history_band_without_canceled.length }} Getränke
</v-list-item-action-text>
</v-list-item-content>
</v-list-item>
</v-col>
</v-row>
</v-col>
</v-row>
</v-card-text>
</v-card>
</v-container>
<v-navigation-drawer v-model="isMenuShow" right app clipped>
@ -127,13 +86,13 @@
<v-list-item-title class="headline">Verlauf</v-list-item-title>
</v-list-item>
<v-divider />
<div
<!-- <div
v-for="message in messages"
three-line
:key="messages.indexOf(message)"
class="history-item"
>
<v-list-item three-line inactive @click="stornoAmount(message)">
<v-list-item three-line inactive @click="canceledAmount(message)">
<v-list-item-content>
<v-list-item-title>{{ now(message.date) }}</v-list-item-title>
<v-list-item-subtitle>
@ -141,9 +100,28 @@
createMessage(message)
}}
</v-list-item-subtitle>
<v-list-item-subtitle class="red--text" v-if="message.storno">STORNIERT!!!</v-list-item-subtitle>
<v-list-item-subtitle class="red--text" v-if="message.canceled">STORNIERT!!!</v-list-item-subtitle>
<v-list-item-action-text
v-if="isStronoEnabled(message.date) && !message.storno"
v-if="isStronoEnabled(message.date) && !message.canceled"
>Klicken um zu Stornieren</v-list-item-action-text>
</v-list-item-content>
</v-list-item>
</div> -->
<div
v-for="freeDrinkHistory in free_drink_list_history"
:key="freeDrinkHistory.id"
>
<v-list-item three-line inactive @click="canceledAmount(freeDrinkHistory)">
<v-list-item-content>
<v-list-item-title>{{ now(freeDrinkHistory.timestamp) }}</v-list-item-title>
<v-list-item-subtitle>{{ freeDrinkHistory.free_drink_type.name }}: {{ freeDrinkHistory.free_drink_config.label }} wurde für
{{
(freeDrinkHistory.free_drink_config.price/100).toFixed(2)
}} hinzugefügt
</v-list-item-subtitle>
<v-list-item-subtitle class="red--text" v-if="freeDrinkHistory.canceled">STORNIERT!!!</v-list-item-subtitle>
<v-list-item-action-text
v-if="isStronoEnabled(freeDrinkHistory.timestamp) && !freeDrinkHistory.canceled"
>Klicken um zu Stornieren</v-list-item-action-text>
</v-list-item-content>
</v-list-item>
@ -151,18 +129,16 @@
</v-list-item-group>
</v-navigation-drawer>
<v-dialog v-model="showConfirmStornoDialog" max-width="290">
<v-dialog v-model="showConfirmCanceledDialog" max-width="290">
<v-card>
<v-card-title>Willst du wirklich??</v-card-title>
<v-card-text v-if="stornoMessage">
Willst du wirklich den Betrag
{{ (stornoMessage.amount / 100).toFixed(2) }} von
den Dienstgetränke stornieren?
<v-card-text v-if="canceledMessage">
{{canceledMessage.free_drink_type.name}}: Willst du wirklich ein {{canceledMessage.free_drink_config.label}} im Wert von {{(canceledMessage.free_drink_config.price/100).toFixed(2)}} stornieren?
</v-card-text>
<v-card-actions>
<v-spacer />
<v-btn text @click="cancelStorno">Abbrechen</v-btn>
<v-btn text @click="acceptStorno">Stornieren</v-btn>
<v-btn text @click="cancelCanceled">Abbrechen</v-btn>
<v-btn text @click="acceptCanceled">Stornieren</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
@ -176,58 +152,66 @@
<script>
// eslint-disable-next-line no-unused-vars
import AddAmountSkeleton from '../user/Skeleton/AddAmountSkeleton'
import { mapActions, mapGetters } from 'vuex'
import { mdiPlus, mdiMenu } from '@mdi/js'
export default {
name: 'BarFreedrinks',
components: { AddAmountSkeleton },
created() {
this.loading = false
this.timer = setInterval(() => (this.componentRenderer += 1), 1000)
this.get_free_drink_list_config()
this.get_free_drink_list_history()
},
data() {
return {
plus: mdiPlus,
menuIcon: mdiMenu,
loading: true,
locked: false,
showConfirmStornoDialog: false,
stornoMessage: null,
showConfirmCanceledDialog: false,
canceledMessage: null,
limit: 1000,
amount: 0,
customValue: null,
color: 'green accent-4',
color_fix: 'green accent-4',
messages: [],
timer: '',
componentRenderer: 0,
isMenuShow: false
isMenuShow: false,
freeDrinkTypeJob: 1,
freeDrinkTypeBand: 3
}
},
methods: {
addAmount(amount) {
if (amount) {
...mapActions('freeDrinkList', ['get_free_drink_list_config', 'get_free_drink_list_history','set_free_drink_list_history', 'update_free_drink_list_history']),
output() {
console.log(this.free_drink_list_config)
},
addAmount(freeDrink, free_drink_type_id) {
this.set_free_drink_list_history({...freeDrink, free_drink_type_id})
/*if (amount) {
this.amount += amount
this.generateMessage(amount)
}
this.checkLocked()
this.checkLocked()*/
},
stornoAmount(message) {
if (!this.isStronoEnabled(message.date) || message.storno) {
canceledAmount(historyElement) {
if (!this.isStronoEnabled(historyElement.timestamp)) {
return
}
this.showConfirmStornoDialog = true
this.stornoMessage = message
this.showConfirmCanceledDialog = true
this.canceledMessage = historyElement
},
cancelStorno() {
this.showConfirmStornoDialog = null
this.stornoMessage = null
cancelCanceled() {
this.showConfirmCanceledDialog = null
this.canceledMessage = null
},
generateMessage(amount) {
this.messages.push({
date: new Date(),
storno: false,
canceled: false,
amount: amount,
error: false,
visible: true,
@ -254,14 +238,14 @@ export default {
getColor() {
return this.locked ? 'title red--text' : 'title'
},
acceptStorno() {
this.stornoMessage.storno = true
this.amount -= this.stornoMessage.amount
console.log(this.amount, this.stornoMessage)
this.cancelStorno()
acceptCanceled() {
this.canceledMessage.canceled = true
this.update_free_drink_list_history(this.canceledMessage)
this.cancelCanceled()
}
},
computed: {
...mapGetters('freeDrinkList', ['free_drink_list_config_job', 'free_drink_list_config_band', 'free_drink_list_history', 'free_drink_list_history_job_credit', 'free_drink_list_history_band', 'free_drink_list_history_band_without_canceled']),
now() {
return now => {
var actual = new Date()
@ -316,6 +300,9 @@ export default {
var actual = new Date()
return actual - now < 60000
}
},
locked() {
return this.free_drink_list_history_job_credit >= 1000
}
},
beforeDestroy() {

View File

@ -1,7 +1,7 @@
//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 = 'https://groeger-clan.duckdns.org:5000/'
//const main = 'https://groeger-clan.duckdns.org:5000/'
//const main = 'https://flaschengeist.wu5.de:5000/'
const url = {
@ -28,6 +28,9 @@ const url = {
saveLifeTime: main + 'saveLifeTime',
getLifeTime: main + 'getLifeTime',
resetPassword: main + 'passwordReset',
freeDrinkListConfig: main + 'freeDrinkListConfig',
freeDrinkListHistory: main + 'freeDrinkListHistory',
deleteDrinkListHistory: main + 'deleteDrinkListHistory',
vorstand: {
sm: {
addUser: main + 'sm/addUser',

View File

@ -13,6 +13,7 @@ import jkm from '@/store/modules/jobkindManager'
import jobInvites from '@/store/modules/jobInvites'
import jobRequests from '@/store/modules/jobRequests'
import connectionError from '@/store/modules/connectionError'
import freeDrinkList from '@/store/modules/freeDrinkList'
Vue.use(Vuex)
@ -30,6 +31,7 @@ export default new Vuex.Store({
jkm,
jobInvites,
jobRequests,
connectionError
connectionError,
freeDrinkList
}
})

View File

@ -0,0 +1,155 @@
import axios from 'axios'
import url from '@/plugins/routes'
const timeout = 20000
const state = {
free_drink_list_config: [],
free_drink_list_history: []
}
const mutations = {
set_free_drink_list_config(state, data) {
state.free_drink_list_config = data
},
set_free_drink_list_history(state, data) {
data.forEach(item => {
item.timestamp = new Date(
item.timestamp.year,
item.timestamp.month - 1,
item.timestamp.day,
item.timestamp.hour,
item.timestamp.minute,
item.timestamp.second
)
})
state.free_drink_list_history = data
state.free_drink_list_history.reverse()
}
}
const actions = {
async get_free_drink_list_config({ commit, dispatch, rootState }) {
try {
const response = await axios.get(url.freeDrinkListConfig, {
headers: { Token: rootState.login.user.accessToken },
timeout
})
commit('set_free_drink_list_config', response.data)
} catch (e) {
if (e.message == 'Network Error') {
dispatch('connectionError/addError', null, { root: true })
}
if (e.response)
if (e.response.status === 401) dispatch('logout', null, { root: true })
}
},
async get_free_drink_list_history({ commit, dispatch, rootState }) {
try {
const response = await axios.get(url.freeDrinkListHistory, {
headers: { Token: rootState.login.user.accessToken },
timeout
})
commit('set_free_drink_list_history', response.data)
} catch (e) {
if (e.message == 'Network Error') {
dispatch('connectionError/addError', null, { root: true })
}
if (e.response)
if (e.response.status === 401) dispatch('logout', null, { root: true })
}
},
async set_free_drink_list_history({ commit, dispatch, rootState }, data) {
try {
const response = await axios.post(
url.freeDrinkListHistory,
{ ...data },
{
headers: { Token: rootState.login.user.accessToken },
timeout
}
)
commit('set_free_drink_list_history', response.data)
} catch (e) {
if (e.message == 'Network Error') {
dispatch('connectionError/addError', null, { root: true })
}
if (e.response)
if (e.response.status === 401) dispatch('logout', null, { root: true })
}
},
async update_free_drink_list_history({ commit, dispatch, rootState }, data) {
try {
await axios.put(
url.freeDrinkListHistory,
{ ...data },
{ headers: { Token: rootState.login.user.accessToken }, timeout }
)
commit('set_free_drink_list_history', data)
} catch (e) {
if (e.message == 'Network Error') {
dispatch('connectionError/addError', null, { root: true })
}
if (e.response)
if (e.response.status === 401) dispatch('logout', null, { root: true })
}
}
}
const getters = {
free_drink_list_config(state) {
return state.free_drink_list_config
},
free_drink_list_config_job(state) {
return state.free_drink_list_config.filter(item => {
console.log(item)
return item.free_drink_types.find(drink_type => {
return drink_type.id == 1
})
})
},
free_drink_list_config_workgroup(state) {
return state.free_drink_list_config.filter(item => {
return item.free_drink_types.find(drink_type => {
return drink_type.id == 2
})
})
},
free_drink_list_config_band(state) {
return state.free_drink_list_config.filter(item => {
return item.free_drink_types.find(drink_type => {
return drink_type.id == 3
})
})
},
free_drink_list_history(state) {
return state.free_drink_list_history
},
free_drink_list_history_band(state) {
return state.free_drink_list_history.filter(item => {
return item.free_drink_type.id == 3
})
},
free_drink_list_history_band_without_canceled(state) {
return state.free_drink_list_history.filter(item => {
return item.free_drink_type.id == 3 && !item.canceled
})
},
free_drink_list_history_job_credit(state) {
let jobDrinks = state.free_drink_list_history.filter(item => {
return item.free_drink_type.id == 1 && !item.storno
})
let credit = 0
jobDrinks.forEach(item => {
credit += item.free_drink_config.price
})
return credit
}
}
export default {
namespaced: true,
state,
mutations,
actions,
getters
}