mirror of https://github.com/doccano/doccano.git
Hironsan
5 years ago
5 changed files with 155 additions and 3 deletions
Split View
Diff Options
-
30frontend/components/containers/DocumentUploadButton.vue
-
111frontend/components/organisms/DocumentUploadForm.vue
-
5frontend/pages/projects/_id/dataset/index.vue
-
10frontend/rules/index.js
-
2frontend/store/documents.js
@ -0,0 +1,30 @@ |
|||
<template> |
|||
<base-modal |
|||
text="Upload" |
|||
:is-create="true" |
|||
> |
|||
<template v-slot="slotProps"> |
|||
<document-upload-form |
|||
:upload-document="uploadDocument" |
|||
@close="slotProps.close" |
|||
/> |
|||
</template> |
|||
</base-modal> |
|||
</template> |
|||
|
|||
<script> |
|||
import { mapActions } from 'vuex' |
|||
import BaseModal from '@/components/molecules/BaseModal' |
|||
import DocumentUploadForm from '@/components/organisms/DocumentUploadForm' |
|||
|
|||
export default { |
|||
components: { |
|||
BaseModal, |
|||
DocumentUploadForm |
|||
}, |
|||
|
|||
methods: { |
|||
...mapActions('documents', ['uploadDocument']) |
|||
} |
|||
} |
|||
</script> |
@ -0,0 +1,111 @@ |
|||
<template> |
|||
<base-card |
|||
title="Upload Data" |
|||
agree-text="Upload" |
|||
cancel-text="Cancel" |
|||
:disabled="!valid" |
|||
@agree="create" |
|||
@cancel="cancel" |
|||
> |
|||
<template #content> |
|||
<v-form |
|||
ref="form" |
|||
v-model="valid" |
|||
> |
|||
<v-radio-group |
|||
v-model="selectedFormat" |
|||
:rules="fileFormatRules" |
|||
> |
|||
<v-radio |
|||
v-for="(format, i) in formats" |
|||
:key="i" |
|||
:label="format.text" |
|||
:value="format" |
|||
/> |
|||
</v-radio-group> |
|||
<v-file-input |
|||
v-model="file" |
|||
:accept="acceptType" |
|||
:rules="uploadFileRules" |
|||
label="File input" |
|||
/> |
|||
</v-form> |
|||
</template> |
|||
</base-card> |
|||
</template> |
|||
|
|||
<script> |
|||
import BaseCard from '@/components/molecules/BaseCard' |
|||
import { fileFormatRules, uploadFileRules } from '@/rules/index' |
|||
|
|||
export default { |
|||
components: { |
|||
BaseCard |
|||
}, |
|||
props: { |
|||
uploadDocument: { |
|||
type: Function, |
|||
default: () => {}, |
|||
required: true |
|||
} |
|||
}, |
|||
data() { |
|||
return { |
|||
valid: false, |
|||
file: null, |
|||
selectedFormat: null, |
|||
formats: [ |
|||
{ |
|||
type: 'csv', |
|||
text: 'Upload a CSV file from your computer', |
|||
accept: '.csv' |
|||
}, |
|||
{ |
|||
type: 'plain', |
|||
text: 'Upload text items from your computer', |
|||
accept: '.txt' |
|||
}, |
|||
{ |
|||
type: 'json', |
|||
text: 'Upload a JSON file from your computer', |
|||
accept: '.json,.jsonl' |
|||
} |
|||
], |
|||
fileFormatRules, |
|||
uploadFileRules |
|||
} |
|||
}, |
|||
|
|||
computed: { |
|||
acceptType() { |
|||
if (this.selectedFormat) { |
|||
return this.selectedFormat.accept |
|||
} else { |
|||
return '.txt,.csv,.json,.jsonl' |
|||
} |
|||
} |
|||
}, |
|||
|
|||
methods: { |
|||
cancel() { |
|||
this.$emit('close') |
|||
}, |
|||
validate() { |
|||
return this.$refs.form.validate() |
|||
}, |
|||
reset() { |
|||
this.$refs.form.reset() |
|||
}, |
|||
create() { |
|||
if (this.validate()) { |
|||
this.uploadDocument({ |
|||
format: this.selectedFormat, |
|||
file: this.file |
|||
}) |
|||
this.reset() |
|||
this.cancel() |
|||
} |
|||
} |
|||
} |
|||
} |
|||
</script> |
Write
Preview
Loading…
Cancel
Save