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.

118 lines
2.3 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. <h2>Select a file format</h2>
  16. <v-radio-group
  17. v-model="selectedFormat"
  18. :rules="fileFormatRules"
  19. >
  20. <v-radio
  21. v-for="(format, i) in formats"
  22. :key="i"
  23. :label="format.text"
  24. :value="format"
  25. />
  26. </v-radio-group>
  27. <code
  28. v-if="selectedFormat"
  29. class="mb-10 pa-5 highlight"
  30. >
  31. <span v-for="(example, index) in selectedFormat.examples" :key="index">{{ example }}</span>
  32. </code>
  33. <h2>Select a file</h2>
  34. <v-file-input
  35. v-model="file"
  36. :accept="acceptType"
  37. :rules="uploadFileRules"
  38. label="File input"
  39. />
  40. </v-form>
  41. </template>
  42. </base-card>
  43. </template>
  44. <script>
  45. import BaseCard from '@/components/molecules/BaseCard'
  46. import { fileFormatRules, uploadFileRules } from '@/rules/index'
  47. export default {
  48. components: {
  49. BaseCard
  50. },
  51. props: {
  52. uploadDocument: {
  53. type: Function,
  54. default: () => {},
  55. required: true
  56. },
  57. formats: {
  58. type: Array,
  59. default: () => [],
  60. required: true
  61. }
  62. },
  63. data() {
  64. return {
  65. valid: false,
  66. file: null,
  67. selectedFormat: null,
  68. fileFormatRules,
  69. uploadFileRules
  70. }
  71. },
  72. computed: {
  73. acceptType() {
  74. if (this.selectedFormat) {
  75. return this.selectedFormat.accept
  76. } else {
  77. return '.txt,.csv,.json,.jsonl'
  78. }
  79. }
  80. },
  81. methods: {
  82. cancel() {
  83. this.$emit('close')
  84. },
  85. validate() {
  86. return this.$refs.form.validate()
  87. },
  88. reset() {
  89. this.$refs.form.reset()
  90. },
  91. create() {
  92. if (this.validate()) {
  93. this.uploadDocument({
  94. projectId: this.$route.params.id,
  95. format: this.selectedFormat.type,
  96. file: this.file
  97. })
  98. this.reset()
  99. this.cancel()
  100. }
  101. }
  102. }
  103. }
  104. </script>
  105. <style scoped>
  106. .highlight {
  107. font-size: 100%;
  108. width: 100%;
  109. }
  110. .highlight:before {
  111. content: ''
  112. }
  113. </style>