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.

104 lines
2.0 KiB

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