Browse Source

Add label service and store

pull/341/head
Hironsan 5 years ago
parent
commit
41029e7392
2 changed files with 108 additions and 0 deletions
  1. 32
      frontend/services/label.service.js
  2. 76
      frontend/store/labels.js

32
frontend/services/label.service.js

@ -0,0 +1,32 @@
import ApiService from '@/services/api.service'
class MemberService {
constructor() {
this.request = new ApiService()
}
getMemberList(projectId) {
return this.request.get(`/projects/${projectId}/users`)
}
addMember(projectId, userId, role) {
const data = {
id: userId,
role
}
return this.request.post(`/projects/${projectId}/users`, data)
}
deleteMember(projectId, userId) {
return this.request.delete(`/projects/${projectId}/users/${userId}`)
}
updateMemberRole(projectId, userId, role) {
const data = {
role
}
return this.request.patch(`/projects/${projectId}/users/${userId}`, data)
}
}
export default new MemberService()

76
frontend/store/labels.js

@ -0,0 +1,76 @@
import LabelService from '@/services/label.service'
export const state = () => ({
items: [],
selected: []
})
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 = []
}
}
export const actions = {
getLabelList(context, config) {
return LabelService.getLabelList()
.then((response) => {
context.commit('setLabelList', response)
})
.catch((error) => {
alert(error)
})
},
addMember({ commit }, data) {
LabelService.addLabel(data.projectId, data.labelId, data)
.then((response) => {
commit('addLabel', response)
})
.catch((error) => {
alert(error)
})
},
updateLabel({ commit }, data) {
LabelService.updateLabel(data.projectId, data.labelId, data)
.then((response) => {
commit('updateLabel', response)
})
.catch((error) => {
alert(error)
})
},
removeLabel({ 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')
}
}
Loading…
Cancel
Save