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.

179 lines
4.4 KiB

  1. <template>
  2. <v-card>
  3. <v-card-title>
  4. <action-menu
  5. @upload="dialogUpload=true"
  6. @download="dialogDownload=true"
  7. />
  8. <v-btn
  9. class="text-capitalize ms-2"
  10. :disabled="!canDelete"
  11. outlined
  12. @click.stop="dialogDelete=true"
  13. >
  14. {{ $t('generic.delete') }}
  15. </v-btn>
  16. <v-spacer />
  17. <v-btn
  18. :disabled="!item.count"
  19. class="text-capitalize"
  20. color="error"
  21. @click="dialogDeleteAll=true"
  22. >
  23. {{ $t('generic.deleteAll') }}
  24. </v-btn>
  25. <v-dialog v-model="dialogDelete">
  26. <form-delete
  27. :selected="selected"
  28. @cancel="dialogDelete=false"
  29. @remove="remove"
  30. />
  31. </v-dialog>
  32. <v-dialog v-model="dialogDeleteAll">
  33. <form-delete-bulk
  34. @cancel="dialogDeleteAll=false"
  35. @remove="removeAll"
  36. />
  37. </v-dialog>
  38. <v-dialog v-model="dialogUpload">
  39. <form-upload
  40. :formats="project.uploadFormats"
  41. :upload-document="upload"
  42. @cancel="dialogUpload=false"
  43. @success="$fetch();dialogUpload=false"
  44. />
  45. </v-dialog>
  46. <v-dialog v-model="dialogDownload">
  47. <form-download
  48. :formats="project.downloadFormats"
  49. @cancel="dialogDownload=false"
  50. @download="download"
  51. />
  52. </v-dialog>
  53. </v-card-title>
  54. <document-list
  55. v-model="selected"
  56. :items="item.items"
  57. :is-loading="isLoading"
  58. :total="item.count"
  59. @update:query="updateQuery"
  60. @click:labeling="movePage"
  61. />
  62. </v-card>
  63. </template>
  64. <script lang="ts">
  65. import Vue from 'vue'
  66. import _ from 'lodash'
  67. import DocumentList from '@/components/document/DocumentList.vue'
  68. import FormDelete from '@/components/document/FormDelete.vue'
  69. import FormDeleteBulk from '@/components/document/FormDeleteBulk.vue'
  70. import FormDownload from '@/components/document/FormDownload.vue'
  71. import FormUpload from '@/components/document/FormUpload.vue'
  72. import { DocumentListDTO, DocumentDTO } from '~/services/application/document/documentData'
  73. import ActionMenu from '~/components/document/ActionMenu.vue'
  74. import { ProjectDTO, FormatDTO } from '~/services/application/project/projectData'
  75. export default Vue.extend({
  76. layout: 'project',
  77. components: {
  78. ActionMenu,
  79. DocumentList,
  80. FormDelete,
  81. FormDeleteBulk,
  82. FormDownload,
  83. FormUpload
  84. },
  85. async fetch() {
  86. this.isLoading = true
  87. this.item = await this.$services.document.list(this.projectId, this.$route.query)
  88. this.isLoading = false
  89. },
  90. data() {
  91. return {
  92. dialogCreate: false,
  93. dialogDelete: false,
  94. dialogDeleteAll: false,
  95. dialogUpload: false,
  96. dialogDownload: false,
  97. formats: [] as FormatDTO[],
  98. project: {} as ProjectDTO,
  99. item: {} as DocumentListDTO,
  100. selected: [] as DocumentDTO[],
  101. isLoading: false
  102. }
  103. },
  104. computed: {
  105. canDelete(): boolean {
  106. return this.selected.length > 0
  107. },
  108. projectId(): string {
  109. return this.$route.params.id
  110. }
  111. },
  112. watch: {
  113. '$route.query': _.debounce(function() {
  114. // @ts-ignore
  115. this.$fetch()
  116. }, 1000
  117. ),
  118. },
  119. async created() {
  120. this.project = await this.$services.project.findById(this.projectId)
  121. },
  122. methods: {
  123. async remove() {
  124. await this.$services.document.bulkDelete(this.projectId, this.selected)
  125. this.$fetch()
  126. this.dialogDelete = false
  127. this.selected = []
  128. },
  129. async removeAll() {
  130. await this.$services.document.bulkDelete(this.projectId, [])
  131. this.$fetch()
  132. this.dialogDeleteAll = false
  133. this.selected = []
  134. },
  135. async download(format: FormatDTO, filename: string, onlyApproved: boolean) {
  136. await this.$services.document.download(
  137. this.projectId,
  138. filename,
  139. format,
  140. onlyApproved
  141. )
  142. },
  143. async upload(file: File, format: string) {
  144. await this.$services.document.upload(
  145. this.projectId, file, format
  146. )
  147. },
  148. updateQuery(query: object) {
  149. this.$router.push(query)
  150. },
  151. movePage(query: object) {
  152. this.updateQuery({
  153. path: this.localePath(this.project.pageLink),
  154. query
  155. })
  156. }
  157. },
  158. validate({ params, query }) {
  159. // @ts-ignore
  160. return /^\d+$/.test(params.id) && /^\d+|$/.test(query.limit) && /^\d+|$/.test(query.offset)
  161. }
  162. })
  163. </script>
  164. <style scoped>
  165. ::v-deep .v-dialog {
  166. width: 800px;
  167. }
  168. </style>