From af542bb2e528c0decf3f52dad42a1762cfb671ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Sun, 19 Jan 2020 21:31:48 +0100 Subject: [PATCH] finished serviceManagement --- src/components/vorstand/ServiceManagement.vue | 54 ++++--- .../ServiceManagementComponents/Day.vue | 129 +++++++++++----- src/plugins/routes.js | 9 +- src/store/modules/serviceManagement.js | 139 +++++++++++------- 4 files changed, 217 insertions(+), 114 deletions(-) diff --git a/src/components/vorstand/ServiceManagement.vue b/src/components/vorstand/ServiceManagement.vue index 8586493..276d364 100644 --- a/src/components/vorstand/ServiceManagement.vue +++ b/src/components/vorstand/ServiceManagement.vue @@ -11,7 +11,10 @@ keyboard_arrow_left - {{monthArray[date.getMonth()]}} {{date.getFullYear()}} + {{ monthArray[date.getMonth()] }} + {{ date.getFullYear() }} keyboard_arrow_right @@ -20,17 +23,22 @@ - + Woche vom {{ week.startDate.getDate() }}.{{ - week.startDate.getMonth()+1 - }}.{{week.startDate.getFullYear()}} bis {{ week.endDate.getDate() }}.{{ - week.endDate.getMonth()+1 - }}.{{week.endDate.getFullYear()}} + week.startDate.getMonth() + 1 + }}.{{ week.startDate.getFullYear() }} bis + {{ week.endDate.getDate() }}.{{ week.endDate.getMonth() + 1 }}.{{ + week.endDate.getFullYear() + }} -
- -
+ +
+ + + +
+
@@ -48,18 +56,18 @@ export default { id: 0, date: new Date(), monthArray: [ - 'Januar', - 'Februar', - 'März', - 'April', - 'Mai', - 'Juni', - 'Juli', - 'August', - 'September', - 'Oktober', - 'November', - 'Dezember' + 'Januar', + 'Februar', + 'März', + 'April', + 'Mai', + 'Juni', + 'Juli', + 'August', + 'September', + 'Oktober', + 'November', + 'Dezember' ] } }, @@ -74,9 +82,9 @@ export default { }), changeMonth(value) { if (value === -1) { - this.date = new Date(this.date.getFullYear(), this.date.getMonth(), 0, 1) + this.date = new Date(this.date.getFullYear(), this.date.getMonth() - 1) } else { - this.date = new Date(this.date.getFullYear(), this.date.getMonth() + 2, 0, 1) + this.date = new Date(this.date.getFullYear(), this.date.getMonth() + 1) } this.createMonth(this.date) } diff --git a/src/components/vorstand/ServiceManagementComponents/Day.vue b/src/components/vorstand/ServiceManagementComponents/Day.vue index 84c4266..0b69f14 100644 --- a/src/components/vorstand/ServiceManagementComponents/Day.vue +++ b/src/components/vorstand/ServiceManagementComponents/Day.vue @@ -1,28 +1,46 @@ diff --git a/src/plugins/routes.js b/src/plugins/routes.js index 3fca019..0cbcb75 100644 --- a/src/plugins/routes.js +++ b/src/plugins/routes.js @@ -18,7 +18,14 @@ const url = { finanzerSendAllMail: main + 'finanzerSendAllMail', finanzerSendOneMail: main + 'finanzerSendOneMail', userMain: main + 'user/main', - userAddAmount: main + 'user/addAmount' + userAddAmount: main + 'user/addAmount', + vorstand: { + sm: { + addUser: main + 'sm/addUser', + deleteUser: main + 'sm/deleteUser', + getUser: main + 'sm/getUser' + } + } } export default url diff --git a/src/store/modules/serviceManagement.js b/src/store/modules/serviceManagement.js index 7702697..237da7c 100644 --- a/src/store/modules/serviceManagement.js +++ b/src/store/modules/serviceManagement.js @@ -20,8 +20,7 @@ const mutations = { let id = 0 const year = date.getFullYear() const mon = date.getMonth() - let a = new Date(year, mon, 0, 13, 1) - console.log('createMonth', a) + let a = new Date(year, mon + 1, 0) let days = a.getDate() let startDate = 1 for (let intDay = 1; intDay <= days; intDay++) { @@ -30,45 +29,15 @@ const mutations = { break } } + let end = false let week = { id: id, days: {} } - for (let intDay = startDate; intDay <= days; intDay++) { - let currentDate = new Date(year, mon, intDay, 13, 1) - console.log('currentDate', currentDate) + for (let intDay = startDate; intDay <= days + 7; intDay++) { + if (end) break + let currentDate = new Date(year, mon, intDay, 12) switch (currentDate.getDay()) { case 1: - if (week.days.monday) { - week.startDate = week.days.monday.date - } else if (week.days.tuesday) { - week.startDate = week.days.tuesday.date - } else if (week.days.wednesday) { - week.startDate = week.days.wednesday.date - } else if (week.days.thursday) { - week.startDate = week.days.thursday.date - } else if (week.days.friday) { - week.startDate = week.days.friday.date - } else if (week.days.satturday) { - week.startDate = week.days.satturday.date - } else if (week.days.sunday) { - week.startDate = week.days.sunday.date - } - - if (week.days.sunday) { - week.endDate = week.days.sunday.date - } else if (week.days.satturday) { - week.endDate = week.days.satturday.date - } else if (week.days.friday) { - week.endDate = week.days.friday.date - } else if (week.days.thursday) { - week.endDate = week.days.thursday.date - } else if (week.days.wednesday) { - week.endDate = week.days.wednesday.date - } else if (week.days.tuesday) { - week.endDate = week.days.tuesday.date - } else if (week.days.monday) { - week.endDate = week.days.monday.date - } - + mutations.setStartEndDate(week) month.push(week) id++ week = { id: id, days: {} } @@ -88,11 +57,17 @@ const mutations = { } break case 3: - week.days.wednesday = { - id: currentDate.getDay(), - date: currentDate, - name: 'Mittwoch', - worker: [] + if (currentDate.getMonth() === mon + 1) { + end = true + mutations.setStartEndDate(week) + month.push(week) + } else { + week.days.wednesday = { + id: currentDate.getDay(), + date: currentDate, + name: 'Mittwoch', + worker: [] + } } break case 4: @@ -129,6 +104,9 @@ const mutations = { break } } + state.month = month + }, + setStartEndDate: week => { if (week.days.monday) { week.startDate = week.days.monday.date } else if (week.days.tuesday) { @@ -160,20 +138,24 @@ const mutations = { } else if (week.days.monday) { week.endDate = week.days.monday.date } - month.push(week) - state.month = month - console.log(state.month) }, - setWorker: (state, data) => { - console.log('hier ist die mutation', data) - for (let week in state.month) { - console.log('week', week) + updateMonth: (state, data) => { + const date = new Date(data.startdatetime) + const user = data.user + for (let week = 0; week < state.month.length; week++) { for (let day in state.month[week].days) { - console.log(state.month[week].days[day], data.day) - if (state.month[week].days[day].date - data.day.date === 0) { - state.month[week].days[day].worker.push(data.worker) - console.log('sm', state.month) - return + if (state.month[week].days[day].date - date === 0) { + 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 + }) + } } } } @@ -196,9 +178,52 @@ const actions = { if (e.response.data === 401) dispatch('logout', null, { root: true }) } }, - setWorker({ commit }, data) { - console.log('hier bin ich', data) - commit('setWorker', data) + // eslint-disable-next-line no-unused-vars + async addUser({ commit, rootState, dispatch }, data) { + try { + const response = await axios.post( + url.vorstand.sm.addUser, + { ...data }, + { + headers: { Token: rootState.login.user.accessToken } + } + ) + console.log(response.data) + commit('updateMonth', {...response.data[0], com: 'add'}) + } catch (e) { + if (e.response) + if (e.response.status === 401) dispatch('logout', null, { root: true }) + } + }, + async getUser({ commit, rootState, dispatch }, data) { + try { + const response = await axios.post( + url.vorstand.sm.getUser, + { ...data }, + { headers: { Token: rootState.login.user.accessToken } } + ) + for (let item = 0; item < response.data.length; item++) { + commit('updateMonth', { ...response.data[item], com: 'add' }) + } + } 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 { + // eslint-disable-next-line no-unused-vars + const response = await axios.post( + url.vorstand.sm.deleteUser, + { ...data }, + { headers: { Token: rootState.login.user.accessToken } } + ) + commit('updateMonth', {...data, com: 'delete'}) + } catch (e) { + if (e.response) + if (e.response.status === 401) dispatch('logout', null, { root: true }) + } } } const getters = {