Browse Source

Implement upload feature roughly

pull/341/head
Hironsan 5 years ago
parent
commit
d19a51f0dd
5 changed files with 20 additions and 31 deletions
  1. 12
      frontend/api/routes/docs.js
  2. 7
      frontend/components/containers/DocumentUploadButton.vue
  3. 26
      frontend/components/organisms/DocumentUploadForm.vue
  4. 4
      frontend/services/document.service.js
  5. 2
      frontend/store/documents.js

12
frontend/api/routes/docs.js

@ -22,6 +22,18 @@ router.post('/', (req, res) => {
res.json(doc) res.json(doc)
}) })
// Upload a file.
router.post('/upload', (req, res) => {
const doc = {
id: db.reduce((x, y) => { return x.id > y.id ? x : y }).id + 1,
text: 'Uploaded Document',
meta: JSON.stringify({}),
annotations: []
}
db.push(doc)
res.json(doc)
})
// Update a document partially. // Update a document partially.
router.patch('/:docId', (req, res) => { router.patch('/:docId', (req, res) => {
const docIndex = db.findIndex(item => item.id === parseInt(req.params.docId)) const docIndex = db.findIndex(item => item.id === parseInt(req.params.docId))

7
frontend/components/containers/DocumentUploadButton.vue

@ -7,9 +7,6 @@
<document-upload-form <document-upload-form
:upload-document="uploadDocument" :upload-document="uploadDocument"
:formats="formatList" :formats="formatList"
:headers="headers"
:parse-file="parseFile"
:parsed-doc="parsedDoc"
@close="slotProps.close" @close="slotProps.close"
/> />
</template> </template>
@ -28,11 +25,11 @@ export default {
}, },
computed: { computed: {
...mapGetters('documents', ['formatList', 'parsedDoc', 'headers'])
...mapGetters('documents', ['formatList'])
}, },
methods: { methods: {
...mapActions('documents', ['uploadDocument', 'parseFile'])
...mapActions('documents', ['uploadDocument'])
} }
} }
</script> </script>

26
frontend/components/organisms/DocumentUploadForm.vue

@ -28,28 +28,19 @@
:accept="acceptType" :accept="acceptType"
:rules="uploadFileRules" :rules="uploadFileRules"
label="File input" label="File input"
@change="parseFile"
/> />
</v-form> </v-form>
<document-list
:headers="headers"
:docs="parsedDoc"
:selected="[]"
:loading="false"
/>
</template> </template>
</base-card> </base-card>
</template> </template>
<script> <script>
import BaseCard from '@/components/molecules/BaseCard' import BaseCard from '@/components/molecules/BaseCard'
import DocumentList from '@/components/organisms/DocumentList'
import { fileFormatRules, uploadFileRules } from '@/rules/index' import { fileFormatRules, uploadFileRules } from '@/rules/index'
export default { export default {
components: { components: {
BaseCard,
DocumentList
BaseCard
}, },
props: { props: {
uploadDocument: { uploadDocument: {
@ -57,25 +48,10 @@ export default {
default: () => {}, default: () => {},
required: true required: true
}, },
parseFile: {
type: Function,
default: () => {},
required: true
},
formats: { formats: {
type: Array, type: Array,
default: () => [], default: () => [],
required: true required: true
},
parsedDoc: {
type: Array,
default: () => [],
required: true
},
headers: {
type: Array,
default: () => [],
required: true
} }
}, },
data() { data() {

4
frontend/services/document.service.js

@ -20,6 +20,10 @@ class DocumentService {
updateDocument(projectId, docId, payload) { updateDocument(projectId, docId, payload) {
return this.request.patch(`/projects/${projectId}/docs/${docId}`, payload) return this.request.patch(`/projects/${projectId}/docs/${docId}`, payload)
} }
uploadFile(projectId, payload) {
return this.request.post(`/projects/${projectId}/docs/upload`, payload)
}
} }
export default new DocumentService() export default new DocumentService()

2
frontend/store/documents.js

@ -99,7 +99,7 @@ export const actions = {
}) })
}, },
uploadDocument({ commit }, data) { uploadDocument({ commit }, data) {
DocumentService.addDocument(data.projectId, data)
DocumentService.uploadFile(data.projectId, data)
.then((response) => { .then((response) => {
commit('addDocument', response) commit('addDocument', response)
}) })

Loading…
Cancel
Save