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.

194 lines
4.7 KiB

3 years ago
3 years ago
  1. <template>
  2. <v-card>
  3. <v-card-title v-if="isProjectAdmin">
  4. <action-menu
  5. @upload="upload"
  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. :item-key="itemKey"
  29. @cancel="dialogDelete=false"
  30. @remove="remove"
  31. />
  32. </v-dialog>
  33. <v-dialog v-model="dialogDeleteAll">
  34. <form-delete-bulk
  35. @cancel="dialogDeleteAll=false"
  36. @remove="removeAll"
  37. />
  38. </v-dialog>
  39. <v-dialog v-model="dialogDownload">
  40. <form-download
  41. @cancel="dialogDownload=false"
  42. />
  43. </v-dialog>
  44. </v-card-title>
  45. <image-list
  46. v-if="isImageTask"
  47. v-model="selected"
  48. :items="item.items"
  49. :is-loading="isLoading"
  50. :total="item.count"
  51. @update:query="updateQuery"
  52. @click:labeling="movePage"
  53. />
  54. <audio-list
  55. v-else-if="isAudioTask"
  56. v-model="selected"
  57. :items="item.items"
  58. :is-loading="isLoading"
  59. :total="item.count"
  60. @update:query="updateQuery"
  61. @click:labeling="movePage"
  62. />
  63. <document-list
  64. v-else
  65. v-model="selected"
  66. :items="item.items"
  67. :is-loading="isLoading"
  68. :total="item.count"
  69. @update:query="updateQuery"
  70. @click:labeling="movePage"
  71. />
  72. </v-card>
  73. </template>
  74. <script lang="ts">
  75. import Vue from 'vue'
  76. import _ from 'lodash'
  77. import DocumentList from '@/components/example/DocumentList.vue'
  78. import FormDelete from '@/components/example/FormDelete.vue'
  79. import FormDeleteBulk from '@/components/example/FormDeleteBulk.vue'
  80. import FormDownload from '@/components/example/FormDownload.vue'
  81. import ImageList from '~/components/example/ImageList.vue'
  82. import AudioList from '~/components/example/AudioList.vue'
  83. import { ExampleListDTO, ExampleDTO } from '~/services/application/example/exampleData'
  84. import ActionMenu from '~/components/example/ActionMenu.vue'
  85. import { ProjectDTO } from '~/services/application/project/projectData'
  86. export default Vue.extend({
  87. components: {
  88. ActionMenu,
  89. AudioList,
  90. DocumentList,
  91. ImageList,
  92. FormDelete,
  93. FormDeleteBulk,
  94. FormDownload,
  95. },
  96. layout: 'project',
  97. validate({ params, query }) {
  98. // @ts-ignore
  99. return /^\d+$/.test(params.id) && /^\d+|$/.test(query.limit) && /^\d+|$/.test(query.offset)
  100. },
  101. data() {
  102. return {
  103. dialogDelete: false,
  104. dialogDeleteAll: false,
  105. dialogDownload: false,
  106. project: {} as ProjectDTO,
  107. item: {} as ExampleListDTO,
  108. selected: [] as ExampleDTO[],
  109. isLoading: false,
  110. isProjectAdmin: false
  111. }
  112. },
  113. async fetch() {
  114. this.isLoading = true
  115. this.item = await this.$services.example.list(this.projectId, this.$route.query)
  116. this.isLoading = false
  117. },
  118. computed: {
  119. canDelete(): boolean {
  120. return this.selected.length > 0
  121. },
  122. projectId(): string {
  123. return this.$route.params.id
  124. },
  125. isImageTask(): boolean {
  126. return this.project.projectType === 'ImageClassification'
  127. },
  128. isAudioTask(): boolean {
  129. return this.project.projectType === 'Speech2text'
  130. },
  131. itemKey(): string {
  132. if (this.isImageTask || this.isAudioTask) {
  133. return 'filename'
  134. } else {
  135. return 'text'
  136. }
  137. }
  138. },
  139. watch: {
  140. '$route.query': _.debounce(function() {
  141. // @ts-ignore
  142. this.$fetch()
  143. }, 1000
  144. ),
  145. },
  146. async created() {
  147. this.project = await this.$services.project.findById(this.projectId)
  148. this.isProjectAdmin = this.project.current_users_role.is_project_admin
  149. },
  150. methods: {
  151. async remove() {
  152. await this.$services.example.bulkDelete(this.projectId, this.selected)
  153. this.$fetch()
  154. this.dialogDelete = false
  155. this.selected = []
  156. },
  157. async removeAll() {
  158. await this.$services.example.bulkDelete(this.projectId, [])
  159. this.$fetch()
  160. this.dialogDeleteAll = false
  161. this.selected = []
  162. },
  163. upload() {
  164. this.$router.push(`/projects/${this.projectId}/upload`)
  165. },
  166. updateQuery(query: object) {
  167. this.$router.push(query)
  168. },
  169. movePage(query: object) {
  170. this.updateQuery({
  171. path: this.localePath(this.project.pageLink),
  172. query
  173. })
  174. }
  175. }
  176. })
  177. </script>
  178. <style scoped>
  179. ::v-deep .v-dialog {
  180. width: 800px;
  181. }
  182. </style>