mirror of https://github.com/doccano/doccano.git
7 changed files with 0 additions and 764 deletions
Split View
Diff Options
-
115frontend/store/comments.js
-
252frontend/store/documents.js
-
136frontend/store/labels.js
-
84frontend/store/members.js
-
70frontend/store/pagination.js
-
37frontend/store/roles.js
-
70frontend/store/statistics.js
@ -1,115 +0,0 @@ |
|||
import CommentService from '@/services/comment.service' |
|||
import UserService from '@/services/user.service' |
|||
|
|||
export const state = () => ({ |
|||
comments: [], |
|||
selectedComments: [], |
|||
totalComments: 0, |
|||
userId: -1, |
|||
loading: false |
|||
}) |
|||
|
|||
export const getters = { |
|||
isCommentSelected(state) { |
|||
return state.selectedComments.length > 0 |
|||
} |
|||
} |
|||
export const mutations = { |
|||
setCommentList(state, payload) { |
|||
state.comments = payload |
|||
}, |
|||
addComment(state, payload) { |
|||
state.comments.unshift(payload) |
|||
}, |
|||
updateComment(state, payload) { |
|||
const item = state.comments.find(item => item.id === payload.id) |
|||
Object.assign(item, payload) |
|||
}, |
|||
deleteComment(state, commentId) { |
|||
state.comments = state.comments.filter(item => item.id !== commentId) |
|||
}, |
|||
updateSelectedComments(state, selected) { |
|||
state.selectedComments = selected |
|||
}, |
|||
resetSelectedComments(state) { |
|||
state.selectedComments = [] |
|||
}, |
|||
setTotalComments(state, payload) { |
|||
state.totalComments = payload |
|||
}, |
|||
setUserId(state, payload) { |
|||
state.userId = payload.id |
|||
}, |
|||
setLoading(state, payload) { |
|||
state.loading = payload |
|||
} |
|||
} |
|||
|
|||
export const actions = { |
|||
getCommentList({ commit, state }, payload) { |
|||
commit('setLoading', true) |
|||
return CommentService.getCommentList(payload.projectId, payload.docId) |
|||
.then((response) => { |
|||
commit('setCommentList', response.data) |
|||
}) |
|||
.catch((error) => { |
|||
alert(error) |
|||
}) |
|||
.finally(() => { |
|||
commit('setLoading', false) |
|||
}) |
|||
}, |
|||
getProjectCommentList({ commit, state }, payload) { |
|||
commit('setLoading', true) |
|||
return CommentService.getProjectCommentList(payload.projectId) |
|||
.then((response) => { |
|||
commit('setCommentList', response.data) |
|||
commit('setTotalComments', response.data.count) |
|||
}) |
|||
.catch((error) => { |
|||
alert(error) |
|||
}) |
|||
.finally(() => { |
|||
commit('setLoading', false) |
|||
}) |
|||
}, |
|||
addComment({ commit, state }, payload) { |
|||
CommentService.addComment(payload.projectId, payload.docId, payload) |
|||
.then((response) => { |
|||
commit('addComment', response.data) |
|||
}) |
|||
.catch((error) => { |
|||
alert(error) |
|||
}) |
|||
}, |
|||
updateComment({ commit, state }, payload) { |
|||
CommentService.updateComment(payload.projectId, payload.docId, payload.commentId, payload) |
|||
.then((response) => { |
|||
commit('updateComment', response.data) |
|||
}) |
|||
.catch((error) => { |
|||
alert(error) |
|||
}) |
|||
}, |
|||
deleteComment({ commit, state }, payload) { |
|||
for (const comment of state.selectedComments) { |
|||
CommentService.deleteComment(payload.projectId, comment.document, comment.id) |
|||
.then((response) => { |
|||
commit('deleteComment', comment.id) |
|||
}) |
|||
.catch((error) => { |
|||
alert(error) |
|||
}) |
|||
commit('resetSelectedComments') |
|||
} |
|||
}, |
|||
getMyUserId({ commit, state }) { |
|||
UserService.getMe() |
|||
.then((response) => { |
|||
commit('setUserId', response.data) |
|||
}) |
|||
.catch((error) => { |
|||
alert(error) |
|||
}) |
|||
} |
|||
} |
@ -1,252 +0,0 @@ |
|||
import DocumentService from '@/services/document.service' |
|||
import AnnotationService from '@/services/annotation.service' |
|||
|
|||
export const state = () => ({ |
|||
items: [], |
|||
selected: [], |
|||
loading: false, |
|||
current: 0, |
|||
total: 0, |
|||
searchOptions: { |
|||
limit: 10, |
|||
offset: 0, |
|||
q: '', |
|||
isChecked: '', |
|||
filterName: '' |
|||
} |
|||
}) |
|||
|
|||
export const getters = { |
|||
isDocumentSelected(state) { |
|||
return state.selected.length > 0 |
|||
}, |
|||
approved(state) { |
|||
if (state.items[state.current]) { |
|||
return state.items[state.current].annotation_approver !== null |
|||
} else { |
|||
return false |
|||
} |
|||
}, |
|||
currentDoc(state) { |
|||
return state.items[state.current] |
|||
} |
|||
} |
|||
export const mutations = { |
|||
setCurrent(state, payload) { |
|||
state.current = payload |
|||
}, |
|||
setDocumentList(state, payload) { |
|||
state.items = payload |
|||
}, |
|||
addDocument(state, document) { |
|||
state.items.unshift(document) |
|||
}, |
|||
deleteDocument(state, documentId) { |
|||
state.items = state.items.filter(item => item.id !== documentId) |
|||
}, |
|||
updateSelected(state, selected) { |
|||
state.selected = selected |
|||
}, |
|||
updateDocument(state, document) { |
|||
const item = state.items.find(item => item.id === document.id) |
|||
Object.assign(item, document) |
|||
}, |
|||
resetSelected(state) { |
|||
state.selected = [] |
|||
}, |
|||
setLoading(state, payload) { |
|||
state.loading = payload |
|||
}, |
|||
setTotalItems(state, payload) { |
|||
state.total = payload |
|||
}, |
|||
addAnnotation(state, payload) { |
|||
state.items[state.current].annotations.push(payload) |
|||
}, |
|||
setAnnotations(state, payload) { |
|||
state.items[state.current].annotations = payload |
|||
}, |
|||
deleteAnnotation(state, annotationId) { |
|||
state.items[state.current].annotations = state.items[state.current].annotations.filter(item => item.id !== annotationId) |
|||
}, |
|||
clearAnnotations(state) { |
|||
state.items[state.current].annotations = [] |
|||
}, |
|||
updateAnnotation(state, payload) { |
|||
const item = state.items[state.current].annotations.find(item => item.id === payload.id) |
|||
Object.assign(item, payload) |
|||
}, |
|||
updateSearchOptions(state, payload) { |
|||
state.searchOptions = Object.assign(state.searchOptions, payload) |
|||
}, |
|||
initSearchOptions(state) { |
|||
state.searchOptions = { |
|||
limit: 10, |
|||
offset: 0, |
|||
q: '', |
|||
isChecked: '', |
|||
filterName: '' |
|||
} |
|||
}, |
|||
setUserId(state, payload) { |
|||
state.userId = payload.id |
|||
} |
|||
} |
|||
|
|||
export const actions = { |
|||
getDocumentList({ commit, state }, payload) { |
|||
commit('setLoading', true) |
|||
return DocumentService.getDocumentList(payload) |
|||
.then((response) => { |
|||
commit('setDocumentList', response.data.results) |
|||
commit('setTotalItems', response.data.count) |
|||
}) |
|||
.catch((error) => { |
|||
alert(error) |
|||
}) |
|||
.finally(() => { |
|||
commit('setLoading', false) |
|||
}) |
|||
}, |
|||
uploadDocument({ commit, dispatch }, data) { |
|||
commit('setLoading', true) |
|||
const formData = new FormData() |
|||
formData.append('file', data.file) |
|||
formData.append('format', data.format) |
|||
const config = { |
|||
headers: { |
|||
'Content-Type': 'multipart/form-data' |
|||
} |
|||
} |
|||
return DocumentService.uploadFile(data.projectId, formData, config) |
|||
.then((response) => { |
|||
dispatch('getDocumentList', data) |
|||
}) |
|||
.finally(() => { |
|||
commit('setLoading', false) |
|||
}) |
|||
}, |
|||
exportDocument({ commit }, data) { |
|||
commit('setLoading', true) |
|||
DocumentService.exportFile(data.projectId, data.format, data.onlyApproved) |
|||
.then((response) => { |
|||
const url = window.URL.createObjectURL(new Blob([response.data])) |
|||
const link = document.createElement('a') |
|||
link.href = url |
|||
link.setAttribute('download', data.fileName + '.' + data.suffix) |
|||
document.body.appendChild(link) |
|||
link.click() |
|||
}) |
|||
.catch((error) => { |
|||
alert(error) |
|||
}) |
|||
.finally(() => { |
|||
commit('setLoading', false) |
|||
}) |
|||
}, |
|||
updateDocument({ commit }, data) { |
|||
DocumentService.updateDocument(data.projectId, data.id, data) |
|||
.then((response) => { |
|||
commit('updateDocument', response.data) |
|||
}) |
|||
.catch((error) => { |
|||
alert(error) |
|||
}) |
|||
}, |
|||
deleteAllDocuments({ commit, state }, projectId) { |
|||
DocumentService.deleteAllDocuments(projectId) |
|||
.then((response) => { |
|||
commit('setDocumentList', []) |
|||
commit('setTotalItems', 0) |
|||
commit('resetSelected') |
|||
}) |
|||
.catch((error) => { |
|||
alert(error) |
|||
}) |
|||
}, |
|||
deleteDocument({ commit, state }, projectId) { |
|||
for (const document of state.selected) { |
|||
DocumentService.deleteDocument(projectId, document.id) |
|||
.then((response) => { |
|||
commit('deleteDocument', document.id) |
|||
}) |
|||
.catch((error) => { |
|||
alert(error) |
|||
}) |
|||
} |
|||
commit('resetSelected') |
|||
}, |
|||
addAnnotation({ commit, state }, payload) { |
|||
const documentId = state.items[state.current].id |
|||
AnnotationService.addAnnotation(payload.projectId, documentId, payload) |
|||
.then((response) => { |
|||
commit('addAnnotation', response.data) |
|||
}) |
|||
.catch((error) => { |
|||
alert(error) |
|||
}) |
|||
}, |
|||
updateAnnotation({ commit, state }, payload) { |
|||
const documentId = state.items[state.current].id |
|||
AnnotationService.updateAnnotation(payload.projectId, documentId, payload.annotationId, payload) |
|||
.then((response) => { |
|||
commit('updateAnnotation', response.data) |
|||
}) |
|||
.catch((error) => { |
|||
alert(error) |
|||
}) |
|||
}, |
|||
deleteAnnotation({ commit, state }, payload) { |
|||
const documentId = state.items[state.current].id |
|||
AnnotationService.deleteAnnotation(payload.projectId, documentId, payload.annotationId) |
|||
.then((response) => { |
|||
commit('deleteAnnotation', payload.annotationId) |
|||
}) |
|||
.catch((error) => { |
|||
alert(error) |
|||
}) |
|||
}, |
|||
clearAnnotations({ commit, state }, projectId) { |
|||
const documentId = state.items[state.current].id |
|||
AnnotationService.clearAnnotations(projectId, documentId) |
|||
.then((response) => { |
|||
commit('clearAnnotations') |
|||
}) |
|||
.catch((error) => { |
|||
alert(error) |
|||
}) |
|||
}, |
|||
approve({ commit, getters }, payload) { |
|||
const documentId = getters.currentDoc.id |
|||
const data = { |
|||
approved: !getters.currentDoc.annotation_approver |
|||
} |
|||
DocumentService.approveDocument(payload.projectId, documentId, data) |
|||
.then((response) => { |
|||
commit('updateDocument', response.data) |
|||
}) |
|||
.catch((error) => { |
|||
alert(error) |
|||
}) |
|||
}, |
|||
async autoLabeling({ commit, state }, payload) { |
|||
const document = state.items[state.current] |
|||
if (document) { |
|||
const response = await AnnotationService.autoLabel(payload.projectId, document.id) |
|||
commit('setAnnotations', response.data) |
|||
// commit('setLoading', true)
|
|||
// return AnnotationService.autoLabel(payload.projectId, document.id)
|
|||
// .then((response) => {
|
|||
// commit('setAnnotations', response.data)
|
|||
// })
|
|||
// .catch((error) => {
|
|||
// const message = error.response.data['detail']
|
|||
// Promise.reject(error)
|
|||
// // throw new Error(message)
|
|||
// })
|
|||
// .finally(() => {
|
|||
// commit('setLoading', false)
|
|||
// })
|
|||
} |
|||
}, |
|||
} |
@ -1,136 +0,0 @@ |
|||
import LabelService from '@/services/label.service' |
|||
|
|||
export const state = () => ({ |
|||
items: [], |
|||
selected: [], |
|||
loading: false |
|||
}) |
|||
|
|||
export const getters = { |
|||
isLabelSelected(state) { |
|||
return state.selected.length > 0 |
|||
}, |
|||
shortkeys() { |
|||
return '0123456789abcdefghijklmnopqrstuvwxyz'.split('') |
|||
} |
|||
} |
|||
|
|||
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.data) |
|||
}) |
|||
.catch((error) => { |
|||
alert(error) |
|||
}) |
|||
.finally(() => { |
|||
commit('setLoading', false) |
|||
}) |
|||
}, |
|||
createLabel({ commit }, data) { |
|||
return LabelService.addLabel(data.projectId, data) |
|||
.then((response) => { |
|||
commit('addLabel', response.data) |
|||
}) |
|||
}, |
|||
updateLabel({ commit }, data) { |
|||
LabelService.updateLabel(data.projectId, data.id, data) |
|||
.then((response) => { |
|||
commit('updateLabel', response.data) |
|||
}) |
|||
.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') |
|||
}, |
|||
importLabels({ commit }, payload) { |
|||
commit('setLoading', true) |
|||
const formData = new FormData() |
|||
formData.append('file', payload.file) |
|||
const reader = new FileReader() |
|||
reader.onload = (e) => { |
|||
const labels = JSON.parse(e.target.result) |
|||
for (const label of labels) { |
|||
LabelService.addLabel(payload.projectId, label) |
|||
.then((response) => { |
|||
commit('addLabel', response.data) |
|||
}) |
|||
} |
|||
} |
|||
reader.readAsText(payload.file) |
|||
commit('setLoading', false) |
|||
}, |
|||
exportLabels({ commit }, payload) { |
|||
commit('setLoading', true) |
|||
LabelService.getLabelList(payload.projectId) |
|||
.then((response) => { |
|||
const url = window.URL.createObjectURL(new Blob([JSON.stringify(response.data)])) |
|||
const link = document.createElement('a') |
|||
link.href = url |
|||
link.setAttribute('download', `project_${payload.projectId}_labels.json`) |
|||
document.body.appendChild(link) |
|||
link.click() |
|||
}) |
|||
.catch((error) => { |
|||
alert(error) |
|||
}) |
|||
.finally(() => { |
|||
commit('setLoading', false) |
|||
}) |
|||
}, |
|||
uploadLabel({ commit, dispatch }, data) { |
|||
commit('setLoading', true) |
|||
const formData = new FormData() |
|||
formData.append('file', data.file) |
|||
const config = { |
|||
headers: { |
|||
'Content-Type': 'multipart/form-data' |
|||
} |
|||
} |
|||
return LabelService.uploadFile(data.projectId, formData, config) |
|||
.then((response) => { |
|||
dispatch('getLabelList', data) |
|||
}) |
|||
.finally(() => { |
|||
commit('setLoading', false) |
|||
}) |
|||
} |
|||
} |
@ -1,84 +0,0 @@ |
|||
import MemberService from '@/services/member.service' |
|||
|
|||
export const state = () => ({ |
|||
items: [], |
|||
selected: [], |
|||
loading: false |
|||
}) |
|||
|
|||
export const getters = { |
|||
isMemberSelected(state) { |
|||
return state.selected.length > 0 |
|||
} |
|||
} |
|||
|
|||
export const mutations = { |
|||
setMemberList(state, payload) { |
|||
state.items = payload |
|||
}, |
|||
addMember(state, member) { |
|||
state.items.unshift(member) |
|||
}, |
|||
deleteMember(state, userId) { |
|||
state.items = state.items.filter(item => item.id !== userId) |
|||
}, |
|||
updateSelected(state, selected) { |
|||
state.selected = selected |
|||
}, |
|||
updateMember(state, member) { |
|||
const item = state.items.find(item => item.id === member.id) |
|||
Object.assign(item, member) |
|||
}, |
|||
resetSelected(state) { |
|||
state.selected = [] |
|||
}, |
|||
setLoading(state, payload) { |
|||
state.loading = payload |
|||
} |
|||
} |
|||
|
|||
export const actions = { |
|||
getMemberList({ commit }, payload) { |
|||
commit('setLoading', true) |
|||
return MemberService.getMemberList(payload.projectId) |
|||
.then((response) => { |
|||
commit('setMemberList', response.data) |
|||
}) |
|||
.catch((error) => { |
|||
alert(error) |
|||
}) |
|||
.finally(() => { |
|||
commit('setLoading', false) |
|||
}) |
|||
}, |
|||
addMember({ commit }, data) { |
|||
MemberService.addMember(data.projectId, data.userId, data.role) |
|||
.then((response) => { |
|||
commit('addMember', response.data) |
|||
}) |
|||
.catch((error) => { |
|||
alert(error) |
|||
}) |
|||
}, |
|||
updateMemberRole({ commit }, member) { |
|||
MemberService.updateMemberRole(member.projectId, member.id, member.role) |
|||
.then((response) => { |
|||
commit('updateMember', response.data) |
|||
}) |
|||
.catch((error) => { |
|||
alert(error) |
|||
}) |
|||
}, |
|||
removeMember({ commit, state }, projectId) { |
|||
for (const member of state.selected) { |
|||
MemberService.deleteMember(projectId, member.id) |
|||
.then((response) => { |
|||
commit('deleteMember', member.id) |
|||
}) |
|||
.catch((error) => { |
|||
alert(error) |
|||
}) |
|||
} |
|||
commit('resetSelected') |
|||
} |
|||
} |
@ -1,70 +0,0 @@ |
|||
export const state = () => ({ |
|||
limit: 10, |
|||
page: 1, |
|||
options: {}, |
|||
projectId: null |
|||
}) |
|||
|
|||
export const getters = { |
|||
offset(state) { |
|||
return Math.floor((state.page - 1) / state.limit) * state.limit |
|||
}, |
|||
current(state) { |
|||
return (state.page - 1) % state.limit |
|||
}, |
|||
page(state) { |
|||
return state.page |
|||
}, |
|||
limit(state) { |
|||
return state.limit |
|||
} |
|||
} |
|||
|
|||
export const mutations = { |
|||
updatePage(state, page) { |
|||
state.page = page |
|||
}, |
|||
savePage(state) { |
|||
const checkpoint = {} |
|||
checkpoint[state.projectId] = state.page |
|||
localStorage.setItem('checkpoint', JSON.stringify(checkpoint)) |
|||
}, |
|||
loadPage(state) { |
|||
const checkpoint = JSON.parse(localStorage.getItem('checkpoint')) || {} |
|||
state.page = checkpoint[state.projectId] ? checkpoint[state.projectId] : 1 |
|||
}, |
|||
setProjectId(state, projectId) { |
|||
state.projectId = projectId |
|||
}, |
|||
setOptions(state, limit, offset, q) { |
|||
state.options = { |
|||
limit, |
|||
offset, |
|||
q |
|||
} |
|||
} |
|||
} |
|||
|
|||
export const actions = { |
|||
prevPage({ commit, state }) { |
|||
const page = Math.max(state.page - 1, 1) |
|||
commit('updatePage', page) |
|||
commit('savePage') |
|||
}, |
|||
nextPage({ commit, state }, total) { |
|||
const page = Math.min(state.page + 1, total) |
|||
commit('updatePage', page) |
|||
commit('savePage') |
|||
}, |
|||
movePage({ commit }, newPage) { |
|||
commit('updatePage', newPage) |
|||
commit('savePage') |
|||
}, |
|||
initPage({ commit }, payload) { |
|||
commit('setProjectId', payload.projectId) |
|||
commit('loadPage') |
|||
}, |
|||
setOptions({ commit }, payload) { |
|||
commit('setOptions', payload.limit, payload.offset, payload.q) |
|||
} |
|||
} |
@ -1,37 +0,0 @@ |
|||
import RoleService from '@/services/role.service' |
|||
|
|||
export const state = () => ({ |
|||
items: [], |
|||
loading: false |
|||
}) |
|||
|
|||
export const getters = { |
|||
roles(state) { |
|||
return state.items |
|||
} |
|||
} |
|||
|
|||
export const mutations = { |
|||
setRoleList(state, payload) { |
|||
state.items = payload |
|||
}, |
|||
setLoading(state, payload) { |
|||
state.loading = payload |
|||
} |
|||
} |
|||
|
|||
export const actions = { |
|||
getRoleList({ commit }) { |
|||
commit('setLoading', true) |
|||
return RoleService.getRoleList() |
|||
.then((response) => { |
|||
commit('setRoleList', response.data) |
|||
}) |
|||
.catch((error) => { |
|||
alert(error) |
|||
}) |
|||
.finally(() => { |
|||
commit('setLoading', false) |
|||
}) |
|||
} |
|||
} |
@ -1,70 +0,0 @@ |
|||
import StatisticsService from '@/services/statistics.service' |
|||
|
|||
function makeData(object, label) { |
|||
const labels = object ? Object.keys(object) : [] |
|||
const counts = object ? Object.values(object) : [] |
|||
return { |
|||
labels, |
|||
datasets: [{ |
|||
label, |
|||
backgroundColor: '#00d1b2', |
|||
data: counts |
|||
}] |
|||
} |
|||
} |
|||
|
|||
export const state = () => ({ |
|||
loading: false, |
|||
stats: {} |
|||
}) |
|||
|
|||
export const mutations = { |
|||
setLoading(state, payload) { |
|||
state.loading = payload |
|||
}, |
|||
setStatistics(state, payload) { |
|||
state.stats = payload |
|||
} |
|||
} |
|||
|
|||
export const getters = { |
|||
progress(state) { |
|||
return (labels) => { |
|||
const complete = state.stats.total - state.stats.remaining |
|||
const incomplete = state.stats.remaining |
|||
return { |
|||
datasets: [{ |
|||
data: [complete, incomplete], |
|||
backgroundColor: ['#00d1b2', '#ffdd57'] |
|||
}], |
|||
labels |
|||
} |
|||
} |
|||
}, |
|||
labelStats(state) { |
|||
return (label) => { |
|||
return makeData(state.stats.label, label) |
|||
} |
|||
}, |
|||
userStats(state) { |
|||
return (label) => { |
|||
return makeData(state.stats.user, label) |
|||
} |
|||
} |
|||
} |
|||
|
|||
export const actions = { |
|||
fetchStatistics({ commit }, payload) { |
|||
commit('setLoading', true) |
|||
StatisticsService.getStatistics(payload) |
|||
.then((response) => { |
|||
commit('setStatistics', response.data) |
|||
}) |
|||
.catch((error) => { |
|||
alert(error) |
|||
}) |
|||
.finally(() => { |
|||
commit('setLoading', false) |
|||
}) |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save