From d6261d8a0dc6cebe568427562a58a98fa6e14df7 Mon Sep 17 00:00:00 2001 From: Dominik Date: Sat, 23 Jan 2021 16:06:44 +0100 Subject: [PATCH] Added Eventtype functionality --- .../components/management/Eventtypes.vue | 117 +++++++++++++++--- .../components/management/JobTypes.vue | 2 +- src/plugins/schedule/store/schedule.ts | 76 +++++++++++- 3 files changed, 168 insertions(+), 27 deletions(-) diff --git a/src/plugins/schedule/components/management/Eventtypes.vue b/src/plugins/schedule/components/management/Eventtypes.vue index b92f7ec..50ad988 100644 --- a/src/plugins/schedule/components/management/Eventtypes.vue +++ b/src/plugins/schedule/components/management/Eventtypes.vue @@ -1,18 +1,42 @@ diff --git a/src/plugins/schedule/components/management/JobTypes.vue b/src/plugins/schedule/components/management/JobTypes.vue index 8f952d0..2362235 100644 --- a/src/plugins/schedule/components/management/JobTypes.vue +++ b/src/plugins/schedule/components/management/JobTypes.vue @@ -9,7 +9,7 @@ - + diff --git a/src/plugins/schedule/store/schedule.ts b/src/plugins/schedule/store/schedule.ts index 5df9273..b0a1309 100644 --- a/src/plugins/schedule/store/schedule.ts +++ b/src/plugins/schedule/store/schedule.ts @@ -8,16 +8,19 @@ export interface JobType { name: string; } -export interface ScheduleInterface { - jobTypes: JobType[]; +export interface EventType { + id: number; + name: string; } -// export interface StateInterfaceSchedule extends StateInterface { -// // balance: BalanceInterface; -// } +export interface ScheduleInterface { + jobTypes: JobType[]; + eventTypes: EventType[]; +} const state: ScheduleInterface = { - jobTypes: [] + jobTypes: [], + eventTypes: [] }; const mutations: MutationTree = { @@ -36,6 +39,22 @@ const mutations: MutationTree = { if (_jobtype) { _jobtype.name = jobType.name; } + }, + setEventTypes(state, eventTypes: EventType[]) { + state.eventTypes = eventTypes; + }, + addEventType(state, eventType: EventType) { + state.eventTypes.unshift(eventType); + }, + removeEventType(state, name: string) { + const index = state.eventTypes.findIndex(item => item.name == name); + state.eventTypes.splice(index, 1); + }, + setEventType(state, eventType: EventType) { + const _eventtype = state.eventTypes.find(item => item.id == eventType.id); + if (_eventtype) { + _eventtype.name = eventType.name; + } } }; @@ -62,6 +81,7 @@ const actions: ActionTree = { console.warn(err); }); }, + removeJobType({ commit }, data: number) { axios .delete(`/schedule/job-types/${data}`) @@ -82,6 +102,50 @@ const actions: ActionTree = { .catch(err => { console.warn(err); }); + }, + + getEventTypes({ commit }) { + axios + .get('/schedule/event-types') + .then((response: AxiosResponse) => { + console.log('action:', response.data); + commit('setEventTypes', response.data); + }) + .catch(err => { + console.warn(err); + }); + }, + + addEventType({ commit }, data) { + console.log(data); + axios + .post('/schedule/event-types', data) + .then((response: AxiosResponse) => { + commit('addEventType', response.data); + }) + .catch(err => { + console.warn(err); + }); + }, + removeEventType({ commit }, data: string) { + axios + .delete(`/schedule/event-types/${data}`) + .then(() => { + commit('removeEventType', data); + }) + .catch(err => { + console.warn(err); + }); + }, + changeEventTypeName({ commit }, eventtype: { id: number; name: string; oldname: string }) { + axios + .put(`/schedule/event-types/${eventtype.oldname}`, eventtype) + .then(() => { + commit('setEventType', eventtype); + }) + .catch(err => { + console.warn(err); + }); } };