diff --git a/src/components/user/Jobs.vue b/src/components/user/Jobs.vue index 02fd66b..64ad1e5 100644 --- a/src/components/user/Jobs.vue +++ b/src/components/user/Jobs.vue @@ -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) { diff --git a/src/components/user/Jobs/Day.vue b/src/components/user/Jobs/Day.vue index bbdacac..bed17f9 100644 --- a/src/components/user/Jobs/Day.vue +++ b/src/components/user/Jobs/Day.vue @@ -3,7 +3,7 @@ {{ day.name }} den {{ day.date.getDate() }}.{{ - day.date.getMonth() + 1 + day.date.getMonth() + 1 }}.{{ day.date.getFullYear() }} @@ -14,25 +14,36 @@
-
- {{ worker.firstname }} {{ worker.lastname }} +
+
+ {{ jobkinddateitem.job_kind.name }} +
+ + +
-
+
@@ -59,35 +73,43 @@ senden
- -
-
- Du kannst dich nicht zum Bardienst eintragen, da der Tag gesperrt - ist. -
-
- Du kannst dich nicht Bardienst eintragen, da mehr als 2 Personen - schon eingetragen sind. -
-
Hier kannst du dich zum Bardienst eintragen.
+ +
+
Hier kannst du dich zum Bardienst eintragen.
+ + + + + + + {{ jobkinddateitem.job_kind.name }} + + + +
- - Eintragen
@@ -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 } } } diff --git a/src/components/vorstand/ServiceManagementComponents/Day.vue b/src/components/vorstand/ServiceManagementComponents/Day.vue index 270f0e8..2fdefdb 100644 --- a/src/components/vorstand/ServiceManagementComponents/Day.vue +++ b/src/components/vorstand/ServiceManagementComponents/Day.vue @@ -249,7 +249,6 @@ export default { methods: { ...mapActions({ addUser: 'sm/addUser', - getUser: 'sm/getUser', deleteUser: 'sm/deleteUser', setLoading: 'sm/setDayLoading', setNotLoading: 'sm/setDayNotLoading', diff --git a/src/plugins/routes.js b/src/plugins/routes.js index faee231..a746b8a 100644 --- a/src/plugins/routes.js +++ b/src/plugins/routes.js @@ -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 = { diff --git a/src/store/modules/jobs.js b/src/store/modules/jobs.js index 2fd0ca2..07c93cc 100644 --- a/src/store/modules/jobs.js +++ b/src/store/modules/jobs.js @@ -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, - { ...data }, - { headers: { Token: rootState.login.user.accessToken } } + 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 + response.data[day].day.date.year, + response.data[day].day.date.month - 1, + response.data[day].day.date.day ) - commit('setDayNotLoading', { date: 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('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 }) } - 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) diff --git a/src/store/modules/serviceManagement.js b/src/store/modules/serviceManagement.js index 7158aec..8ff9436 100644 --- a/src/store/modules/serviceManagement.js +++ b/src/store/modules/serviceManagement.js @@ -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 {