You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

84 lines
1.9 KiB

import LabelService from '@/services/label.service'
export const state = () => ({
items: [],
selected: [],
loading: false
})
export const getters = {
isLabelSelected(state) {
return state.selected.length > 0
}
}
export const mutations = {
setLabelList(state, payload) {
state.items = payload
},
addLabel(state, label) {
state.items.unshift(label)
},
deleteLabel(state, labelId) {
state.items = state.items.filter(item => item.id !== labelId)
},
updateSelected(state, selected) {
state.selected = selected
},
updateLabel(state, label) {
const item = state.items.find(item => item.id === label.id)
Object.assign(item, label)
},
resetSelected(state) {
state.selected = []
},
setLoading(state, payload) {
state.loading = payload
}
}
export const actions = {
getLabelList({ commit }, config) {
commit('setLoading', true)
return LabelService.getLabelList()
.then((response) => {
commit('setLabelList', response)
})
.catch((error) => {
alert(error)
})
.finally(() => {
commit('setLoading', false)
})
},
createLabel({ commit }, data) {
LabelService.addLabel(data.projectId, data)
.then((response) => {
commit('addLabel', response)
})
.catch((error) => {
alert(error)
})
},
updateLabel({ commit }, data) {
LabelService.updateLabel(data.projectId, data.id, data)
.then((response) => {
commit('updateLabel', response)
})
.catch((error) => {
alert(error)
})
},
deleteLabel({ commit, state }, projectId) {
for (const label of state.selected) {
LabelService.deleteLabel(projectId, label.id)
.then((response) => {
commit('deleteLabel', label.id)
})
.catch((error) => {
alert(error)
})
}
commit('resetSelected')
}
}