user können sich in verschiedene dienstarten eintragen.

This commit is contained in:
Tim Gröger 2020-05-24 22:11:41 +02:00
parent 0a6994e107
commit b4f5735947
6 changed files with 251 additions and 144 deletions

View File

@ -70,6 +70,7 @@ export default {
}
},
created() {
this.getActiveUser()
for (let intDate = 1; intDate < 7; intDate++) {
if (
new Date(
@ -81,6 +82,7 @@ export default {
if (this.date.getDate() < intDate)
this.date = new Date(this.date.getFullYear(), this.date.getMonth(), 0)
}
this.getAllJobKinds()
this.createMonth(this.date)
this.getAllUsers()
this.getUsers({
@ -103,10 +105,13 @@ export default {
},
methods: {
...mapActions({
getActiveUser: 'user/getUser',
getTransactJobs: 'requestJobs/getTransactJobs',
createMonth: 'jobs/createMonth',
getAllUsers: 'jobs/getAllUsers',
getUsers: 'jobs/getUsers'
getUsers: 'jobs/getUsers',
getDBUsers: 'usermanager/getUsersWithExtern',
getAllJobKinds: 'jkm/getAllJobKinds',
}),
changeMonth(value) {
if (value === -1) {

View File

@ -14,25 +14,36 @@
</v-expand-transition>
<v-expand-transition>
<div v-show="!day.loading">
<div v-for="worker in day.worker" :key="day.worker.indexOf(worker)">
<div
v-for="(jobkinddateitem, index) in day.jobkinddate"
:key="index"
>
<div class="title black--text text-sm-center">
{{ jobkinddateitem.job_kind.name }}
</div>
<v-combobox
multiple
filled
disabled
readonly
:counter="jobkinddateitem.maxpersons"
v-model="jobkinddateitem.worker"
:item-text="item => item.firstname + ' ' + item.lastname"
item-value="username"
chips
append-icon=""
>
<template v-slot:selection="data">
<v-chip
style="margin: 3px;"
:close="
(user(worker) && !day.locked) || (canDelete && user(worker))
"
@click:close="
deleteJob({
year: day.date.getFullYear(),
month: day.date.getMonth() + 1,
day: day.date.getDate()
})
"
>{{ worker.firstname }} {{ worker.lastname }}</v-chip>
>{{ data.item.firstname }} {{ data.item.lastname }}</v-chip
>
</template>
</v-combobox>
</div>
</div>
</v-expand-transition>
</v-card-text>
<div v-if="userInWorker && day.locked">
<div v-if="userInWorker() && day.locked">
<v-card-actions class="text--secondary">
<v-autocomplete
return-object
@ -50,7 +61,10 @@
</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-title
>{{ data.item.firstname }}
{{ data.item.lastname }}</v-list-item-title
>
</v-list-item-content>
</template>
</v-autocomplete>
@ -59,35 +73,43 @@
<v-btn text block @click="send">senden</v-btn>
</v-card-actions>
</div>
<v-card-actions class="text--secondary">
<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>
<v-card-actions
class="text--secondary"
v-if="!day.loading"
v-show="filterAddJob.length > 0 && !userInWorker()"
>
<div>
<div>Hier kannst du dich zum Bardienst eintragen.</div>
<v-spacer />
<v-menu
v-model="menu"
open-on-hover
close-on-click
close-on-content-click
offset-y
>
<template v-slot:activator="{ on }">
<v-btn
text
v-if="
!day.locked &&
!day.loading &&
day.worker.length < 2 &&
!userInWorker
"
@click="
addJob({
year: day.date.getFullYear(),
month: day.date.getMonth() + 1,
day: day.date.getDate()
})
"
>Eintragen</v-btn>
v-on="on"
v-show="filterAddJob.length > 0 && !userInWorker()"
>
Eintragen
</v-btn>
</template>
<v-list>
<v-list-item
v-for="(jobkinddateitem, index) in filterAddJob"
:key="index"
@click="addingJob(jobkinddateitem)"
>
<v-list-item-title>
{{ jobkinddateitem.job_kind.name }}
</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
</div>
</v-card-actions>
</v-card>
</div>
@ -105,7 +127,9 @@ export default {
return {
account_add: mdiAccountPlus,
searchInput: null,
requestUser: null
requestUser: null,
menu: false,
update: 0
}
},
created() {
@ -134,11 +158,17 @@ export default {
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'
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'
}
return retVal
}
} else {
return 'grey lighten-4'
@ -146,20 +176,37 @@ export default {
},
user(worker) {
return worker.username === this.activeUser.username
},
addingJob(jobkinddateitem) {
this.addJob({
year: this.day.date.getFullYear(),
month: this.day.date.getMonth() + 1,
day: this.day.date.getDate(),
job_kind: jobkinddateitem.job_kind
})
this.menu = false
setTimeout(() => {
this.update += 1
}, 200)
console.log('after adding Job', this.day.jobkinddate)
},
userInWorker() {
var jobkinddate = this.day.jobkinddate.find(item => {
return item.worker.find(workeritem => {
return workeritem.id === this.activeUser.id
})
})
console.log('userin', !!jobkinddate, !jobkinddate)
return !!jobkinddate
}
},
computed: {
...mapGetters({
disabled: 'jobs/disabled',
activeUser: 'user',
activeUser: 'user/user',
allUsers: 'jobs/allUsers',
transactJobs: 'requestJobs/transactJobs'
}),
userInWorker() {
return this.day.worker.find(a => {
return a.username === this.activeUser.username
})
},
specifiedUsers() {
var users = [...this.allUsers]
for (var i in this.day.worker) {
@ -179,11 +226,24 @@ export default {
return a.accepted && a.answerd
})
return test
}
},
watch: {
worker() {
return this.day.worker
filterAddJob() {
var retVal = this.day.jobkinddate.filter(item => {
if (item.maxpersons <= item.worker.length) {
return false
}
if (!item.job_kind.workgroup) {
return true
} else {
if (this.activeUser.workgroups) {
return this.activeUser.workgroups.find(workgroup => {
return workgroup.id === item.job_kind.workgroup.id
})
}
}
})
console.log('filterAddJob', retVal, retVal.length > 0, this.user.workgroups)
return retVal
}
}
}

View File

@ -249,7 +249,6 @@ export default {
methods: {
...mapActions({
addUser: 'sm/addUser',
getUser: 'sm/getUser',
deleteUser: 'sm/deleteUser',
setLoading: 'sm/setDayLoading',
setNotLoading: 'sm/setDayNotLoading',

View File

@ -1,6 +1,6 @@
//const main = 'https://192.168.5.128:5000/'
const main = 'http://localhost:5000/'
//const main = 'http://192.168.5.118:5000/'
//const main = 'http://localhost:5000/'
const main = 'http://192.168.5.118:5000/'
//const main = 'https://groeger-clan.duckdns.org:5000/'
const url = {

View File

@ -52,7 +52,8 @@ const mutations = {
name: 'Montag',
worker: [],
loading: false,
locked: false
locked: false,
jobkinddate: []
}
break
case 2:
@ -62,7 +63,8 @@ const mutations = {
name: 'Dienstag',
worker: [],
loading: false,
locked: false
locked: false,
jobkinddate: []
}
break
case 3:
@ -77,7 +79,8 @@ const mutations = {
name: 'Mittwoch',
worker: [],
loading: false,
locked: false
locked: false,
jobkinddate: []
}
}
break
@ -88,7 +91,8 @@ const mutations = {
name: 'Donnerstag',
worker: [],
loading: false,
locked: false
locked: false,
jobkinddate: []
}
break
case 5:
@ -98,7 +102,8 @@ const mutations = {
name: 'Freitag',
worker: [],
loading: false,
locked: false
locked: false,
jobkinddate: []
}
break
case 6:
@ -108,7 +113,8 @@ const mutations = {
name: 'Samstag',
worker: [],
loading: false,
locked: false
locked: false,
jobkinddate: []
}
break
case 0:
@ -118,7 +124,8 @@ const mutations = {
name: 'Sontag',
worker: [],
loading: false,
locked: false
locked: false,
jobkinddate: []
}
break
}
@ -155,6 +162,80 @@ const mutations = {
}
}
},
// eslint-disable-next-line no-unused-vars
updateMonthWorker: (state, { workers, date, getters }) => {
var day = getters.getDay(date)
day.jobkinddate.forEach(item => {
var filtered = workers.filter(worker => {
return item.job_kind.id === (worker.job_kind ? worker.job_kind.id : 1)
})
var filteredWorkers = []
filtered.forEach(item => {
filteredWorkers.push(item.user)
})
filteredWorkers.forEach(worker => {
if (!item.worker.find(a => {return a.id === worker.id})) {
item.worker.push(worker)
}
})
item.worker.forEach(worker => {
if (!filteredWorkers.find(a => {return a.id === worker.id})) {
item.worker.splice(item.worker.indexOf(worker), 1)
}
})
})
console.log(day)
},
updateMonthLocked: (state, { locked, date, getters }) => {
var day = getters.getDay(date)
day.locked = !!locked
},
updateMonthJobkind: (state, { data, date, getters }) => {
let day = getters.getDay(date)
var backup = []
for (let jobkind in day.jobkinddate) {
if (day.jobkinddate[jobkind].worker !== undefined) {
backup.push({
id: day.jobkinddate[jobkind].job_kind.id,
worker: day.jobkinddate[jobkind].worker,
backupWorker: day.jobkinddate[jobkind].backupWorker
})
} else {
backup.push({
id: day.jobkinddate[jobkind].job_kind.id,
worker: [],
backupWorker: []
})
}
}
day.jobkinddate = [...data]
var test = day.jobkinddate.find(jobkind => {
return jobkind.job_kind.id === 1
})
if (!test) {
day.jobkinddate.push({
id: -1,
job_kind: { id: 1, name: 'Bardienst' },
maxpersons: 2,
daydate: {
year: date.getFullYear(),
month: date.getMonth() + 1,
day: date.getDate()
},
worker: [],
backupWorker: []
})
}
for (var jobkind in day.jobkinddate) {
var worker = backup.find(item => {
return item.id === day.jobkinddate[jobkind].job_kind.id
})
day.jobkinddate[jobkind].worker = worker ? worker.worker : []
day.jobkinddate[jobkind].backupWorker = worker ? worker.backupWorker : []
}
},
setAllDayLoading: state => {
for (let week = 0; week < state.month.length; week++) {
for (let day in state.month[week].days) {
@ -239,62 +320,44 @@ const actions = {
commit('setAllDayLoading')
try {
const response = await axios.post(
url.user.jobs,
url.vorstand.sm.getUsers,
{ ...data },
{ headers: { Token: rootState.login.user.accessToken } }
)
for (let day in response.data) {
for (let item = 0; item < response.data[day].worker.length; item++) {
commit('updateMonth', {
...response.data[day].worker[item],
com: 'add',
day: response.data[day].day
})
}
commit('updateMonth', {
start: response.data[day].day.date,
day: response.data[day].day
})
console.log(response.data)
for (var day in response.data) {
var date = new Date(
response.data[day].day.date.year,
response.data[day].day.date.month - 1,
response.data[day].day.date.day
)
commit('setDayNotLoading', { date: date, getters })
commit('updateMonthJobkind', {
data: [...response.data[day].jobkinddate],
date,
getters
})
commit('updateMonthWorker', {
workers: [...response.data[day].worker],
date,
getters
})
commit('updateMonthLocked', {
locked: response.data[day].day.locked,
date,
getters
})
commit('setDayNotLoading', { date, getters })
}
} catch (e) {
if (e.response)
if (e.response.status === 401) dispatch('logout', null, { root: true })
}
},
async getUser({ commit, rootState, dispatch, getters }, data) {
commit('setDayLoading', { date: data.startdatetime, getters })
try {
const response = await axios.post(
url.user.job,
{ ...data },
{ headers: { Token: rootState.login.user.accessToken } }
)
for (let item = 0; item < response.data.worker.length; item++) {
commit('updateMonth', {
...response.data.worker[item],
com: 'add',
day: response.data.day
})
}
commit('updateMonth', {
start: response.data.day.date,
day: response.data.day
})
commit('setDayNotLoading', { date: data.startdatetime, getters })
dispatch('getLifeTime', null, { root: true })
} catch (e) {
if (e.response)
if (e.response.status === 401) dispatch('logout', null, { root: true })
}
},
async addJob({ commit, rootState, dispatch }, data) {
async addJob({ commit, rootState, dispatch, getters }, data) {
var date = new Date(data.year, data.month - 1, data.day)
commit('setDayLoading', {date, getters})
try {
const response = await axios.post(
url.user.addJob,
{ ...data },
@ -302,7 +365,13 @@ const actions = {
headers: { Token: rootState.login.user.accessToken }
}
)
commit('updateMonth', { ...response.data[0], com: 'add' })
console.log(response.data)
commit('updateMonthWorker', {
workers: [...response.data],
date: new Date(data.year, data.month - 1, data.day),
getters
})
commit('setDayNotLoading', {date, getters})
dispatch('getLifeTime', null, { root: true })
} catch (e) {
if (e.response)

View File

@ -321,32 +321,6 @@ const actions = {
if (e.response.status === 401) dispatch('logout', null, { root: true })
}
},
async getUser({ commit, rootState, dispatch, getters }, data) {
commit('setDayLoading', { date: data.startdatetime, getters })
try {
const response = await axios.post(
url.vorstand.sm.getUser,
{ ...data },
{ headers: { Token: rootState.login.user.accessToken } }
)
for (let item = 0; item < response.data.worker.length; item++) {
commit('updateMonth', {
...response.data.worker[item],
com: 'add',
day: response.data.day
})
}
commit('updateMonth', {
start: response.data.day.date,
day: response.data.day
})
commit('setDayNotLoading', { date: data.startdatetime, getters })
dispatch('getLifeTime', null, { root: true })
} catch (e) {
if (e.response)
if (e.response.status === 401) dispatch('logout', null, { root: true })
}
},
// eslint-disable-next-line no-unused-vars
async deleteUser({ commit, rootState, dispatch }, data) {
try {