finished ##186

This commit is contained in:
Tim Gröger 2020-02-24 12:19:13 +01:00
parent b6dfc45c46
commit 9082b00567
7 changed files with 97 additions and 35 deletions

View File

@ -21,7 +21,7 @@
</v-toolbar-items> </v-toolbar-items>
<v-spacer /> <v-spacer />
</v-toolbar> </v-toolbar>
<v-card v-for="week in month" :key="month.indexOf(week)"> <v-card v-for="week in month" :key="month.indexOf(week)" flat tile>
<v-card-title class="subtitle-1 font-weight-bold"> <v-card-title class="subtitle-1 font-weight-bold">
Woche vom {{ week.startDate.getDate() }}.{{ Woche vom {{ week.startDate.getDate() }}.{{
week.startDate.getMonth() + 1 week.startDate.getMonth() + 1

View File

@ -23,7 +23,14 @@
</div> </div>
</v-expand-transition> </v-expand-transition>
</v-card-text> </v-card-text>
<v-card-actions> <v-card-actions class="text--secondary">
<div v-if="day.locked">
Du kannst dich nicht zum Bardienst eintragen, da der Tag gesperrt ist.
</div>
<div v-else-if="day.worker.length >= 2">
Du kannst dich nicht Bardienst eintragen, da mehr als 2 Personen schon eingetragen sind.
</div>
<div v-else>Hier kannst du dich zum Bardienst eintragen.</div>
<v-spacer /> <v-spacer />
<v-btn <v-btn
v-if="!day.locked && !day.loading && day.worker.length < 2" v-if="!day.locked && !day.loading && day.worker.length < 2"

View File

@ -21,8 +21,12 @@
</v-btn> </v-btn>
</v-toolbar-items> </v-toolbar-items>
<v-spacer /> <v-spacer />
<v-toolbar-items>
<v-btn text @click="lockDays(true)">Monat sperren</v-btn>
<v-btn text @click="lockDays(false)">Monat freigeben</v-btn>
</v-toolbar-items>
</v-toolbar> </v-toolbar>
<v-card v-for="week in month" :key="month.indexOf(week)"> <v-card v-for="week in month" :key="month.indexOf(week)" tile flat>
<v-card-title class="subtitle-1 font-weight-bold"> <v-card-title class="subtitle-1 font-weight-bold">
Woche vom {{ week.startDate.getDate() }}.{{ Woche vom {{ week.startDate.getDate() }}.{{
week.startDate.getMonth() + 1 week.startDate.getMonth() + 1
@ -81,7 +85,8 @@ export default {
methods: { methods: {
...mapActions({ ...mapActions({
createMonth: 'sm/createMonth', createMonth: 'sm/createMonth',
getAllUsers: 'sm/getAllUsers' getAllUsers: 'sm/getAllUsers',
lockDay: 'sm/lockDay'
}), }),
changeMonth(value) { changeMonth(value) {
if (value === -1) { if (value === -1) {
@ -90,6 +95,14 @@ export default {
this.date = new Date(this.date.getFullYear(), this.date.getMonth() + 1) this.date = new Date(this.date.getFullYear(), this.date.getMonth() + 1)
} }
this.createMonth(this.date) this.createMonth(this.date)
},
lockDays(value) {
for (var week in this.month) {
for (var dayint in this.month[week].days) {
var day = this.month[week].days[dayint]
this.lockDay({year: day.date.getFullYear(), month: day.date.getMonth() + 1, day: day.date.getDate(), locked: value})
}
}
} }
}, },
computed: { computed: {

View File

@ -24,14 +24,13 @@
label="Dienste" label="Dienste"
filled filled
color="green" color="green"
@input="searchInput=null" @input="searchInput = null"
:search-input.sync="searchInput" :search-input.sync="searchInput"
@blur="focused=false" @blur="focused = false"
@focus="focused=true" @focus="focused = true"
> >
<template v-slot:prepend-inner> <template v-slot:prepend-inner>
<v-icon>{{account_add}}</v-icon> <v-icon>{{ account_add }}</v-icon>
</template> </template>
<template v-slot:selection="data"> <template v-slot:selection="data">
<v-chip <v-chip
@ -55,13 +54,18 @@
</div> </div>
</v-expand-transition> </v-expand-transition>
</v-card-text> </v-card-text>
<v-card-actions v-if="!day.loading">
<v-chip class="text-uppercase" :color="lockedColor">{{ lockedText }}</v-chip>
<v-spacer />
<v-btn @click="lock">{{lockedTextBtn}}</v-btn>
</v-card-actions>
</v-card> </v-card>
</div> </div>
</template> </template>
<script> <script>
import { mapGetters, mapActions } from 'vuex' import { mapGetters, mapActions } from 'vuex'
import {mdiAccountPlus} from '@mdi/js' import { mdiAccountPlus } from '@mdi/js'
export default { export default {
name: 'Day', name: 'Day',
props: { props: {
@ -90,7 +94,8 @@ export default {
getUser: 'sm/getUser', getUser: 'sm/getUser',
deleteUser: 'sm/deleteUser', deleteUser: 'sm/deleteUser',
setLoading: 'sm/setDayLoading', setLoading: 'sm/setDayLoading',
setNotLoading: 'sm/setDayNotLoading' setNotLoading: 'sm/setDayNotLoading',
lockDay: 'sm/lockDay'
}), }),
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
remove(deletedUser) { remove(deletedUser) {
@ -126,6 +131,9 @@ export default {
return 'grey lighten-4' return 'grey lighten-4'
} }
}, },
lock() {
this.lockDay({year: this.day.date.getFullYear(), month: this.day.date.getMonth() + 1, day: this.day.date.getDate(), locked: !this.day.locked})
}
}, },
computed: { computed: {
...mapGetters({ ...mapGetters({
@ -134,6 +142,15 @@ export default {
}), }),
worker() { worker() {
return this.day.worker return this.day.worker
},
lockedColor() {
return this.day.locked ? 'red' : 'green'
},
lockedText() {
return this.day.locked ? 'gesperrt' : 'frei'
},
lockedTextBtn() {
return this.day.locked ? 'freigeben' : 'sperren'
} }
}, },
watch: { watch: {
@ -156,7 +173,7 @@ export default {
for (let user in oldValue) { for (let user in oldValue) {
if (!newValue.includes(oldValue[user])) { if (!newValue.includes(oldValue[user])) {
deletedUser = oldValue[user] deletedUser = oldValue[user]
console.log("deleteUser", deletedUser, this.day.date) console.log('deleteUser', deletedUser, this.day.date)
this.deleteUser({ this.deleteUser({
startdatetime: this.day.date, startdatetime: this.day.date,
date: this.day.date.getTime() / 1000, date: this.day.date.getTime() / 1000,

View File

@ -24,7 +24,8 @@ const url = {
sm: { sm: {
addUser: main + 'sm/addUser', addUser: main + 'sm/addUser',
deleteUser: main + 'sm/deleteUser', deleteUser: main + 'sm/deleteUser',
getUser: main + 'sm/getUser' getUser: main + 'sm/getUser',
lockDay: main + 'sm/lockDay'
} }
}, },
user: { user: {

View File

@ -118,10 +118,10 @@ const mutations = {
for (let week = 0; week < state.month.length; week++) { for (let week = 0; week < state.month.length; week++) {
for (let day in state.month[week].days) { for (let day in state.month[week].days) {
if (state.month[week].days[day].date - date === 0) { if (state.month[week].days[day].date - date === 0) {
let worker = state.month[week].days[day].worker.find(a => {
return a.username === user.username
})
if (user) { if (user) {
let worker = state.month[week].days[day].worker.find(a => {
return a.username === user.username
})
if (!worker && data.com === 'add') { if (!worker && data.com === 'add') {
state.month[week].days[day].worker.push({ state.month[week].days[day].worker.push({
firstname: user.firstname, firstname: user.firstname,
@ -211,11 +211,10 @@ const actions = {
day: response.data.day day: response.data.day
}) })
} }
if (response.data.worker.length === 0) commit('updateMonth', {
commit('updateMonth', { start: response.data.day.date,
start: response.data.day.date, day: response.data.day
day: response.data.day })
})
commit('setDayNotLoading', { date: data.startdatetime, getters }) commit('setDayNotLoading', { date: data.startdatetime, getters })
} catch (e) { } catch (e) {
if (e.response) if (e.response)

View File

@ -47,7 +47,8 @@ const mutations = {
date: currentDate, date: currentDate,
name: 'Montag', name: 'Montag',
worker: [], worker: [],
loading: false loading: false,
locked: false
} }
break break
case 2: case 2:
@ -56,7 +57,8 @@ const mutations = {
date: currentDate, date: currentDate,
name: 'Dienstag', name: 'Dienstag',
worker: [], worker: [],
loading: false loading: false,
locked: false
} }
break break
case 3: case 3:
@ -70,7 +72,8 @@ const mutations = {
date: currentDate, date: currentDate,
name: 'Mittwoch', name: 'Mittwoch',
worker: [], worker: [],
loading: false loading: false,
locked: false
} }
} }
break break
@ -80,7 +83,8 @@ const mutations = {
date: currentDate, date: currentDate,
name: 'Donnerstag', name: 'Donnerstag',
worker: [], worker: [],
loading: false loading: false,
locked: false
} }
break break
case 5: case 5:
@ -89,7 +93,8 @@ const mutations = {
date: currentDate, date: currentDate,
name: 'Freitag', name: 'Freitag',
worker: [], worker: [],
loading: false loading: false,
locked: false
} }
break break
case 6: case 6:
@ -98,7 +103,8 @@ const mutations = {
date: currentDate, date: currentDate,
name: 'Samstag', name: 'Samstag',
worker: [], worker: [],
loading: false loading: false,
locked: false
} }
break break
case 0: case 0:
@ -107,7 +113,8 @@ const mutations = {
date: currentDate, date: currentDate,
name: 'Sontag', name: 'Sontag',
worker: [], worker: [],
loading: false loading: false,
locked: false
} }
break break
} }
@ -153,10 +160,10 @@ const mutations = {
for (let week = 0; week < state.month.length; week++) { for (let week = 0; week < state.month.length; week++) {
for (let day in state.month[week].days) { for (let day in state.month[week].days) {
if (state.month[week].days[day].date - date === 0) { if (state.month[week].days[day].date - date === 0) {
let worker = state.month[week].days[day].worker.find(a => {
return a.username === user.username
})
if (user) { if (user) {
let worker = state.month[week].days[day].worker.find(a => {
return a.username === user.username
})
if (!worker && data.com === 'add') { if (!worker && data.com === 'add') {
state.month[week].days[day].worker.push({ state.month[week].days[day].worker.push({
firstname: user.firstname, firstname: user.firstname,
@ -228,12 +235,17 @@ const actions = {
{ ...data }, { ...data },
{ headers: { Token: rootState.login.user.accessToken } } { headers: { Token: rootState.login.user.accessToken } }
) )
console.log(response.data)
for (let item = 0; item < response.data.worker.length; item++) { for (let item = 0; item < response.data.worker.length; item++) {
commit('updateMonth', { ...response.data.worker[item], com: 'add', day: response.data.day }) commit('updateMonth', {
...response.data.worker[item],
com: 'add',
day: response.data.day
})
} }
if (response.data.worker.length === 0) commit('updateMonth', {
commit('updateMonth', { start: response.data.day.date, day:response.data.day}) start: response.data.day.date,
day: response.data.day
})
commit('setDayNotLoading', { date: data.startdatetime, getters }) commit('setDayNotLoading', { date: data.startdatetime, getters })
} catch (e) { } catch (e) {
if (e.response) if (e.response)
@ -255,6 +267,19 @@ const actions = {
if (e.response.status === 401) dispatch('logout', null, { root: true }) if (e.response.status === 401) dispatch('logout', null, { root: true })
} }
}, },
async lockDay({ commit, rootState, dispatch }, data) {
try {
const response = await axios.post(
url.vorstand.sm.lockDay,
{ ...data },
{ headers: { Token: rootState.login.user.accessToken } }
)
commit('updateMonth', { start: response.data.date, day: response.data })
} catch (e) {
if (e.response)
if (e.response.status === 401) dispatch('logout', null, { root: true })
}
},
setDayLoading({ commit, getters }, date) { setDayLoading({ commit, getters }, date) {
commit('setDayLoading', { date, getters }) commit('setDayLoading', { date, getters })
}, },