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.

147 lines
3.8 KiB

4 years ago
4 years ago
4 years ago
4 years ago
  1. <template>
  2. <v-data-table
  3. :value="selected"
  4. :headers="headers"
  5. :items="items"
  6. :search="search"
  7. :loading="loading"
  8. :loading-text="$t('generic.loading')"
  9. :no-data-text="$t('vuetify.noDataAvailable')"
  10. :footer-props="{
  11. 'showFirstLastPage': true,
  12. 'items-per-page-options': [5, 10, 15, $t('generic.all')],
  13. 'items-per-page-text': $t('vuetify.itemsPerPageText'),
  14. 'page-text': $t('dataset.pageText')
  15. }"
  16. item-key="id"
  17. show-select
  18. @input="updateSelected"
  19. >
  20. <template v-slot:top>
  21. <v-text-field
  22. v-model="search"
  23. prepend-inner-icon="search"
  24. :label="$t('generic.search')"
  25. single-line
  26. hide-details
  27. filled
  28. />
  29. </template>
  30. <template v-slot:item.text="{ item }">
  31. <v-edit-dialog>
  32. {{ item.text }}
  33. <template v-slot:input>
  34. <v-text-field
  35. :value="item.text"
  36. :rules="labelNameRules($t('rules.labelNameRules'))"
  37. :label="$t('generic.edit')"
  38. single-line
  39. @change="handleUpdateLabel({ id: item.id, text: $event })"
  40. />
  41. </template>
  42. </v-edit-dialog>
  43. </template>
  44. <template v-slot:item.suffix_key="{ item }">
  45. <v-edit-dialog>
  46. <div>{{ item.suffix_key }}</div>
  47. <template v-slot:input>
  48. <v-select
  49. :value="item.suffix_key"
  50. :items="availableShortkeys(item.suffix_key)"
  51. :label="$t('annotation.key')"
  52. @change="handleUpdateLabel({ id: item.id, suffix_key: $event })"
  53. />
  54. </template>
  55. </v-edit-dialog>
  56. </template>
  57. <template v-slot:item.background_color="{ item }">
  58. <v-edit-dialog>
  59. <v-chip
  60. :color="item.background_color"
  61. :text-color="textColor(item.background_color)"
  62. dark
  63. >
  64. {{ item.background_color }}
  65. </v-chip>
  66. <template v-slot:input>
  67. <v-color-picker
  68. :value="item.background_color"
  69. :rules="colorRules($t('rules.colorRules'))"
  70. show-swatches
  71. hide-mode-switch
  72. width="800"
  73. mode="hexa"
  74. class="ma-2"
  75. @update:color="handleUpdateLabel({ id:item.id, background_color: $event.hex })"
  76. />
  77. </template>
  78. </v-edit-dialog>
  79. </template>
  80. </v-data-table>
  81. </template>
  82. <script>
  83. import { mapGetters, mapState, mapActions, mapMutations } from 'vuex'
  84. import { colorRules, labelNameRules } from '@/rules/index'
  85. import { idealColor } from '~/plugins/utils'
  86. export default {
  87. data() {
  88. return {
  89. search: '',
  90. headers: [
  91. {
  92. text: this.$t('generic.name'),
  93. align: 'left',
  94. value: 'text'
  95. },
  96. {
  97. text: this.$t('labels.shortkey'),
  98. value: 'suffix_key'
  99. },
  100. {
  101. text: this.$t('labels.color'),
  102. sortable: false,
  103. value: 'background_color'
  104. }
  105. ],
  106. colorRules,
  107. labelNameRules
  108. }
  109. },
  110. computed: {
  111. ...mapState('labels', ['items', 'selected', 'loading']),
  112. ...mapGetters('labels', ['shortkeys'])
  113. },
  114. created() {
  115. this.getLabelList({
  116. projectId: this.$route.params.id
  117. })
  118. },
  119. methods: {
  120. ...mapActions('labels', ['getLabelList', 'updateLabel']),
  121. ...mapMutations('labels', ['updateSelected']),
  122. handleUpdateLabel(payload) {
  123. const data = {
  124. projectId: this.$route.params.id,
  125. ...payload
  126. }
  127. this.updateLabel(data)
  128. },
  129. availableShortkeys(suffixKey) {
  130. const usedKeys = this.items.map(item => item.suffix_key)
  131. const unusedKeys = this.shortkeys.filter(item => item === suffixKey || !usedKeys.includes(item))
  132. return unusedKeys
  133. },
  134. textColor(backgroundColor) {
  135. return idealColor(backgroundColor)
  136. }
  137. }
  138. }
  139. </script>