From 33028050fc5c9358de38bd95b828273a9d3d0bdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Tue, 2 Jun 2020 23:23:38 +0200 Subject: [PATCH] =?UTF-8?q?user=20kann=20eine=20dienst=C3=BCbertragung=20a?= =?UTF-8?q?nnehmen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit bugfixes, sodass bei Einladungen oder dienstübertragungen der tag neu geladen wird. Ladezeichen hinzugefügt. --- .../user/JobRequests/JobInvites.vue | 26 +- .../user/JobRequests/JobTransfer.vue | 128 +++++- src/components/user/JobsRequest.vue | 13 +- src/components/user/UserNavigation.vue | 21 +- .../ServiceManagementComponents/Day.vue | 60 ++- src/plugins/routes.js | 3 + src/store/index.js | 4 +- src/store/modules/jobInvites.js | 10 + src/store/modules/jobRequests.js | 371 ++++++++++++++++++ src/store/modules/serviceManagement.js | 30 +- 10 files changed, 613 insertions(+), 53 deletions(-) create mode 100644 src/store/modules/jobRequests.js diff --git a/src/components/user/JobRequests/JobInvites.vue b/src/components/user/JobRequests/JobInvites.vue index 2072d80..46a6e80 100644 --- a/src/components/user/JobRequests/JobInvites.vue +++ b/src/components/user/JobRequests/JobInvites.vue @@ -18,23 +18,27 @@ {{ jobInvite.from_user.lastname }} - - - {{ check }} - + + + {{ check }} + + + - - - - - {{ jobInvite.watched ? seen : notSeen }} - - + + + + + {{ jobInvite.watched ? seen : notSeen }} + + + -
-

- Transfer -

+
+ + + Eingehende Anfragen + + + + + + {{ jobrequest.on_date.getDate() }}.{{ + jobrequest.on_date.getMonth() + 1 + }}.{{ jobrequest.on_date.getFullYear() }} von + {{ jobrequest.from_user.firstname }} + {{ jobrequest.from_user.lastname }} + + + + + + + + + + + + {{ jobrequest.watched ? seen : notSeen }} + + + + + + + + Annehmen + + + + + + + +

+ fromme +

