mirror of https://github.com/doccano/doccano.git
pythondatasetsactive-learningtext-annotationdatasetnatural-language-processingdata-labelingmachine-learningannotation-tool
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.
102 lines
2.2 KiB
102 lines
2.2 KiB
import LabelService from '@/services/label.service'
|
|
|
|
export const state = () => ({
|
|
items: [],
|
|
selected: [],
|
|
loading: false
|
|
})
|
|
|
|
export const getters = {
|
|
isLabelSelected(state) {
|
|
return state.selected.length > 0
|
|
},
|
|
headers() {
|
|
return [
|
|
{
|
|
text: 'Name',
|
|
align: 'left',
|
|
value: 'text'
|
|
},
|
|
{
|
|
text: 'Shortkey',
|
|
value: 'suffix_key'
|
|
},
|
|
{
|
|
text: 'Color',
|
|
sortable: false,
|
|
value: 'background_color'
|
|
}
|
|
]
|
|
}
|
|
}
|
|
|
|
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 }, payload) {
|
|
commit('setLoading', true)
|
|
return LabelService.getLabelList(payload.projectId)
|
|
.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')
|
|
}
|
|
}
|