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

View File

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

View File

@ -130,6 +130,10 @@ const mutations = {
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) {
state.month[week].days[day].locked = data.day.locked
@ -235,6 +239,21 @@ const actions = {
if (e.response)
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 })
}
}
}