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.

216 lines
5.5 KiB

2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
  1. <template>
  2. <v-data-table
  3. :value="value"
  4. :headers="headers"
  5. :items="items"
  6. :options.sync="options"
  7. :server-items-length="total"
  8. :search="search"
  9. :loading="isLoading"
  10. :loading-text="$t('generic.loading')"
  11. :no-data-text="$t('vuetify.noDataAvailable')"
  12. :footer-props="{
  13. showFirstLastPage: true,
  14. 'items-per-page-options': [10, 50, 100],
  15. 'items-per-page-text': $t('vuetify.itemsPerPageText'),
  16. 'page-text': $t('dataset.pageText')
  17. }"
  18. item-key="id"
  19. show-select
  20. @input="$emit('input', $event)"
  21. >
  22. <template #top>
  23. <v-text-field
  24. v-model="search"
  25. :prepend-inner-icon="mdiMagnify"
  26. :label="$t('generic.search') + ' (e.g. label:positive)'"
  27. single-line
  28. hide-details
  29. filled
  30. />
  31. </template>
  32. <template #[`item.isConfirmed`]="{ item }">
  33. <v-chip :color="item.isConfirmed ? 'success' : 'warning'" text small>
  34. {{ item.isConfirmed ? 'Finished' : 'In progress' }}
  35. </v-chip>
  36. </template>
  37. <template #[`item.text`]="{ item }">
  38. <span class="d-flex d-sm-none">{{ item.text | truncate(50) }}</span>
  39. <span class="d-none d-sm-flex">{{ item.text | truncate(200) }}</span>
  40. </template>
  41. <template #[`item.meta`]="{ item }">
  42. {{ JSON.stringify(item.meta, null, 4) }}
  43. </template>
  44. <template #[`item.assignee`]="{ item }">
  45. <v-combobox
  46. :value="toSelected(item)"
  47. :items="members"
  48. item-text="username"
  49. no-data-text="No one"
  50. multiple
  51. chips
  52. dense
  53. flat
  54. hide-selected
  55. hide-details
  56. small-chips
  57. solo
  58. style="width: 200px"
  59. @change="onAssignOrUnassign(item, $event)"
  60. />
  61. </template>
  62. <template #[`item.action`]="{ item }">
  63. <v-btn class="me-1" small color="primary text-capitalize" @click="$emit('edit', item)"
  64. >Edit</v-btn
  65. >
  66. <v-btn small color="primary text-capitalize" @click="toLabeling(item)">
  67. {{ $t('dataset.annotate') }}
  68. </v-btn>
  69. </template>
  70. </v-data-table>
  71. </template>
  72. <script lang="ts">
  73. import { mdiMagnify } from '@mdi/js'
  74. import type { PropType } from 'vue'
  75. import Vue from 'vue'
  76. import { DataOptions } from 'vuetify/types'
  77. import { ExampleDTO } from '~/services/application/example/exampleData'
  78. import { MemberItem } from '~/domain/models/member/member'
  79. export default Vue.extend({
  80. props: {
  81. isLoading: {
  82. type: Boolean,
  83. default: false,
  84. required: true
  85. },
  86. items: {
  87. type: Array as PropType<ExampleDTO[]>,
  88. default: () => [],
  89. required: true
  90. },
  91. value: {
  92. type: Array as PropType<ExampleDTO[]>,
  93. default: () => [],
  94. required: true
  95. },
  96. total: {
  97. type: Number,
  98. default: 0,
  99. required: true
  100. },
  101. members: {
  102. type: Array as PropType<MemberItem[]>,
  103. default: () => [],
  104. required: true
  105. },
  106. isAdmin: {
  107. type: Boolean,
  108. default: false
  109. }
  110. },
  111. data() {
  112. return {
  113. search: this.$route.query.q,
  114. options: {} as DataOptions,
  115. mdiMagnify
  116. }
  117. },
  118. computed: {
  119. headers() {
  120. const headers = [
  121. {
  122. text: 'Status',
  123. value: 'isConfirmed',
  124. sortable: false
  125. },
  126. {
  127. text: this.$t('dataset.text'),
  128. value: 'text',
  129. sortable: false
  130. },
  131. {
  132. text: this.$t('dataset.metadata'),
  133. value: 'meta',
  134. sortable: false
  135. },
  136. {
  137. text: this.$t('dataset.action'),
  138. value: 'action',
  139. sortable: false
  140. }
  141. ]
  142. if (this.isAdmin) {
  143. headers.splice(3, 0, {
  144. text: 'Assignee',
  145. value: 'assignee',
  146. sortable: false
  147. })
  148. }
  149. return headers
  150. }
  151. },
  152. watch: {
  153. options: {
  154. handler() {
  155. this.$emit('update:query', {
  156. query: {
  157. limit: this.options.itemsPerPage.toString(),
  158. offset: ((this.options.page - 1) * this.options.itemsPerPage).toString(),
  159. q: this.search
  160. }
  161. })
  162. },
  163. deep: true
  164. },
  165. search() {
  166. this.$emit('update:query', {
  167. query: {
  168. limit: this.options.itemsPerPage.toString(),
  169. offset: '0',
  170. q: this.search
  171. }
  172. })
  173. this.options.page = 1
  174. }
  175. },
  176. methods: {
  177. toLabeling(item: ExampleDTO) {
  178. const index = this.items.indexOf(item)
  179. const offset = (this.options.page - 1) * this.options.itemsPerPage
  180. const page = (offset + index + 1).toString()
  181. this.$emit('click:labeling', { page, q: this.search })
  182. },
  183. toSelected(item: ExampleDTO) {
  184. const assigneeIds = item.assignments.map((assignment) => assignment.assignee_id)
  185. return this.members.filter((member) => assigneeIds.includes(member.user))
  186. },
  187. onAssignOrUnassign(item: ExampleDTO, newAssignees: MemberItem[]) {
  188. const newAssigneeIds = newAssignees.map((assignee) => assignee.user)
  189. const oldAssigneeIds = item.assignments.map((assignment) => assignment.assignee_id)
  190. if (oldAssigneeIds.length > newAssigneeIds.length) {
  191. // unassign
  192. for (const assignment of item.assignments) {
  193. if (!newAssigneeIds.includes(assignment.assignee_id)) {
  194. this.$emit('unassign', assignment.id)
  195. }
  196. }
  197. } else {
  198. // assign
  199. for (const newAssigneeId of newAssigneeIds) {
  200. if (!oldAssigneeIds.includes(newAssigneeId)) {
  201. this.$emit('assign', item.id, newAssigneeId)
  202. }
  203. }
  204. }
  205. }
  206. }
  207. })
  208. </script>