mirror of https://github.com/doccano/doccano.git
6 changed files with 254 additions and 57 deletions
Unified View
Diff Options
-
11frontend/api/routes/docs.js
-
52frontend/components/containers/DocumentList.vue
-
71frontend/components/organisms/DocumentList.vue
-
76frontend/pages/projects/_id/dataset/index.vue
-
25frontend/services/document.service.js
-
76frontend/store/documents.js
@ -0,0 +1,52 @@ |
|||||
|
<template> |
||||
|
<document-list |
||||
|
:headers="headers" |
||||
|
:docs="items" |
||||
|
:selected="selected" |
||||
|
@update-selected="updateSelected" |
||||
|
@update-doc="handleUpdateDoc" |
||||
|
/> |
||||
|
</template> |
||||
|
|
||||
|
<script> |
||||
|
import { mapState, mapActions, mapMutations } from 'vuex' |
||||
|
import DocumentList from '@/components/organisms/DocumentList' |
||||
|
|
||||
|
export default { |
||||
|
components: { |
||||
|
DocumentList |
||||
|
}, |
||||
|
data() { |
||||
|
return { |
||||
|
headers: [ |
||||
|
{ |
||||
|
text: 'Text', |
||||
|
align: 'left', |
||||
|
value: 'text' |
||||
|
} |
||||
|
] |
||||
|
} |
||||
|
}, |
||||
|
|
||||
|
computed: { |
||||
|
...mapState('documents', ['items', 'selected']) |
||||
|
}, |
||||
|
|
||||
|
created() { |
||||
|
this.getDocumentList() |
||||
|
}, |
||||
|
|
||||
|
methods: { |
||||
|
...mapActions('documents', ['getDocumentList', 'updateDocument']), |
||||
|
...mapMutations('documents', ['updateSelected']), |
||||
|
|
||||
|
handleUpdateDoc(payload) { |
||||
|
const data = { |
||||
|
projectId: this.$route.params.id, |
||||
|
...payload |
||||
|
} |
||||
|
this.updateDocument(data) |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
</script> |
@ -0,0 +1,71 @@ |
|||||
|
<template> |
||||
|
<v-data-table |
||||
|
v-model="selected" |
||||
|
:headers="headers" |
||||
|
:items="docs" |
||||
|
item-key="id" |
||||
|
:search="search" |
||||
|
show-select |
||||
|
@input="update" |
||||
|
> |
||||
|
<template v-slot:top> |
||||
|
<v-text-field |
||||
|
v-model="search" |
||||
|
prepend-inner-icon="search" |
||||
|
label="Search" |
||||
|
single-line |
||||
|
hide-details |
||||
|
filled |
||||
|
/> |
||||
|
</template> |
||||
|
<template v-slot:item.text="{ item }"> |
||||
|
<v-edit-dialog> |
||||
|
<span class="d-flex d-sm-none">{{ item.text | truncate(50) }}</span> |
||||
|
<span class="d-none d-sm-flex">{{ item.text | truncate(200) }}</span> |
||||
|
<template v-slot:input> |
||||
|
<v-textarea |
||||
|
:value="item.text" |
||||
|
label="Edit" |
||||
|
autofocus |
||||
|
@change="updateDocument({ id: item.id, text: $event })" |
||||
|
/> |
||||
|
</template> |
||||
|
</v-edit-dialog> |
||||
|
</template> |
||||
|
</v-data-table> |
||||
|
</template> |
||||
|
|
||||
|
<script> |
||||
|
export default { |
||||
|
props: { |
||||
|
headers: { |
||||
|
type: Array, |
||||
|
default: () => [], |
||||
|
required: true |
||||
|
}, |
||||
|
docs: { |
||||
|
type: Array, |
||||
|
default: () => [], |
||||
|
required: true |
||||
|
}, |
||||
|
selected: { |
||||
|
type: Array, |
||||
|
default: () => [], |
||||
|
required: true |
||||
|
} |
||||
|
}, |
||||
|
data() { |
||||
|
return { |
||||
|
search: '' |
||||
|
} |
||||
|
}, |
||||
|
methods: { |
||||
|
update(selected) { |
||||
|
this.$emit('update-selected', selected) |
||||
|
}, |
||||
|
updateDocument(payload) { |
||||
|
this.$emit('update-doc', payload) |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
</script> |
@ -0,0 +1,25 @@ |
|||||
|
import ApiService from '@/services/api.service' |
||||
|
|
||||
|
class DocumentService { |
||||
|
constructor() { |
||||
|
this.request = new ApiService() |
||||
|
} |
||||
|
|
||||
|
getDocumentList(projectId) { |
||||
|
return this.request.get(`/projects/${projectId}/docs`) |
||||
|
} |
||||
|
|
||||
|
addDocument(projectId, payload) { |
||||
|
return this.request.post(`/projects/${projectId}/docs`, payload) |
||||
|
} |
||||
|
|
||||
|
deleteDocument(projectId, docId) { |
||||
|
return this.request.delete(`/projects/${projectId}/docs/${docId}`) |
||||
|
} |
||||
|
|
||||
|
updateDocument(projectId, docId, payload) { |
||||
|
return this.request.patch(`/projects/${projectId}/docs/${docId}`, payload) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export default new DocumentService() |
@ -0,0 +1,76 @@ |
|||||
|
import DocumentService from '@/services/document.service' |
||||
|
|
||||
|
export const state = () => ({ |
||||
|
items: [], |
||||
|
selected: [] |
||||
|
}) |
||||
|
|
||||
|
export const getters = { |
||||
|
isDocumentSelected(state) { |
||||
|
return state.selected.length > 0 |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export const mutations = { |
||||
|
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 = [] |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export const actions = { |
||||
|
getDocumentList(context, config) { |
||||
|
return DocumentService.getDocumentList() |
||||
|
.then((response) => { |
||||
|
context.commit('setDocumentList', response) |
||||
|
}) |
||||
|
.catch((error) => { |
||||
|
alert(error) |
||||
|
}) |
||||
|
}, |
||||
|
createDocument({ commit }, data) { |
||||
|
DocumentService.addDocument(data.projectId, data) |
||||
|
.then((response) => { |
||||
|
commit('addDocument', response) |
||||
|
}) |
||||
|
.catch((error) => { |
||||
|
alert(error) |
||||
|
}) |
||||
|
}, |
||||
|
updateDocument({ commit }, data) { |
||||
|
DocumentService.updateDocument(data.projectId, data.id, data) |
||||
|
.then((response) => { |
||||
|
commit('updateDocument', response) |
||||
|
}) |
||||
|
.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') |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save