vorstand can create, edit and delete jobkinds

This commit is contained in:
Tim Gröger 2020-05-17 20:22:03 +02:00
parent e0eeb5c467
commit 4af0d77584
6 changed files with 258 additions and 2 deletions

View File

@ -0,0 +1,119 @@
<template>
<div>
<v-card tile :loading="jobkindsLoading">
<v-card-title>
Dienstarten
<v-spacer />
<v-btn fab small color="primary" @click="add()">
<v-icon>
{{ plusIcon }}
</v-icon>
</v-btn>
</v-card-title>
<v-card-text>
<v-card tile v-for="jobkind in jobkinds" :key="jobkind.id">
<v-card-text class="black--text">
<v-row class="ml-3 mr-3">
{{ jobkind.name }}
<v-spacer />
<v-btn icon @click="editJobKind(jobkind)">
<v-icon>
{{ editIcon }}
</v-icon>
</v-btn>
<v-btn icon @click="deleteJobKind(jobkind)">
<v-icon>
{{ deleteIcon }}
</v-icon>
</v-btn>
</v-row>
</v-card-text>
</v-card>
</v-card-text>
</v-card>
<v-dialog v-model="dialog">
<v-card>
<v-card-title>
{{ title }}
</v-card-title>
<v-card-text>
<v-text-field outlined label="Name" v-model="editedItem.name" />
</v-card-text>
<v-card-actions>
<v-spacer />
<v-btn text color="primary" @click="close()">Abbrechen</v-btn>
<v-btn text color="primary" @click="save()">Speichern</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</div>
</template>
<script>
import { mapGetters, mapActions } from 'vuex'
import { mdiPencil, mdiDelete, mdiPlus } from '@mdi/js'
export default {
name: 'JobKindManager',
data() {
return {
editIcon: mdiPencil,
deleteIcon: mdiDelete,
plusIcon: mdiPlus,
dialog: false,
editedItem: {
id: -1,
name: null
},
defaultItem: {
id: -1,
name: null
}
}
},
methods: {
...mapActions({
getAllJobKinds: 'jkm/getAllJobKinds',
addingJobKind: 'jkm/addJobKind',
updateJobKind: 'jkm/updateJobKind',
deletingJobKind: 'jkm/deleteJobKind'
}),
add() {
this.dialog = true
},
editJobKind(jobkind) {
this.dialog = true
this.editedItem = Object.assign({}, jobkind)
},
deleteJobKind(jobkind) {
confirm("Willst du diese Dienstart wirklich löschen") && this.deletingJobKind(jobkind)
this.close()
},
close() {
setTimeout(() => {
this.editedItem = Object.assign({}, this.defaultItem)
this.dialog = false
}, 200)
},
save() {
this.editedItem.id === -1 ? this.addingJobKind(this.editedItem) : this.updateJobKind(this.editedItem)
this.close()
}
},
computed: {
...mapGetters({
jobkinds: 'jkm/jobkinds',
jobkindsLoading: 'jkm/jobkindsLoading'
}),
title() {
return this.editedItem.id === -1
? 'Neue Dienstart erstellen'
: 'Dienstart bearbeiten'
}
},
created() {
this.getAllJobKinds()
}
}
</script>
<style scoped></style>

View File

@ -24,6 +24,14 @@
Arbeitsgruppen Arbeitsgruppen
</v-list-item-title> </v-list-item-title>
</v-list-item> </v-list-item>
<v-list-item link to="/main/management/jobkindmanagement">
<v-list-item-icon>
<v-icon>???</v-icon>
</v-list-item-icon>
<v-list-item-title>
Dienstarten
</v-list-item-title>
</v-list-item>
</v-list> </v-list>
</template> </template>

View File

@ -33,7 +33,11 @@ const url = {
getUser: main + 'sm/getUser', getUser: main + 'sm/getUser',
getUsers: main + 'sm/getUsers', getUsers: main + 'sm/getUsers',
lockDay: main + 'sm/lockDay', lockDay: main + 'sm/lockDay',
searchUser: main + 'sm/searchWithExtern' searchUser: main + 'sm/searchWithExtern',
jobkind: main + 'sm/JobKind',
getAllJobKindsbKinds: main + 'sm/getAllJobKinds',
getJobKind: main + 'sm/getJobKind',
deleteJobKind: main + 'sm/deleteJobKind'
}, },
um: { um: {
setStatus: main + 'um/setStatus', setStatus: main + 'um/setStatus',

View File

@ -24,6 +24,7 @@ import GastroNavigation from '@/components/gastro/GastroNavigation'
import PriceListView from '@/views/contents/PriceListView' import PriceListView from '@/views/contents/PriceListView'
import UserManager from '@/components/vorstand/UserManager' import UserManager from '@/components/vorstand/UserManager'
import WorkgroupManagement from "@/components/vorstand/WorkgroupManagement"; import WorkgroupManagement from "@/components/vorstand/WorkgroupManagement";
import JobKindManager from "@/components/vorstand/JobKindManager";
Vue.use(VueRouter) Vue.use(VueRouter)
@ -63,6 +64,10 @@ const routes = [
{ {
path: 'workgroupmanagement', path: 'workgroupmanagement',
component: WorkgroupManagement component: WorkgroupManagement
},
{
path: 'jobkindmanagement',
component: JobKindManager
} }
] ]
}, },

