2020-01-18 11:49:49 +00:00
|
|
|
<template>
|
2020-01-19 20:31:48 +00:00
|
|
|
<div v-if="day">
|
2020-01-23 10:11:26 +00:00
|
|
|
<v-card :color="color(day)" max-width="250px" min-width="250px">
|
2020-01-19 20:31:48 +00:00
|
|
|
<v-card-title v-if="day.date" class="subtitle-1 font-weight-bold">
|
|
|
|
{{ day.name }} den {{ day.date.getDate() }}.{{
|
|
|
|
day.date.getMonth() + 1
|
|
|
|
}}.{{ day.date.getFullYear() }}
|
|
|
|
</v-card-title>
|
|
|
|
<v-card-text>
|
2020-01-23 10:11:26 +00:00
|
|
|
<v-expand-transition>
|
|
|
|
<v-row align="center" justify="center" v-if="day.loading">
|
2020-01-23 22:25:21 +00:00
|
|
|
<v-progress-circular indeterminate color="grey" />
|
2020-01-23 10:11:26 +00:00
|
|
|
</v-row>
|
|
|
|
</v-expand-transition>
|
|
|
|
<v-expand-transition>
|
|
|
|
<div v-show="!day.loading">
|
|
|
|
<v-autocomplete
|
|
|
|
chips
|
|
|
|
return-object
|
|
|
|
multiple
|
|
|
|
v-model="day.worker"
|
|
|
|
:items="allUsers"
|
|
|
|
item-text="fullName"
|
|
|
|
label="Dienste"
|
|
|
|
filled
|
|
|
|
color="green"
|
2020-02-24 11:19:13 +00:00
|
|
|
@input="searchInput = null"
|
2020-01-23 10:11:26 +00:00
|
|
|
:search-input.sync="searchInput"
|
2020-02-24 11:19:13 +00:00
|
|
|
@blur="focused = false"
|
|
|
|
@focus="focused = true"
|
2020-01-19 20:31:48 +00:00
|
|
|
>
|
2020-01-26 22:55:59 +00:00
|
|
|
<template v-slot:prepend-inner>
|
2020-02-24 11:19:13 +00:00
|
|
|
<v-icon>{{ account_add }}</v-icon>
|
2020-01-26 22:55:59 +00:00
|
|
|
</template>
|
2020-01-23 10:11:26 +00:00
|
|
|
<template v-slot:selection="data">
|
|
|
|
<v-chip
|
|
|
|
v-bind="data.attrs"
|
|
|
|
:input-value="data.selected"
|
|
|
|
close
|
|
|
|
@click="data.select"
|
|
|
|
@click:close="remove(data.item)"
|
|
|
|
>
|
|
|
|
{{ data.item.firstname }} {{ data.item.lastname }}
|
|
|
|
</v-chip>
|
|
|
|
</template>
|
|
|
|
<template v-slot:item="data">
|
|
|
|
<v-list-item-content>
|
|
|
|
<v-list-item-title>
|
|
|
|
{{ data.item.firstname }} {{ data.item.lastname }}
|
|
|
|
</v-list-item-title>
|
|
|
|
</v-list-item-content>
|
|
|
|
</template>
|
|
|
|
</v-autocomplete>
|
|
|
|
</div>
|
|
|
|
</v-expand-transition>
|
2020-01-19 20:31:48 +00:00
|
|
|
</v-card-text>
|
2020-02-24 11:19:13 +00:00
|
|
|
<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>
|
2020-01-19 20:31:48 +00:00
|
|
|
</v-card>
|
|
|
|
</div>
|
2020-01-18 11:49:49 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import { mapGetters, mapActions } from 'vuex'
|
2020-02-24 11:19:13 +00:00
|
|
|
import { mdiAccountPlus } from '@mdi/js'
|
2020-01-18 11:49:49 +00:00
|
|
|
export default {
|
|
|
|
name: 'Day',
|
|
|
|
props: {
|
|
|
|
day: Object
|
|
|
|
},
|
|
|
|
data() {
|
2020-01-23 10:11:26 +00:00
|
|
|
return {
|
2020-01-26 22:55:59 +00:00
|
|
|
account_add: mdiAccountPlus,
|
2020-01-23 10:11:26 +00:00
|
|
|
searchInput: null,
|
|
|
|
focused: false
|
|
|
|
}
|
2020-01-19 20:31:48 +00:00
|
|
|
},
|
|
|
|
created() {
|
2020-01-23 10:11:26 +00:00
|
|
|
this.setLoading(this.day.date)
|
|
|
|
this.getUser({
|
|
|
|
date: this.day.date.getTime() / 1000,
|
2020-02-23 10:19:53 +00:00
|
|
|
startdatetime: this.day.date,
|
|
|
|
year: this.day.date.getFullYear(),
|
|
|
|
month: this.day.date.getMonth() + 1,
|
|
|
|
day: this.day.date.getDate()
|
2020-01-23 10:11:26 +00:00
|
|
|
})
|
2020-01-18 11:49:49 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
...mapActions({
|
2020-01-19 20:31:48 +00:00
|
|
|
addUser: 'sm/addUser',
|
|
|
|
getUser: 'sm/getUser',
|
2020-01-23 10:11:26 +00:00
|
|
|
deleteUser: 'sm/deleteUser',
|
|
|
|
setLoading: 'sm/setDayLoading',
|
2020-02-24 11:19:13 +00:00
|
|
|
setNotLoading: 'sm/setDayNotLoading',
|
|
|
|
lockDay: 'sm/lockDay'
|
2020-01-18 11:49:49 +00:00
|
|
|
}),
|
2020-01-19 20:31:48 +00:00
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
|
|
remove(deletedUser) {
|
|
|
|
const obj = this.day.worker.find(a => {
|
|
|
|
return a.username === deletedUser.username
|
|
|
|
})
|
|
|
|
const index = this.day.worker.indexOf(obj)
|
|
|
|
if (index >= 0) this.day.worker.splice(index, 1)
|
2020-01-23 10:11:26 +00:00
|
|
|
this.deleteUser({
|
|
|
|
startdatetime: this.day.date,
|
|
|
|
date: this.day.date.getTime() / 1000,
|
2020-02-23 10:19:53 +00:00
|
|
|
user: deletedUser,
|
|
|
|
year: this.day.date.getFullYear(),
|
|
|
|
month: this.day.date.getMonth() + 1,
|
|
|
|
day: this.day.date.getDate()
|
2020-01-23 10:11:26 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
test(event) {
|
|
|
|
console.log('blur', event)
|
2020-01-19 20:31:48 +00:00
|
|
|
},
|
|
|
|
color: day => {
|
|
|
|
if (day) {
|
|
|
|
if (day.date.getDay() === 0 || day.date.getDay() === 1) {
|
|
|
|
return 'grey lighten-4'
|
|
|
|
} else {
|
|
|
|
if (day.worker.length < 2) {
|
|
|
|
return 'yellow'
|
|
|
|
} else {
|
|
|
|
return 'light-green'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return 'grey lighten-4'
|
|
|
|
}
|
2020-01-23 10:11:26 +00:00
|
|
|
},
|
2020-02-24 11:19:13 +00:00
|
|
|
lock() {
|
|
|
|
this.lockDay({year: this.day.date.getFullYear(), month: this.day.date.getMonth() + 1, day: this.day.date.getDate(), locked: !this.day.locked})
|
|
|
|
}
|
2020-01-18 11:49:49 +00:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapGetters({
|
2020-01-23 10:11:26 +00:00
|
|
|
allUsers: 'sm/allUsers',
|
|
|
|
disabled: 'sm/disabled'
|
2020-01-19 20:31:48 +00:00
|
|
|
}),
|
|
|
|
worker() {
|
|
|
|
return this.day.worker
|
2020-02-24 11:19:13 +00:00
|
|
|
},
|
|
|
|
lockedColor() {
|
|
|
|
return this.day.locked ? 'red' : 'green'
|
|
|
|
},
|
|
|
|
lockedText() {
|
|
|
|
return this.day.locked ? 'gesperrt' : 'frei'
|
|
|
|
},
|
|
|
|
lockedTextBtn() {
|
|
|
|
return this.day.locked ? 'freigeben' : 'sperren'
|
2020-01-19 20:31:48 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
worker(newValue, oldValue) {
|
2020-01-23 10:11:26 +00:00
|
|
|
if (oldValue !== newValue && this.focused) {
|
2020-01-19 20:31:48 +00:00
|
|
|
let addedUser = null
|
|
|
|
for (let user in newValue) {
|
|
|
|
if (!oldValue.includes(newValue[user])) {
|
|
|
|
addedUser = newValue[user]
|
2020-01-23 10:11:26 +00:00
|
|
|
this.addUser({
|
|
|
|
date: this.day.date.getTime() / 1000,
|
2020-02-23 10:19:53 +00:00
|
|
|
user: addedUser,
|
|
|
|
year: this.day.date.getFullYear(),
|
|
|
|
month: this.day.date.getMonth() + 1,
|
|
|
|
day: this.day.date.getDate()
|
2020-01-23 10:11:26 +00:00
|
|
|
})
|
2020-01-19 20:31:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
let deletedUser = null
|
|
|
|
for (let user in oldValue) {
|
|
|
|
if (!newValue.includes(oldValue[user])) {
|
|
|
|
deletedUser = oldValue[user]
|
2020-02-24 11:19:13 +00:00
|
|
|
console.log('deleteUser', deletedUser, this.day.date)
|
2020-01-23 10:11:26 +00:00
|
|
|
this.deleteUser({
|
|
|
|
startdatetime: this.day.date,
|
|
|
|
date: this.day.date.getTime() / 1000,
|
2020-02-23 10:19:53 +00:00
|
|
|
user: deletedUser,
|
|
|
|
year: this.day.date.getFullYear(),
|
|
|
|
month: this.day.date.getMonth() + 1,
|
|
|
|
day: this.day.date.getDate()
|
2020-01-23 10:11:26 +00:00
|
|
|
})
|
2020-01-19 20:31:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-23 10:11:26 +00:00
|
|
|
},
|
|
|
|
day() {
|
|
|
|
this.getUser({
|
|
|
|
date: this.day.date.getTime() / 1000,
|
2020-02-23 10:19:53 +00:00
|
|
|
startdatetime: this.day.date,
|
|
|
|
year: this.day.date.getFullYear(),
|
|
|
|
month: this.day.date.getMonth() + 1,
|
|
|
|
day: this.day.date.getDate()
|
2020-01-23 10:11:26 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
focused(newVal, oldValue) {
|
|
|
|
console.log(newVal, oldValue)
|
2020-01-19 20:31:48 +00:00
|
|
|
}
|
2020-01-18 11:49:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped></style>
|