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.

128 lines
2.9 KiB

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