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)
})
// 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.
router.patch('/:docId', (req, res) => {
const docIndex = db.findIndex(item => item.id === parseInt(req.params.docId))

7
frontend/components/containers/DocumentUploadButton.vue

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

26
frontend/components/organisms/DocumentUploadForm.vue

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

4
frontend/services/document.service.js

@ -20,6 +20,10 @@ class DocumentService {
updateDocument(projectId, 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()

2
frontend/store/documents.js

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

Loading…
Cancel
Save