View File

@ -10,6 +10,7 @@ import requestJobs from '@/store/modules/jobRequests'
import priceList from '@/store/modules/pricelist' import priceList from '@/store/modules/pricelist'
import usermanager from '@/store/modules/userManager' import usermanager from '@/store/modules/userManager'
import wm from '@/store/modules/workgroupManagement' import wm from '@/store/modules/workgroupManagement'
import jkm from '@/store/modules/jobkindManager'
Vue.use(Vuex) Vue.use(Vuex)
@ -24,6 +25,7 @@ export default new Vuex.Store({
requestJobs, requestJobs,
priceList, priceList,
usermanager, usermanager,
wm wm,
jkm
} }
}) })

View File

@ -0,0 +1,118 @@
import url from '@/plugins/routes'
import axios from 'axios'
const state = {
jobkinds: [],
jobkindLoading: false
}
const mutations = {
setJobkinds: (state, jobkinds) => {
state.jobkinds = jobkinds
},
updateJobKind: (state, jobkind) => {
console.log(jobkind)
const exists = state.jobkinds.find(a => {
return a.id === jobkind.id
})
console.log(exists)
if (exists) {
exists.name = jobkind.name
} else {
state.jobkinds.push(jobkind)
}
},
deleteJobKind: (state, jobkind) => {
const exists = state.jobkinds.indexOf(
state.jobkinds.find(a => {
return a.id === jobkind.id
})
)
state.jobkinds.splice(exists, 1)
},
setJobkindsLoading: (state, value) => {
state.jobkindLoading = value
}
}
const actions = {
async getAllJobKinds({ commit, rootState, dispatch }) {
try {
commit('setJobkindsLoading', true)
const response = await axios.get(url.vorstand.sm.getAllJobKindsbKinds, {
headers: { Token: rootState.login.user.accessToken }
})
commit('setJobkinds', response.data)
commit('setJobkindsLoading', false)
dispatch('getLifeTime', null, { root: true })
} catch (e) {
if (e.response)
if (e.response.status === 401) dispatch('logout', null, { root: true })
}
},
async addJobKind({ commit, rootState, dispatch }, data) {
try {
commit('setJobkindsLoading', true)
const response = await axios.put(
url.vorstand.sm.jobkind,
{ ...data },
{ headers: { Token: rootState.login.user.accessToken } }
)
commit('updateJobKind', response.data)
commit('setJobkindsLoading', false)
dispatch('getLifeTime', null, { root: true })
} catch (e) {
if (e.response)
if (e.response.status === 401) dispatch('logout', null, { root: true })
}
},
async updateJobKind({ commit, rootState, dispatch }, data) {
try {
commit('setJobkindsLoading', true)
const response = await axios.post(
url.vorstand.sm.jobkind,
{ ...data },
{ headers: { Token: rootState.login.user.accessToken } }
)
commit('updateJobKind', response.data)
commit('setJobkindsLoading', false)
dispatch('getLifeTime', null, { root: true })
} catch (e) {
if (e.response)
if (e.response.status === 401) dispatch('logout', null, { root: true })
}
},
async deleteJobKind({ commit, rootState, dispatch }, data) {
try {
commit('setJobkindsLoading', true)
await axios.post(
url.vorstand.sm.deleteJobKind,
{ ...data },
{ headers: { Token: rootState.login.user.accessToken } }
)
commit('deleteJobKind', data)
commit('setJobkindsLoading', false)
dispatch('getLifeTime', null, { root: true })
} catch (e) {
if (e.response)
if (e.response.status === 401) dispatch('logout', null, { root: true })
}
}
}
const getters = {
jobkinds: state => {
return state.jobkinds
},
jobkindsLoading: state => {
return state.jobkindLoading
}
}
export default {
namespaced: true,
state,
mutations,
actions,
getters
}