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.4 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>{{ $t('dataset.importDataMessage1') }}</h2>
  16. <v-radio-group
  17. ref="format"
  18. v-model="selectedFormat"
  19. :rules="fileFormatRules($t('rules.fileFormatRules'))"
  20. >
  21. <v-radio
  22. v-for="(format, i) in formats"
  23. :key="i"
  24. :label="format.text"
  25. :value="format"
  26. />
  27. </v-radio-group>
  28. <v-sheet
  29. v-if="selectedFormat"
  30. :dark="!$vuetify.theme.dark"
  31. :light="$vuetify.theme.dark"
  32. class="mb-5 pa-5"
  33. >
  34. <span v-for="(example, index) in selectedFormat.examples" :key="index">
  35. {{ example }}<br>
  36. </span>
  37. </v-sheet>
  38. <h2>{{ $t('dataset.exportDataMessage2') }}</h2>
  39. <v-text-field v-model="selectedFileName" placeholder="Name the file" />
  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. exportDocument: {
  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. selectedFileName: 'project_' + this.$route.params.id + '_dataset',
  69. fileFormatRules,
  70. uploadFileRules
  71. }
  72. },
  73. computed: {
  74. acceptType() {
  75. if (this.selectedFormat) {
  76. return this.selectedFormat.accept
  77. } else {
  78. return '.txt,.csv,.json,.jsonl'
  79. }
  80. }
  81. },
  82. methods: {
  83. cancel() {
  84. this.$emit('close')
  85. },
  86. validate() {
  87. return this.$refs.form.validate()
  88. },
  89. reset() {
  90. this.$refs.format.reset()
  91. },
  92. download() {
  93. if (this.validate()) {
  94. this.exportDocument({
  95. projectId: this.$route.params.id,
  96. fileName: this.selectedFileName,
  97. format: this.selectedFormat.type,
  98. suffix: this.selectedFormat.suffix
  99. })
  100. this.reset()
  101. this.cancel()
  102. }
  103. }
  104. }
  105. }
  106. </script>