flaschengeist-frontend/src/components/vorstand/ServiceManagementComponents/Day.vue

522 lines
16 KiB
Vue
Raw Normal View History

2020-01-18 11:49:49 +00:00
<template>
2020-01-19 20:31:48 +00:00
<div v-if="day">
<v-card :color="color(day)" max-width="20em">
2020-01-19 20:31:48 +00:00
<v-card-title v-if="day.date" class="subtitle-1 font-weight-bold">
{{ day.name }} {{ day.date.getDate() }}.{{ day.date.getMonth() + 1 }}.{{
day.date.getFullYear()
}}
<v-spacer />
<v-btn icon small @click="dialog = true">
<v-icon>{{ menuIcon }}</v-icon>
</v-btn>
2020-01-19 20:31:48 +00:00
</v-card-title>
<v-card-text>
<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" />
</v-row>
</v-expand-transition>
<div v-for="(jobkinddateitem, index) in day.jobkinddate" :key="index">
<div
v-if="
jobkinddateitem.job_kind
? jobkinddateitem.job_kind.id !== 0
: false
"
>
<v-expand-transition>
<div v-show="!day.loading">
<v-autocomplete
chips
return-object
multiple
:counter="jobkinddateitem.maxpersons"
v-model="jobkinddateitem.worker"
:items="filterUser(jobkinddateitem.job_kind)"
:item-text="item => item.firstname + ' ' + item.lastname"
:label="jobkinddateitem.job_kind.name"
filled
color="green"
@blur="focused = false"
@focus="focused = true"
:key="update"
@change="forceRenderer(jobkinddateitem)"
>
<template v-slot:prepend-inner>
<v-icon>{{ account_add }}</v-icon>
</template>
<template v-slot:selection="data">
<v-chip
v-bind="data.attrs"
:input-value="data.selected"
close
@click="data.select"
@click:close="remove(jobkinddateitem, data.item)"
>{{ data.item.firstname }} {{ data.item.lastname }}
</v-chip>
</template>
</v-autocomplete>
</div>
</v-expand-transition>
</div>
</div>
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>
2020-02-24 11:19:13 +00:00
<v-spacer />
2020-03-13 17:07:57 +00:00
<v-btn text @click="lock">{{ lockedTextBtn }}</v-btn>
2020-02-24 11:19:13 +00:00
</v-card-actions>
2020-01-19 20:31:48 +00:00
</v-card>
<v-dialog v-model="dialog">
<v-card>
<v-card-title>
Bearbeite Tag
</v-card-title>
<v-card-text>
<div>
<v-row v-if="!isBarDienstIn">
<v-col cols="8">
<v-text-field readonly outlined value="Bardienst" />
</v-col>
<v-col cols="2">
<v-text-field
outlined
label="Maximale Personen"
type="number"
v-model="maxpersons"
@change="createBarJobKindDate(maxpersons)"
/>
</v-col>
<v-col cols="2"> </v-col>
</v-row>
<v-row
v-for="(jobkinddateitem, index) in day.jobkinddate"
:key="index"
>
<v-col cols="8">
<v-text-field
v-if="!jobkinddateitem.new"
readonly
outlined
:value="jobkinddateitem.job_kind.name"
/>
<v-autocomplete
v-else
outlined
:items="filterJobKinds(jobkinddateitem, index)"
:rules="rules"
item-text="name"
item-value="id"
v-model="jobkinddateitem.job_kind"
return-object
></v-autocomplete>
</v-col>
<v-col cols="2">
<v-text-field
outlined
label="Maximale Personen"
type="number"
v-model="jobkinddateitem.maxpersons"
/>
</v-col>
<v-col cols="2">
<div v-if="jobkinddateitem.job_kind !== null">
<div v-if="jobkinddateitem.job_kind.id !== 1">
<v-btn
v-if="jobkinddateitem.id === 0"
fab
x-small
color="green"
@click="undoDelteJobKindDate(index)"
>
<v-icon>{{ plusIcon }}</v-icon>
</v-btn>
<v-btn
v-else
fab
x-small
color="red"
@click="deleteJobKindDate(index)"
>
<v-icon>{{ minusIcon }}</v-icon>
</v-btn>
</div>
</div>
<div v-else>
<v-btn
v-if="jobkinddateitem.id === 0"
fab
x-small
color="green"
@click="undoDelteJobKindDate(index)"
>
<v-icon>{{ plusIcon }}</v-icon>
</v-btn>
<v-btn
v-else
fab
x-small
color="red"
@click="deleteJobKindDate(index)"
>
<v-icon>{{ minusIcon }}</v-icon>
</v-btn>
</div>
</v-col>
<v-row v-if="jobkinddateitem.id === 0">
<v-col>
<v-alert dense type="info"
>{{ jobkinddateitem.job_kind.name }} wird beim Speichern
gelöscht.</v-alert
>
</v-col>
</v-row>
</v-row>
</div>
<v-row>
<v-spacer />
<v-btn
fab
small
color="green darken-1"
@click="addJobKindDate()"
:disabled="disableAddBtn"
>
<v-icon>{{ plusIcon }}</v-icon>
</v-btn>
</v-row>
</v-card-text>
<v-card-actions>
<v-spacer />
<v-btn text color="primary" @click="dialog = false">
Abbrechen
</v-btn>
<v-btn text color="primary" @click="saveJobKind()">
Speichern
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
2020-01-19 20:31:48 +00:00
</div>
2020-01-18 11:49:49 +00:00
</template>
<script>
import { mapGetters, mapActions } from 'vuex'
import { mdiAccountPlus, mdiDotsVertical, mdiPlus, mdiMinus } from '@mdi/js'
2020-01-18 11:49:49 +00:00
export default {
name: 'Day',
props: {
day: Object
},
data() {
return {
account_add: mdiAccountPlus,
menuIcon: mdiDotsVertical,
plusIcon: mdiPlus,
minusIcon: mdiMinus,
searchInput: null,
focused: false,
dialog: false,
update: 0,
maxpersons: 2,
rules: [
data => {
if (data === null) return false
var list = this.day.jobkinddate.filter(a => {
if (a.job_kind === null) return false
else {
return a.job_kind.id === data.id
}
})
return list.length > 1 ? data.name + 'ist schon vorhanden' : false
}
],
workerRules: [
(data, test) => {
console.log(data, test)
return false
}
],
backup: null
}
2020-01-19 20:31:48 +00:00
},
created() {
this.setLoading(this.day.date)
2020-01-18 11:49:49 +00:00
},
methods: {
...mapActions({
2020-01-19 20:31:48 +00:00
addUser: 'sm/addUser',
deleteUser: 'sm/deleteUser',
setLoading: 'sm/setDayLoading',
2020-02-24 11:19:13 +00:00
setNotLoading: 'sm/setDayNotLoading',
lockDay: 'sm/lockDay',
updateJobKindDate: 'sm/updateJobKindDate'
2020-01-18 11:49:49 +00:00
}),
forceRenderer(jobkind) {
console.log(jobkind)
this.update += 1
console.log('before', jobkind.worker, jobkind.backupWorker)
if (jobkind.backupWorker !== jobkind.worker && this.focused) {
let addedUser = null
for (let user in jobkind.worker) {
if (!jobkind.backupWorker.includes(jobkind.worker[user])) {
addedUser = jobkind.worker[user]
this.addUser({
date: this.day.date.getTime() / 1000,
user: addedUser,
year: this.day.date.getFullYear(),
month: this.day.date.getMonth() + 1,
day: this.day.date.getDate(),
job_kind: jobkind.job_kind
})
}
}
let deletedUser = null
for (let user in jobkind.backupWorker) {
if (!jobkind.worker.includes(jobkind.backupWorker[user])) {
deletedUser = jobkind.backupWorker[user]
this.deleteUser({
startdatetime: this.day.date,
date: this.day.date.getTime() / 1000,
user: deletedUser,
year: this.day.date.getFullYear(),
month: this.day.date.getMonth() + 1,
day: this.day.date.getDate()
})
}
}
}
jobkind.backupWorker = [...jobkind.worker]
},
2020-01-19 20:31:48 +00:00
// eslint-disable-next-line no-unused-vars
remove(jobkind, deletedUser) {
jobkind.worker.indexOf()
const obj = jobkind.worker.find(a => {
2020-01-19 20:31:48 +00:00
return a.username === deletedUser.username
})
const index = jobkind.worker.indexOf(obj)
if (index >= 0) jobkind.worker.splice(index, 1)
this.forceRenderer(jobkind)
},
color(day) {
2020-01-19 20:31:48 +00:00
if (day) {
if (day.date.getDay() === 0 || day.date.getDay() === 1) {
return 'grey lighten-4'
} else {
var retVal = 'yellow'
retVal = 'light-green'
for (var jobkind in day.jobkinddate) {
if (day.jobkinddate[jobkind].worker.length >= day.jobkinddate[jobkind].maxpersons)
retVal = 'light-green'
else
return 'yellow'
2020-01-19 20:31:48 +00:00
}
return retVal
2020-01-19 20:31:48 +00:00
}
} else {
return 'grey lighten-4'
}
},
2020-02-24 11:19:13 +00:00
lock() {
2020-03-13 17:07:57 +00:00
this.lockDay({
year: this.day.date.getFullYear(),
month: this.day.date.getMonth() + 1,
day: this.day.date.getDate(),
locked: !this.day.locked
})
},
createBarJobKindDate(maxpersons) {
this.day.jobkinddate.push({
id: -1,
job_kind: Object.assign(
{},
this.jobkinds.find(a => {
return a.id === 1
})
),
maxpersons: maxpersons,
daydate: {
year: this.day.date.getFullYear(),
month: this.day.date.getMonth() + 1,
day: this.day.date.getDate()
},
worker: [],
backupWorker: []
})
},
addJobKindDate() {
this.day.jobkinddate.push({
id: -1,
job_kind: null,
maxpersons: 2,
new: true,
daydate: {
year: this.day.date.getFullYear(),
month: this.day.date.getMonth() + 1,
day: this.day.date.getDate()
},
worker: [],
backupWorker: []
})
},
mop(jobkind) {
console.log(jobkind.worker)
},
deleteJobKindDate(index) {
if (this.day.jobkinddate[index].id === -1) {
this.day.jobkinddate.splice(index, 1)
} else {
this.day.jobkinddate[index].backupid = this.day.jobkinddate[index].id
this.day.jobkinddate[index].id = 0
}
},
undoDelteJobKindDate(index) {
this.day.jobkinddate[index].id = this.day.jobkinddate[index].backupid
},
saveJobKind() {
this.updateJobKindDate({
data: this.day.jobkinddate,
date: this.day.date
})
this.dialog = false
},
filterWorker() {},
filterUser(jobkind) {
var filtered = this.dbUsers.filter(user => {
var test = this.day.jobkinddate.find(item => {
if (item.job_kind === null) {
return false
}
if (item.job_kind.id === jobkind.id) {
return false
}
return item.worker.find(work => {
return work.id === user.id
})
})
if (test) {
return false
}
if (jobkind.workgroup === null) {
return true
}
return user.workgroups.find(workgroup => {
if (jobkind.workgroup && workgroup) {
return jobkind.workgroup.id === workgroup.id
} else return true
})
})
return filtered
},
// eslint-disable-next-line no-unused-vars
filterJobKinds(jobkinddateitem, index) {
var retVal = this.jobkinds.filter(jobkind => {
return jobkind.id !== 1
})
retVal = retVal.filter(jobkind => {
return !this.day.jobkinddate.find(item => {
if (item.job_kind === jobkinddateitem.job_kind) {
return false
} else {
if (item.job_kind !== null && jobkind !== null)
if (item.job_kind.id === jobkind.id) return true
}
return false
})
})
return retVal
2020-02-24 11:19:13 +00:00
}
2020-01-18 11:49:49 +00:00
},
computed: {
...mapGetters({
allUsers: 'sm/allUsers',
dbUsers: 'usermanager/users',
disabled: 'sm/disabled',
jobkinds: 'jkm/jobkinds'
2020-01-19 20:31:48 +00:00
}),
worker() {
return this.day.worker
2020-02-24 11:19:13 +00:00
},
tada() {
return this.day.jobkinddate
},
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'
},
isBarDienstIn() {
for (var jobkinddate in this.day.jobkinddate) {
if (!(this.day.jobkinddate[jobkinddate].job_kind === null))
if (this.day.jobkinddate[jobkinddate].job_kind.id === 1) return true
}
return false
},
existJobKinds() {
var retVal = [...this.jobkinds]
retVal.splice(
retVal.findIndex(a => {
return a.id === 1
}),
1
)
return retVal
},
disableAddBtn() {
var barset = this.isBarDienstIn ? 0 : 1
return this.day.jobkinddate.length === this.jobkinds.length - barset
2020-01-19 20:31:48 +00:00
}
},
watch: {
worker(newValue, oldValue) {
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]
this.addUser({
date: this.day.date.getTime() / 1000,
user: addedUser,
year: this.day.date.getFullYear(),
month: this.day.date.getMonth() + 1,
day: this.day.date.getDate()
})
2020-01-19 20:31:48 +00:00
}
}
let deletedUser = null
for (let user in oldValue) {
if (!newValue.includes(oldValue[user])) {
deletedUser = oldValue[user]
this.deleteUser({
startdatetime: this.day.date,
date: this.day.date.getTime() / 1000,
user: deletedUser,
year: this.day.date.getFullYear(),
month: this.day.date.getMonth() + 1,
day: this.day.date.getDate()
})
2020-01-19 20:31:48 +00:00
}
}
}
},
dialog(newValue) {
if (newValue) {
this.backup = [...this.day.jobkinddate]
} else {
this.day.jobkinddate = [...this.backup]
this.backup = []
}
2020-01-19 20:31:48 +00:00
}
2020-01-18 11:49:49 +00:00
}
}
</script>
<style scoped></style>