+
+ {{ jobrequest }}
+
- + diff --git a/src/components/user/JobsRequest.vue b/src/components/user/JobsRequest.vue index 1d20c53..c2283f6 100644 --- a/src/components/user/JobsRequest.vue +++ b/src/components/user/JobsRequest.vue @@ -2,11 +2,13 @@
- Diensteinladungen + + Diensteinladungen + + + + Dienstübertragung - Dienstübertragung @@ -33,7 +35,8 @@ export default { }, computed: { ...mapGetters({ - news: 'jobInvites/news' + newsInvite: 'jobInvites/news', + newsRequest: 'jobRequests/news' }) }, created() { diff --git a/src/components/user/UserNavigation.vue b/src/components/user/UserNavigation.vue index 7c76bd8..5d0d574 100644 --- a/src/components/user/UserNavigation.vue +++ b/src/components/user/UserNavigation.vue @@ -77,20 +77,31 @@ export default { methods: { ...mapActions({ getJobInvites: 'jobInvites/getJobInvites', + getJobRequests: 'jobRequests/getJobRequests', getUser: 'user/getUser' }) }, computed: { ...mapGetters({ - news: 'jobInvites/news' - }) + newsInvite: 'jobInvites/news', + newsRequest: 'jobRequests/news', + loading: 'user/loading' + }), + news() { + return this.newsInvite + this.newsRequest + } }, created() { this.getUser() - setTimeout(() => { - this.getJobInvites() - }, 500) + }, + watch: { + loading(newValue) { + if (!newValue) { + this.getJobInvites() + this.getJobRequests() + } + } } } diff --git a/src/components/vorstand/ServiceManagementComponents/Day.vue b/src/components/vorstand/ServiceManagementComponents/Day.vue index 202367f..ac92a66 100644 --- a/src/components/vorstand/ServiceManagementComponents/Day.vue +++ b/src/components/vorstand/ServiceManagementComponents/Day.vue @@ -309,10 +309,12 @@ export default { var retVal = 'yellow' retVal = 'light-green' for (var jobkind in day.jobkinddate) { - if (day.jobkinddate[jobkind].worker.length >= day.jobkinddate[jobkind].maxpersons) + if ( + day.jobkinddate[jobkind].worker.length >= + day.jobkinddate[jobkind].maxpersons + ) retVal = 'light-green' - else - return 'yellow' + else return 'yellow' } return retVal } @@ -384,9 +386,41 @@ export default { this.dialog = false }, filterWorker() {}, + // filterUser(jobkind) { + // console.log(jobkind, this.day.jobkinddate) + // 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 + // }) + // }) + // console.log('test', test) + // 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 filterUser(jobkind) { + console.log(jobkind, this.day.jobkinddate) + // eslint-disable-next-line no-unused-vars var filtered = this.dbUsers.filter(user => { - var test = this.day.jobkinddate.find(item => { + var userInOther = this.day.jobkinddate.find(item => { if (item.job_kind === null) { return false } @@ -397,17 +431,21 @@ export default { return work.id === user.id }) }) - if (test) { + if (userInOther) { return false } - if (jobkind.workgroup === null) { + if (jobkind.id === 1 || !jobkind.workgroup) { return true + } else { + if (user.workgroups ? user.workgroups.length > 0 : false) { + return user.workgroups.find(wg => { + console.log(wg, jobkind.workgroup) + return wg.id === jobkind.workgroup.id + }) + } else { + return false + } } - return user.workgroups.find(workgroup => { - if (jobkind.workgroup && workgroup) { - return jobkind.workgroup.id === workgroup.id - } else return true - }) }) return filtered }, diff --git a/src/plugins/routes.js b/src/plugins/routes.js index 8269202..b7a896c 100644 --- a/src/plugins/routes.js +++ b/src/plugins/routes.js @@ -66,6 +66,9 @@ const url = { getJobInvites: main + 'user/getJobInvites', setJobInvites: main + 'user/JobInvites', deletJobInvite: main + 'user/deleteJobInvite', + getJobRequests: main + 'user/getJobRequests', + setJobRequests: main + 'user/JobRequests', + deletJobRequest: main + 'user/deleteJobRequest', storno: main + 'user/storno', getAllStatus: main + 'getAllStatus', getStatus: main + 'getStatus', diff --git a/src/store/index.js b/src/store/index.js index e212536..e68ab38 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -11,6 +11,7 @@ import usermanager from '@/store/modules/userManager' import wm from '@/store/modules/workgroupManagement' import jkm from '@/store/modules/jobkindManager' import jobInvites from "@/store/modules/jobInvites"; +import jobRequests from "@/store/modules/jobRequests"; Vue.use(Vuex) @@ -26,6 +27,7 @@ export default new Vuex.Store({ usermanager, wm, jkm, - jobInvites + jobInvites, + jobRequests } }) diff --git a/src/store/modules/jobInvites.js b/src/store/modules/jobInvites.js index 65607cf..b5094f8 100644 --- a/src/store/modules/jobInvites.js +++ b/src/store/modules/jobInvites.js @@ -175,6 +175,7 @@ const mutations = { const actions = { async getJobInvites({ commit, dispatch, rootState, getters }) { try { + commit('setJobInvitesLoading', true) const date = new Date() const from_me = await axios.post( url.user.getJobInvites, @@ -232,6 +233,7 @@ const actions = { commit('updateMonthWorker', { workers: item.worker, date, getters, from_me: false }) commit('updateMonthLocked', { locked: item.day.locked, date, getters, from_me: false }) }) + commit('setJobInvitesLoading', false) dispatch('getLifeTime', null, { root: true }) } catch (e) { if (e.response) @@ -256,6 +258,7 @@ const actions = { var date = new Date(data.year, data.month - 1, data.day) commit('setDayLoading', { date, getters, value: true }) try { + commit('setJobInvitesLoading', true) const response = await axios.post( url.user.addJob, { ...data }, @@ -270,6 +273,7 @@ const actions = { }) commit('setDayLoading', { date, getters, value: false }) dispatch('getLifeTime', null, { root: true }) + commit('setJobInvitesLoading', false) } catch (e) { if (e.response) if (e.response.status === 401) dispatch('logout', null, { root: true }) @@ -278,6 +282,7 @@ const actions = { async deleteJob({ commit, rootState, dispatch, getters }, data) { var date = new Date(data.year, data.month - 1, data.day) commit('setDayLoading', {date, getters, value: true}) + commit('setJobInvitesLoading', true) try { const response = await axios.post( url.user.deleteJob, @@ -294,6 +299,7 @@ const actions = { }) commit('setDayLoading', {date, getters, value: false}) dispatch('getLifeTime', null, { root: true }) + commit('setJobInvitesLoading', false) } catch (e) { console.log(e) if (e.response) @@ -302,11 +308,13 @@ const actions = { }, async updateJobInviteToMe({ commit, rootState, dispatch }, data) { try { + commit('setJobInvitesLoading', true) const response = await axios.post(url.user.setJobInvites, data, { headers: { Token: rootState.login.user.accessToken } }) commit('updateJobInviteToMe', response.data) dispatch('getLifeTime', null, { root: true }) + commit('setJobInvitesLoading', false) } catch (e) { if (e.response) if (e.response.status === 401) dispatch('logout', null, { root: true }) @@ -314,8 +322,10 @@ const actions = { }, async deleteJobInviteFromMe({ commit, rootState, dispatch}, data) { try { + commit('setJobInvitesLoading', true) await axios.post(url.user.deletJobInvite, data, {headers: {Token: rootState.login.user.accessToken}}) commit('deleteJobInviteFromMe', data) + commit('setJobInvitesLoading', false) } catch (e) { if (e.response) if (e.response.status === 401) dispatch('logout', null, { root: true }) diff --git a/src/store/modules/jobRequests.js b/src/store/modules/jobRequests.js new file mode 100644 index 0000000..cf9af9e --- /dev/null +++ b/src/store/modules/jobRequests.js @@ -0,0 +1,371 @@ +import axios from 'axios' +import url from '@/plugins/routes' + +const state = { + jobRequestsFromMe: [], + jobRequestsToMe: [], + jobRequestsLoading: false +} + +const mutations = { + setJobRequestsFromMe: (state, jobRequests) => { + state.jobRequestsFromMe = jobRequests + state.jobRequestsFromMe.forEach(item => { + item.on_date = new Date( + item.on_date.year, + item.on_date.month - 1, + item.on_date.day + ) + item.day = { + date: new Date(), + worker: [], + loading: false, + locked: false, + jobkinddate: [] + } + }) + }, + setJobRequestsToMe: (state, jobRequests) => { + state.jobRequestsToMe = jobRequests + state.jobRequestsToMe.forEach(item => { + item.on_date = new Date( + item.on_date.year, + item.on_date.month - 1, + item.on_date.day + ) + item.day = { + date: new Date(), + worker: [], + loading: false, + locked: false, + jobkinddate: [] + } + }) + }, + setJobRequestsLoading: (state, value) => { + state.jobRequestsLoading = value + }, + updateJobRequestToMe: (state, jobRequest) => { + state.jobRequestsToMe.forEach(item => { + if (item.id === jobRequest.id) { + item.watched = jobRequest.watched + item.accepted = jobRequest.accepted + } + }) + }, + updateMonthWorker: (state, { workers, date, getters, from_me }) => { + let mop + if (from_me) { + mop = getters.getDayFromMe(date) + } else { + mop = getters.getDayToMe(date) + } + mop.forEach(a => { + let day = a.day + 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) + } + }) + }) + }) + }, + updateMonthLocked: (state, { locked, date, getters, from_me }) => { + let mop + if (from_me) { + mop = getters.getDayFromMe(date) + } else { + mop = getters.getDayToMe(date) + } + mop.forEach(a => { + let day = a.day + day.locked = !!locked + }) + }, + updateMonthJobkind: (state, { data, date, getters, from_me }) => { + let mop + if (from_me) { + mop = getters.getDayFromMe(date) + } else { + mop = getters.getDayToMe(date) + } + mop.forEach(a => { + let day = a.day + day.date = 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 + : [] + } + }) + console.log(mop) + }, + setDayLoading: (state, { getters, date, value }) => { + let day = getters.getDayToMe(date) + day.forEach(a => { + a.day.loading = value + console.log('day', value ? 'loading' : 'not loading', day, a.day.loading) + }) + }, + deleteJobRequestFromMe: (state, jobrequest) => { + var item = state.jobRequestsFromMe.find(item => { + return item.id === jobrequest.id + }) + state.jobRequestsFromMe.splice(item, 1) + } +} + +const actions = { + async getJobRequests({ commit, dispatch, rootState, getters }) { + try { + commit('setJobRequestsLoading', true) + const date = new Date() + const from_me = await axios.post( + url.user.getJobRequests, + { + from_user: rootState.user.user, + date: { + year: date.getFullYear(), + month: date.getMonth() + 1, + day: date.getDate() + } + }, + { headers: { Token: rootState.login.user.accessToken } } + ) + const workers_from_me = await axios.post( + url.user.getJobOnDates, + from_me.data, + { headers: { Token: rootState.login.user.accessToken } } + ) + commit('setJobRequestsFromMe', from_me.data) + workers_from_me.data.forEach(item => { + var date = new Date( + item.day.date.year, + item.day.date.month - 1, + item.day.date.day + ) + commit('updateMonthJobkind', { + data: item.jobkinddate, + date, + getters, + from_me: true + }) + commit('updateMonthWorker', { + workers: item.worker, + date, + getters, + from_me: true + }) + commit('updateMonthLocked', { + locked: item.day.locked, + date, + getters, + from_me: true + }) + }) + const to_me = await axios.post( + url.user.getJobRequests, + { + to_user: rootState.user.user, + date: { + year: date.getFullYear(), + month: date.getMonth() + 1, + day: date.getDate() + } + }, + { headers: { Token: rootState.login.user.accessToken } } + ) + const workers_to_me = await axios.post( + url.user.getJobOnDates, + to_me.data, + { headers: { Token: rootState.login.user.accessToken } } + ) + console.log(to_me.data) + commit('setJobRequestsToMe', to_me.data) + workers_to_me.data.forEach(item => { + var date = new Date( + item.day.date.year, + item.day.date.month - 1, + item.day.date.day + ) + commit('updateMonthJobkind', { + data: item.jobkinddate, + date, + getters, + from_me: false + }) + commit('updateMonthWorker', { + workers: item.worker, + date, + getters, + from_me: false + }) + commit('updateMonthLocked', { + locked: item.day.locked, + date, + getters, + from_me: false + }) + }) + commit('setJobRequestsLoading', false) + dispatch('getLifeTime', null, { root: true }) + } catch (e) { + if (e.response) + if (e.response.status === 401) dispatch('logout', null, { root: true }) + } + }, + async setJobRequests({ commit, dispatch, rootState }, data) { + try { + commit('setJobRequestsLoading', true) + const response = await axios.put(url.user.setJobRequests, data, { + headers: { Token: rootState.login.user.accessToken } + }) + commit('setJobRequestsFromMe', response.data) + commit('setJobRequestsLoading', false) + dispatch('getLifeTime', null, { root: true }) + } catch (e) { + if (e.response) + if (e.response.status === 401) dispatch('logout', null, { root: true }) + } + }, + async updateJobRequestToMe({ commit, rootState, dispatch }, data) { + try { + commit('setJobRequestsLoading', true) + data.on_date = { + year: data.on_date.getFullYear(), + month: data.on_date.getMonth() + 1, + day: data.on_date.getDate() + } + const response = await axios.post(url.user.setJobRequests, data, { + headers: { Token: rootState.login.user.accessToken } + }) + response.data.on_date = new Date(response.data.on_date.year, response.data.on_date.month - 1, response.data.on_date.day) + commit('updateJobRequestToMe', response.data) + commit('setJobRequestsLoading', false) + dispatch('getLifeTime', null, { root: true }) + } catch (e) { + if (e.response) + if (e.response.status === 401) dispatch('logout', null, { root: true }) + } + }, + async deleteJobRequestFromMe({ commit, rootState, dispatch }, data) { + try { + commit('setJobRequestsLoading', true) + await axios.post(url.user.deletJobRequest, data, { + headers: { Token: rootState.login.user.accessToken } + }) + commit('deleteJobRequestFromMe', data) + commit('setJobRequestsLoading', false) + } catch (e) { + if (e.response) + if (e.response.status === 401) dispatch('logout', null, { root: true }) + } + } +} + +const getters = { + jobRequestsFromMe: state => { + return state.jobRequestsFromMe + }, + jobRequestsToMe: state => { + return state.jobRequestsToMe + }, + jobRequestsLoading: state => { + return state.jobRequestsLoading + }, + getDayToMe: state => { + return date => { + return state.jobRequestsToMe.filter(item => { + return item.on_date - date === 0 + }) + } + }, + getDayFromMe: state => { + return date => { + return state.jobRequestsFromMe.filter(item => { + return item.on_date - date === 0 + }) + } + }, + getDayWorkerFromMe: state => { + return date => { + return state.jobRequestsFromMe.filter(jobRequest => { + return jobRequest.on_date - date === 0 + }) + } + }, + news: state => { + var test = state.jobRequestsToMe.filter(item => { + return !item.watched + }) + return test.length + } +} + +export default { + namespaced: true, + state, + mutations, + actions, + getters +} diff --git a/src/store/modules/serviceManagement.js b/src/store/modules/serviceManagement.js index a66798f..148799b 100644 --- a/src/store/modules/serviceManagement.js +++ b/src/store/modules/serviceManagement.js @@ -164,18 +164,26 @@ const mutations = { // eslint-disable-next-line no-unused-vars updateMonthWorker: (state, { workers, date, getters }) => { var day = getters.getDay(date) - for (var worker in workers) { - var jobkind = day.jobkinddate.find(jobkind => { - return ( - jobkind.job_kind.id === - (workers[worker].job_kind ? workers[worker].job_kind.id : 1) - ) + day.jobkinddate.forEach(item => { + var filtered = workers.filter(worker => { + return item.job_kind.id === (worker.job_kind ? worker.job_kind.id : 1) }) - if (jobkind) { - jobkind.worker.push(workers[worker].user) - jobkind.backupWorker.push(workers[worker].user) - } - } + 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.backupWorker.push(worker) + } + }) + item.worker.forEach(worker => { + if (!filteredWorkers.find(a => {return a.id === worker.id})) { + item.worker.splice(item.worker.indexOf(worker), 1) + } + }) + }) }, updateMonthLocked: (state, { locked, date, getters }) => { var day = getters.getDay(date)