diff --git a/src/components/vorstand/ServiceManagement.vue b/src/components/vorstand/ServiceManagement.vue index 6a43295..e4fdddb 100644 --- a/src/components/vorstand/ServiceManagement.vue +++ b/src/components/vorstand/ServiceManagement.vue @@ -86,9 +86,10 @@ 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.getDBUsers() this.getUsers({ from_date: { year: this.startDate.getFullYear(), @@ -107,7 +108,9 @@ export default { createMonth: 'sm/createMonth', getAllUsers: 'sm/getAllUsers', getUsers: 'sm/getUsers', - lockDay: 'sm/lockDay' + lockDay: 'sm/lockDay', + getDBUsers: 'usermanager/getUsers', + getAllJobKinds: 'jkm/getAllJobKinds', }), changeMonth(value) { if (value === -1) { diff --git a/src/components/vorstand/ServiceManagementComponents/Day.vue b/src/components/vorstand/ServiceManagementComponents/Day.vue index c34581e..270f0e8 100644 --- a/src/components/vorstand/ServiceManagementComponents/Day.vue +++ b/src/components/vorstand/ServiceManagementComponents/Day.vue @@ -2,9 +2,13 @@
- {{ day.name }} den {{ day.date.getDate() }}.{{ - day.date.getMonth() + 1 - }}.{{ day.date.getFullYear() }} + {{ day.name }} {{ day.date.getDate() }}.{{ day.date.getMonth() + 1 }}.{{ + day.date.getFullYear() + }} + + + {{ menuIcon }} + @@ -12,59 +16,196 @@ - -
- - - - - + +
+
+ +
+ + + + +
+
- +
- {{ lockedText }} + {{ + lockedText + }} {{ lockedTextBtn }} + + + + Bearbeite Tag + + +
+ + + + + + + + + + + + + + + + + + +
+
+ + {{ plusIcon }} + + + {{ minusIcon }} + +
+
+
+ + {{ plusIcon }} + + + {{ minusIcon }} + +
+
+ + + {{ jobkinddateitem.job_kind.name }} wird beim Speichern + gelöscht. + + +
+
+ + + + {{ plusIcon }} + + +
+ + + + Abbrechen + + + Speichern + + +
+
diff --git a/src/plugins/routes.js b/src/plugins/routes.js index 66b4282..faee231 100644 --- a/src/plugins/routes.js +++ b/src/plugins/routes.js @@ -31,13 +31,15 @@ const url = { addUser: main + 'sm/addUser', deleteUser: main + 'sm/deleteUser', getUser: main + 'sm/getUser', - getUsers: main + 'sm/getUsers', + getUsers: main + 'user/jobs', lockDay: main + 'sm/lockDay', searchUser: main + 'sm/searchWithExtern', jobkind: main + 'sm/JobKind', getAllJobKindsbKinds: main + 'sm/getAllJobKinds', getJobKind: main + 'sm/getJobKind', - deleteJobKind: main + 'sm/deleteJobKind' + deleteJobKind: main + 'sm/deleteJobKind', + updateJobKindDates: main + 'jk/JobKindDate', + getJobKindDates: main + 'jk/JobKindDate' }, um: { setStatus: main + 'um/setStatus', diff --git a/src/store/modules/serviceManagement.js b/src/store/modules/serviceManagement.js index a195db8..7158aec 100644 --- a/src/store/modules/serviceManagement.js +++ b/src/store/modules/serviceManagement.js @@ -48,7 +48,8 @@ const mutations = { name: 'Montag', worker: [], loading: false, - locked: false + locked: false, + jobkinddate: [] } break case 2: @@ -58,7 +59,8 @@ const mutations = { name: 'Dienstag', worker: [], loading: false, - locked: false + locked: false, + jobkinddate: [] } break case 3: @@ -73,7 +75,8 @@ const mutations = { name: 'Mittwoch', worker: [], loading: false, - locked: false + locked: false, + jobkinddate: [] } } break @@ -84,7 +87,8 @@ const mutations = { name: 'Donnerstag', worker: [], loading: false, - locked: false + locked: false, + jobkinddate: [] } break case 5: @@ -94,7 +98,8 @@ const mutations = { name: 'Freitag', worker: [], loading: false, - locked: false + locked: false, + jobkinddate: [] } break case 6: @@ -104,7 +109,8 @@ const mutations = { name: 'Samstag', worker: [], loading: false, - locked: false + locked: false, + jobkinddate: [] } break case 0: @@ -114,7 +120,8 @@ const mutations = { name: 'Sontag', worker: [], loading: false, - locked: false + locked: false, + jobkinddate: [] } break } @@ -155,32 +162,72 @@ const mutations = { week.endDate = week.days.monday.date } }, - updateMonth: (state, data) => { - const date = new Date(data.start.year, data.start.month - 1, data.start.day) - const user = data.user - for (let week = 0; week < state.month.length; week++) { - for (let day in state.month[week].days) { - if (state.month[week].days[day].date - date === 0) { - if (user) { - let worker = state.month[week].days[day].worker.find(a => { - return a.username === user.username - }) - if (!worker && data.com === 'add') { - state.month[week].days[day].worker.push({ - firstname: user.firstname, - lastname: user.lastname, - username: user.username, - fullName: user.firstname + ' ' + user.lastname - }) - } - } - if (data.day) { - state.month[week].days[day].locked = data.day.locked - } - } + // 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) + ) + }) + if (jobkind) { + jobkind.worker.push(workers[worker].user) + jobkind.backupWorker.push(workers[worker].user) } } }, + 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) { @@ -221,6 +268,7 @@ const actions = { // eslint-disable-next-line no-unused-vars async addUser({ commit, rootState, dispatch }, data) { try { + // eslint-disable-next-line no-unused-vars const response = await axios.post( url.vorstand.sm.addUser, { ...data }, @@ -228,7 +276,7 @@ const actions = { headers: { Token: rootState.login.user.accessToken } } ) - commit('updateMonth', { ...response.data[0], com: 'add' }) + //commit('updateMonth', { ...response.data[0], com: 'add' }) dispatch('getLifeTime', null, { root: true }) } catch (e) { if (e.response) @@ -244,24 +292,29 @@ const actions = { { ...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) @@ -303,7 +356,7 @@ const actions = { { ...data }, { headers: { Token: rootState.login.user.accessToken } } ) - commit('updateMonth', { ...data, com: 'delete' }) + //commit('updateMonth', { ...data, com: 'delete' }) dispatch('getLifeTime', null, { root: true }) } catch (e) { if (e.response) @@ -324,6 +377,25 @@ const actions = { if (e.response.status === 401) dispatch('logout', null, { root: true }) } }, + async updateJobKindDate( + { commit, rootState, dispatch, getters }, + { data, date } + ) { + try { + commit('setDayLoading', { date, getters }) + const response = await axios.post( + url.vorstand.sm.updateJobKindDates, + [...data], + { headers: { Token: rootState.login.user.accessToken } } + ) + commit('updateMonthJobkind', { data: response.data, date, getters }) + commit('setDayNotLoading', { date, getters }) + dispatch('getLifeTime', null, { root: true }) + } catch (e) { + if (e.response) + if (e.response.status === 401) dispatch('logout', null, { root: true }) + } + }, setDayLoading({ commit, getters }, date) { commit('setDayLoading', { date, getters }) },