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.

196 lines
4.8 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 { mapGetters } from 'vuex'
  77. import _ from 'lodash'
  78. import DocumentList from '@/components/example/DocumentList.vue'
  79. import FormDelete from '@/components/example/FormDelete.vue'
  80. import FormDeleteBulk from '@/components/example/FormDeleteBulk.vue'
  81. import FormDownload from '@/components/example/FormDownload.vue'
  82. import ImageList from '~/components/example/ImageList.vue'
  83. import AudioList from '~/components/example/AudioList.vue'
  84. import { ExampleListDTO, ExampleDTO } from '~/services/application/example/exampleData'
  85. import ActionMenu from '~/components/example/ActionMenu.vue'
  86. import { ProjectDTO } from '~/services/application/project/projectData'
  87. export default Vue.extend({
  88. components: {
  89. ActionMenu,
  90. AudioList,
  91. DocumentList,
  92. ImageList,
  93. FormDelete,
  94. FormDeleteBulk,
  95. FormDownload,
  96. },
  97. layout: 'project',
  98. validate({ params, query }) {
  99. // @ts-ignore
  100. return /^\d+$/.test(params.id) && /^\d+|$/.test(query.limit) && /^\d+|$/.test(query.offset)
  101. },
  102. data() {
  103. return {
  104. dialogDelete: false,
  105. dialogDeleteAll: false,
  106. dialogDownload: false,
  107. project: {} as ProjectDTO,
  108. item: {} as ExampleListDTO,
  109. selected: [] as ExampleDTO[],
  110. isLoading: false,
  111. isProjectAdmin: false
  112. }
  113. },
  114. async fetch() {
  115. this.isLoading = true
  116. this.item = await this.$services.example.list(this.projectId, this.$route.query)
  117. this.isLoading = false
  118. },
  119. computed: {
  120. canDelete(): boolean {
  121. return this.selected.length > 0
  122. },
  123. projectId(): string {
  124. return this.$route.params.id
  125. },
  126. isImageTask(): boolean {
  127. return this.project.projectType === 'ImageClassification'
  128. },
  129. isAudioTask(): boolean {
  130. return this.project.projectType === 'Speech2text'
  131. },
  132. itemKey(): string {
  133. if (this.isImageTask || this.isAudioTask) {
  134. return 'filename'
  135. } else {
  136. return 'text'
  137. }
  138. },
  139. ...mapGetters('auth', ['getUserId'])
  140. },
  141. watch: {
  142. '$route.query': _.debounce(function() {
  143. // @ts-ignore
  144. this.$fetch()
  145. }, 1000
  146. ),
  147. },
  148. async created() {
  149. this.project = await this.$services.project.findById(this.projectId)
  150. this.isProjectAdmin = await this.$services.member.isProjectAdmin(this.projectId, this.getUserId)
  151. },
  152. methods: {
  153. async remove() {
  154. await this.$services.example.bulkDelete(this.projectId, this.selected)
  155. this.$fetch()
  156. this.dialogDelete = false
  157. this.selected = []
  158. },
  159. async removeAll() {
  160. await this.$services.example.bulkDelete(this.projectId, [])
  161. this.$fetch()
  162. this.dialogDeleteAll = false
  163. this.selected = []
  164. },
  165. upload() {
  166. this.$router.push(`/projects/${this.projectId}/upload`)
  167. },
  168. updateQuery(query: object) {
  169. this.$router.push(query)
  170. },
  171. movePage(query: object) {
  172. this.updateQuery({
  173. path: this.localePath(this.project.pageLink),
  174. query
  175. })
  176. }
  177. }
  178. })
  179. </script>
  180. <style scoped>
  181. ::v-deep .v-dialog {
  182. width: 800px;
  183. }
  184. </style>