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.

110 lines
2.1 KiB

  1. <template>
  2. <base-card
  3. title="Export Data"
  4. agree-text="Export"
  5. cancel-text="Cancel"
  6. :disabled="!valid"
  7. @agree="download"
  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. </v-form>
  34. </template>
  35. </base-card>
  36. </template>
  37. <script>
  38. import BaseCard from '@/components/molecules/BaseCard'
  39. import { fileFormatRules, uploadFileRules } from '@/rules/index'
  40. export default {
  41. components: {
  42. BaseCard
  43. },
  44. props: {
  45. exportDocument: {
  46. type: Function,
  47. default: () => {},
  48. required: true
  49. },
  50. formats: {
  51. type: Array,
  52. default: () => [],
  53. required: true
  54. }
  55. },
  56. data() {
  57. return {
  58. valid: false,
  59. file: null,
  60. selectedFormat: null,
  61. fileFormatRules,
  62. uploadFileRules
  63. }
  64. },
  65. computed: {
  66. acceptType() {
  67. if (this.selectedFormat) {
  68. return this.selectedFormat.accept
  69. } else {
  70. return '.txt,.csv,.json,.jsonl'
  71. }
  72. }
  73. },
  74. methods: {
  75. cancel() {
  76. this.$emit('close')
  77. },
  78. validate() {
  79. return this.$refs.form.validate()
  80. },
  81. reset() {
  82. this.$refs.form.reset()
  83. },
  84. download() {
  85. if (this.validate()) {
  86. this.exportDocument({
  87. projectId: this.$route.params.id,
  88. format: this.selectedFormat.type
  89. })
  90. this.reset()
  91. this.cancel()
  92. }
  93. }
  94. }
  95. }
  96. </script>
  97. <style scoped>
  98. .highlight {
  99. font-size: 100%;
  100. width: 100%;
  101. }
  102. .highlight:before {
  103. content: ''
  104. }
  105. </style>