You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
1.8 KiB

  1. <template>
  2. <base-card
  3. title="Upload Data"
  4. agree-text="Upload"
  5. cancel-text="Cancel"
  6. :disabled="!valid"
  7. @agree="create"
  8. @cancel="cancel"
  9. >
  10. <template #content>
  11. <v-form
  12. ref="form"
  13. v-model="valid"
  14. >
  15. <v-radio-group
  16. v-model="selectedFormat"
  17. :rules="fileFormatRules"
  18. >
  19. <v-radio
  20. v-for="(format, i) in formats"
  21. :key="i"
  22. :label="format.text"
  23. :value="format"
  24. />
  25. </v-radio-group>
  26. <v-file-input
  27. :value="file"
  28. :accept="acceptType"
  29. :rules="uploadFileRules"
  30. label="File input"
  31. />
  32. </v-form>
  33. </template>
  34. </base-card>
  35. </template>
  36. <script>
  37. import BaseCard from '@/components/molecules/BaseCard'
  38. import { fileFormatRules, uploadFileRules } from '@/rules/index'
  39. export default {
  40. components: {
  41. BaseCard
  42. },
  43. props: {
  44. uploadDocument: {
  45. type: Function,
  46. default: () => {},
  47. required: true
  48. },
  49. formats: {
  50. type: Array,
  51. default: () => [],
  52. required: true
  53. }
  54. },
  55. data() {
  56. return {
  57. valid: false,
  58. file: null,
  59. selectedFormat: null,
  60. fileFormatRules,
  61. uploadFileRules
  62. }
  63. },
  64. computed: {
  65. acceptType() {
  66. if (this.selectedFormat) {
  67. return this.selectedFormat.accept
  68. } else {
  69. return '.txt,.csv,.json,.jsonl'
  70. }
  71. }
  72. },
  73. methods: {
  74. cancel() {
  75. this.$emit('close')
  76. },
  77. validate() {
  78. return this.$refs.form.validate()
  79. },
  80. reset() {
  81. this.$refs.form.reset()
  82. },
  83. create() {
  84. if (this.validate()) {
  85. this.uploadDocument({
  86. format: this.selectedFormat,
  87. file: this.file
  88. })
  89. this.reset()
  90. this.cancel()
  91. }
  92. }
  93. }
  94. }
  95. </script>