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.

134 lines
3.1 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="Loading... Please wait"
  9. item-key="id"
  10. show-select
  11. @input="updateSelected"
  12. >
  13. <template v-slot:top>
  14. <v-text-field
  15. v-model="search"
  16. prepend-inner-icon="search"
  17. label="Search"
  18. single-line
  19. hide-details
  20. filled
  21. />
  22. </template>
  23. <template v-slot:item.text="{ item }">
  24. <v-edit-dialog>
  25. {{ item.text }}
  26. <template v-slot:input>
  27. <v-text-field
  28. :value="item.text"
  29. :rules="labelNameRules"
  30. label="Edit"
  31. single-line
  32. @change="handleUpdateLabel({ id: item.id, text: $event })"
  33. />
  34. </template>
  35. </v-edit-dialog>
  36. </template>
  37. <template v-slot:item.suffix_key="{ item }">
  38. <v-edit-dialog>
  39. <div>{{ item.suffix_key }}</div>
  40. <template v-slot:input>
  41. <v-select
  42. :value="item.suffix_key"
  43. :items="shortkeys"
  44. label="Key"
  45. @change="handleUpdateLabel({ id: item.id, suffix_key: $event })"
  46. />
  47. </template>
  48. </v-edit-dialog>
  49. </template>
  50. <template v-slot:item.background_color="{ item }">
  51. <v-edit-dialog>
  52. <v-chip
  53. :color="item.background_color"
  54. :text-color="textColor(item.background_color)"
  55. dark
  56. >
  57. {{ item.background_color }}
  58. </v-chip>
  59. <template v-slot:input>
  60. <v-color-picker
  61. :value="item.background_color"
  62. :rules="colorRules"
  63. show-swatches
  64. hide-mode-switch
  65. width="800"
  66. mode="hexa"
  67. class="ma-2"
  68. @update:color="handleUpdateLabel({ id:item.id, background_color: $event.hex })"
  69. />
  70. </template>
  71. </v-edit-dialog>
  72. </template>
  73. </v-data-table>
  74. </template>
  75. <script>
  76. import { mapGetters, mapState, mapActions, mapMutations } from 'vuex'
  77. import { colorRules, labelNameRules } from '@/rules/index'
  78. import { idealColor } from '~/plugins/utils'
  79. export default {
  80. data() {
  81. return {
  82. search: '',
  83. headers: [
  84. {
  85. text: 'Name',
  86. align: 'left',
  87. value: 'text'
  88. },
  89. {
  90. text: 'Shortkey',
  91. value: 'suffix_key'
  92. },
  93. {
  94. text: 'Color',
  95. sortable: false,
  96. value: 'background_color'
  97. }
  98. ],
  99. colorRules,
  100. labelNameRules
  101. }
  102. },
  103. computed: {
  104. ...mapState('labels', ['items', 'selected', 'loading']),
  105. ...mapGetters('labels', ['shortkeys'])
  106. },
  107. created() {
  108. this.getLabelList({
  109. projectId: this.$route.params.id
  110. })
  111. },
  112. methods: {
  113. ...mapActions('labels', ['getLabelList', 'updateLabel']),
  114. ...mapMutations('labels', ['updateSelected']),
  115. handleUpdateLabel(payload) {
  116. const data = {
  117. projectId: this.$route.params.id,
  118. ...payload
  119. }
  120. this.updateLabel(data)
  121. },
  122. textColor(backgroundColor) {
  123. return idealColor(backgroundColor)
  124. }
  125. }
  126. }
  127. </script>