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.

165 lines
3.7 KiB

3 years ago
3 years ago
  1. <template>
  2. <v-card>
  3. <v-tabs v-if="hasMultiType" v-model="tab">
  4. <v-tab class="text-capitalize">Category</v-tab>
  5. <v-tab class="text-capitalize">Span</v-tab>
  6. </v-tabs>
  7. <v-card-title>
  8. <action-menu
  9. @create="$router.push('labels/add?type=' + labelType)"
  10. @upload="$router.push('labels/import?type=' + labelType)"
  11. @download="download"
  12. />
  13. <v-btn
  14. class="text-capitalize ms-2"
  15. :disabled="!canDelete"
  16. outlined
  17. @click.stop="dialogDelete=true"
  18. >
  19. {{ $t('generic.delete') }}
  20. </v-btn>
  21. <v-dialog v-model="dialogDelete">
  22. <form-delete
  23. :selected="selected"
  24. @cancel="dialogDelete=false"
  25. @remove="remove"
  26. />
  27. </v-dialog>
  28. </v-card-title>
  29. <label-list
  30. v-model="selected"
  31. :items="items"
  32. :is-loading="isLoading"
  33. @edit="editItem"
  34. />
  35. </v-card>
  36. </template>
  37. <script lang="ts">
  38. import Vue from 'vue'
  39. import ActionMenu from '@/components/label/ActionMenu.vue'
  40. import FormDelete from '@/components/label/FormDelete.vue'
  41. import LabelList from '@/components/label/LabelList.vue'
  42. import { LabelDTO } from '~/services/application/label/labelData'
  43. import { ProjectDTO } from '~/services/application/project/projectData'
  44. export default Vue.extend({
  45. components: {
  46. ActionMenu,
  47. FormDelete,
  48. LabelList
  49. },
  50. layout: 'project',
  51. validate({ params, app }) {
  52. if (/^\d+$/.test(params.id)) {
  53. return app.$services.project.findById(params.id)
  54. .then((res:ProjectDTO) => {
  55. return res.canDefineLabel
  56. })
  57. }
  58. return false
  59. },
  60. data() {
  61. return {
  62. dialogDelete: false,
  63. items: [] as LabelDTO[],
  64. selected: [] as LabelDTO[],
  65. isLoading: false,
  66. tab: null,
  67. project: {} as ProjectDTO,
  68. }
  69. },
  70. computed: {
  71. canDelete(): boolean {
  72. return this.selected.length > 0
  73. },
  74. projectId(): string {
  75. return this.$route.params.id
  76. },
  77. hasMultiType(): boolean {
  78. if ('projectType' in this.project) {
  79. return this.project.projectType === 'IntentDetectionAndSlotFilling'
  80. } else {
  81. return false
  82. }
  83. },
  84. labelType(): string {
  85. if (this.hasMultiType) {
  86. if (this.tab === 0) {
  87. return 'category'
  88. } else {
  89. return 'span'
  90. }
  91. } else if (this.project.projectType.endsWith('Classification')) {
  92. return 'category'
  93. } else {
  94. return 'span'
  95. }
  96. },
  97. service(): any {
  98. if (!('projectType' in this.project)) {
  99. return
  100. }
  101. if (this.hasMultiType) {
  102. if (this.tab === 0) {
  103. return this.$services.categoryType
  104. } else {
  105. return this.$services.spanType
  106. }
  107. } else if (this.project.projectType.endsWith('Classification')) {
  108. return this.$services.categoryType
  109. } else {
  110. return this.$services.spanType
  111. }
  112. }
  113. },
  114. watch: {
  115. tab() {
  116. this.list()
  117. }
  118. },
  119. async created() {
  120. this.project = await this.$services.project.findById(this.projectId)
  121. await this.list()
  122. },
  123. methods: {
  124. async list() {
  125. this.isLoading = true
  126. this.items = await this.service.list(this.projectId)
  127. this.isLoading = false
  128. },
  129. async remove() {
  130. await this.service.bulkDelete(this.projectId, this.selected)
  131. this.list()
  132. this.dialogDelete = false
  133. this.selected = []
  134. },
  135. async download() {
  136. await this.service.export(this.projectId)
  137. },
  138. editItem(item: LabelDTO) {
  139. this.$router.push(`labels/${item.id}/edit?type=${this.labelType}`)
  140. }
  141. }
  142. })
  143. </script>
  144. <style scoped>
  145. ::v-deep .v-dialog {
  146. width: 800px;
  147. }
  148. </style>