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.

121 lines
2.8 KiB

  1. <template>
  2. <base-card
  3. :disabled="!valid"
  4. title="Export Data"
  5. agree-text="Export"
  6. cancel-text="Cancel"
  7. @agree="downloadRequest"
  8. @cancel="cancel"
  9. >
  10. <template #content>
  11. <v-overlay :value="isProcessing">
  12. <v-progress-circular
  13. indeterminate
  14. size="64"
  15. />
  16. </v-overlay>
  17. <v-form
  18. ref="form"
  19. v-model="valid"
  20. >
  21. <h2>{{ $t('dataset.importDataMessage1') }}</h2>
  22. <v-radio-group
  23. ref="format"
  24. v-model="selectedFormat"
  25. :rules="fileFormatRules($t('rules.fileFormatRules'))"
  26. >
  27. <v-radio
  28. v-for="(format, i) in formats"
  29. :key="i"
  30. :label="format.name"
  31. :value="format"
  32. />
  33. </v-radio-group>
  34. <v-sheet
  35. v-if="selectedFormat"
  36. :dark="!$vuetify.theme.dark"
  37. :light="$vuetify.theme.dark"
  38. class="mb-5 pa-5"
  39. >
  40. <pre>{{ selectedFormat.example.trim() }}</pre>
  41. </v-sheet>
  42. <h2>{{ $t('dataset.exportDataMessage2') }}</h2>
  43. <v-checkbox
  44. v-model="exportApproved"
  45. label="Export only approved documents"
  46. hide-details
  47. />
  48. </v-form>
  49. </template>
  50. </base-card>
  51. </template>
  52. <script lang="ts">
  53. import Vue from 'vue'
  54. import BaseCard from '@/components/utils/BaseCard.vue'
  55. import { fileFormatRules } from '@/rules/index'
  56. import { FormatDTO } from '~/services/application/download/formatData'
  57. export default Vue.extend({
  58. components: {
  59. BaseCard
  60. },
  61. data() {
  62. return {
  63. file: null,
  64. fileFormatRules,
  65. exportApproved: false,
  66. selectedFormat: null as any,
  67. formats: [] as FormatDTO[],
  68. taskId: '',
  69. polling: null,
  70. valid: false,
  71. isProcessing: false,
  72. }
  73. },
  74. computed: {
  75. projectId() {
  76. return this.$route.params.id
  77. }
  78. },
  79. async created() {
  80. this.formats = await this.$services.downloadFormat.list(this.projectId)
  81. },
  82. beforeDestroy() {
  83. // @ts-ignore
  84. clearInterval(this.polling)
  85. },
  86. methods: {
  87. cancel() {
  88. (this.$refs.format as HTMLFormElement).reset()
  89. this.taskId = ''
  90. this.exportApproved = false
  91. this.selectedFormat = null
  92. this.isProcessing = false
  93. this.$emit('cancel')
  94. },
  95. async downloadRequest() {
  96. this.isProcessing = true
  97. this.taskId = await this.$services.download.request(this.projectId, this.selectedFormat.name, this.exportApproved)
  98. this.pollData()
  99. },
  100. pollData() {
  101. // @ts-ignore
  102. this.polling = setInterval(async() => {
  103. if (this.taskId) {
  104. const res = await this.$services.taskStatus.get(this.taskId)
  105. if (res.ready) {
  106. this.$services.download.download(this.projectId, this.taskId)
  107. this.cancel()
  108. }
  109. }
  110. }, 1000)
  111. },
  112. }
  113. })
  114. </script>