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.

175 lines
4.2 KiB

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