finished ##192

user can delete his job if day not locked
This commit is contained in:
Tim Gröger 2020-02-24 18:57:28 +01:00
parent 9082b00567
commit 917690eba3
3 changed files with 58 additions and 16 deletions

View File

@ -14,23 +14,35 @@
</v-expand-transition> </v-expand-transition>
<v-expand-transition> <v-expand-transition>
<div v-show="!day.loading"> <div v-show="!day.loading">
<div v-for="worker in day.worker" :key="day.worker.indexOf(worker)">
<v-chip <v-chip
style="margin: 3px;" style="margin: 3px;"
v-for="worker in day.worker" :close="user(worker) && !day.locked"
:key="day.worker.indexOf(worker)" @click:close="
>{{ worker.firstname }} {{ worker.lastname }}</v-chip deleteJob({
> year: day.date.getFullYear(),
month: day.date.getMonth() + 1,
day: day.date.getDate()
})
"
>{{ worker.firstname }} {{ worker.lastname }}
</v-chip>
</div>
</div> </div>
</v-expand-transition> </v-expand-transition>
</v-card-text> </v-card-text>
<v-card-actions class="text--secondary"> <v-card-actions class="text--secondary">
<div v-if="!userInWorker">
<div v-if="day.locked"> <div v-if="day.locked">
Du kannst dich nicht zum Bardienst eintragen, da der Tag gesperrt ist. Du kannst dich nicht zum Bardienst eintragen, da der Tag gesperrt
ist.
</div> </div>
<div v-else-if="day.worker.length >= 2"> <div v-else-if="day.worker.length >= 2">
Du kannst dich nicht Bardienst eintragen, da mehr als 2 Personen schon eingetragen sind. Du kannst dich nicht Bardienst eintragen, da mehr als 2 Personen
schon eingetragen sind.
</div> </div>
<div v-else>Hier kannst du dich zum Bardienst eintragen.</div> <div v-else>Hier kannst du dich zum Bardienst eintragen.</div>
</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"
@ -77,7 +89,8 @@ export default {
getUser: 'jobs/getUser', getUser: 'jobs/getUser',
setLoading: 'jobs/setDayLoading', setLoading: 'jobs/setDayLoading',
setNotLoading: 'jobs/setDayNotLoading', setNotLoading: 'jobs/setDayNotLoading',
addJob: 'jobs/addJob' addJob: 'jobs/addJob',
deleteJob: 'jobs/deleteJob'
}), }),
test(event) { test(event) {
console.log('blur', event) console.log('blur', event)
@ -96,12 +109,21 @@ export default {
} else { } else {
return 'grey lighten-4' return 'grey lighten-4'
} }
},
user(worker) {
return worker.username === this.activeUser.username
} }
}, },
computed: { computed: {
...mapGetters({ ...mapGetters({
disabled: 'jobs/disabled' disabled: 'jobs/disabled',
activeUser: 'user'
}),
userInWorker() {
return this.day.worker.find(a => {
return a.username === this.activeUser.username
}) })
}
}, },
watch: { watch: {
day() { day() {

View File

@ -31,7 +31,8 @@ const url = {
user: { user: {
config: main + 'user/saveConfig', config: main + 'user/saveConfig',
job: main + 'user/job', job: main + 'user/job',
addJob: main + 'user/addJob' addJob: main + 'user/addJob',
deleteJob: main + 'user/deleteJob'
}, },
barU: { barU: {
storno: main + 'bar/storno' storno: main + 'bar/storno'

View File

@ -130,6 +130,10 @@ const mutations = {
fullName: user.firstname + ' ' + user.lastname fullName: user.firstname + ' ' + user.lastname
}) })
} }
if (worker && data.com === 'delete') {
const index = state.month[week].days[day].worker.indexOf(worker)
state.month[week].days[day].worker.splice(index, 1)
}
} }
if (data.day) { if (data.day) {
state.month[week].days[day].locked = data.day.locked state.month[week].days[day].locked = data.day.locked
@ -235,6 +239,21 @@ const actions = {
if (e.response) if (e.response)
if (e.response.status === 401) dispatch('logout', null, { root: true }) if (e.response.status === 401) dispatch('logout', null, { root: true })
} }
},
// eslint-disable-next-line no-unused-vars
async deleteJob({ commit, rootState, dispatch }, data) {
try {
const response = await axios.post(
url.user.deleteJob,
{ ...data },
{ headers: { Token: rootState.login.user.accessToken } }
)
commit('updateMonth', {start: {...data}, user: rootState.login.user, com: 'delete'})
console.log(response)
} catch (e) {
if (e.response)
if (e.response.status === 401) dispatch('logout', null, { root: true })
}
} }
} }