Browse Source

Add feature bulkimport for same filetype

pull/1163/head
Chris 3 years ago
parent
commit
cfafe1fd66
4 changed files with 31 additions and 14 deletions
  1. 39
      frontend/components/organisms/documents/DocumentUploadForm.vue
  2. 2
      frontend/i18n/en/projects/dataset.js
  3. 2
      frontend/i18n/en/projects/errors.js
  4. 2
      frontend/rules/index.js

39
frontend/components/organisms/documents/DocumentUploadForm.vue

@ -18,7 +18,7 @@
type="error"
dismissible
>
{{ $t('errors.fileCannotUpload') }}
{{ $t('errors.fileCannotUpload') + errorMsg }}
</v-alert>
<h2>{{ $t('dataset.importDataMessage1') }}</h2>
<v-radio-group
@ -45,6 +45,7 @@
<h2>{{ $t('dataset.importDataMessage2') }}</h2>
<v-file-input
v-model="file"
multiple
:accept="acceptType"
:rules="uploadFileRules($t('rules.uploadFileRules'))"
:label="$t('labels.filePlaceholder')"
@ -81,7 +82,9 @@ export default {
selectedFormat: null,
fileFormatRules,
uploadFileRules,
showError: false
showError: false,
errors: [],
errorMsg: ''
}
},
@ -107,18 +110,32 @@ export default {
},
create() {
if (this.validate()) {
this.uploadDocument({
projectId: this.$route.params.id,
format: this.selectedFormat.type,
file: this.file
})
.then((response) => {
this.reset()
this.cancel()
this.errors = []
const promises = []
const id = this.$route.params.id
const type = this.selectedFormat.type
this.file.forEach((item) => {
promises.push({
projectId: id,
format: type,
file: item
})
.catch(() => {
})
let p = Promise.resolve()
promises.forEach((item) => {
p = p.then(() => this.uploadDocument(item)).catch(() => {
this.errors.push(item.file.name)
this.showError = true
})
})
p.finally(() => {
if (!this.errors.length) {
this.reset()
this.cancel()
} else {
this.errorMsg = this.errors.join(', ')
}
})
}
}
}

2
frontend/i18n/en/projects/dataset.js

@ -9,7 +9,7 @@ export default {
annotate: 'Annotate',
importDataTitle: 'Upload Data',
importDataMessage1: 'Select a file format',
importDataMessage2: 'Select a file',
importDataMessage2: 'Select file(s)',
importDataPlaceholder: 'File input',
exportDataTitle: 'Export Data',
exportDataMessage: 'Select a file format',

2
frontend/i18n/en/projects/errors.js

@ -1,5 +1,5 @@
export default {
fileCannotUpload: 'The file could not be uploaded. Maybe invalid format.\n Please check available formats carefully.',
fileCannotUpload: 'The file(s) could not be uploaded. Maybe invalid format.\n Please check available formats and the following file(s): ',
labelCannotCreate: 'The label could not be created.\n You cannot use the same label name or shortcut key.',
invalidUserOrPass: 'Incorrect username or password, or something went wrong.'
}

2
frontend/rules/index.js

@ -57,7 +57,7 @@ export const fileFormatRules = (msg) => {
export const uploadFileRules = (msg) => {
return [
v => !!v || msg.fileRequired,
v => !v || v.size < 1000000 || msg.fileLessThan1MB
v => !v || v.some(file => file.size < 1000000) || msg.fileLessThan1MB
]
}

Loading…
Cancel
Save