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.

126 lines
2.7 KiB

  1. <template>
  2. <v-card>
  3. <v-data-table
  4. :headers="headers"
  5. :items="annotations"
  6. @input="update"
  7. item-key="id"
  8. hide-default-header
  9. hide-default-footer
  10. disable-pagination
  11. class="elevation-1"
  12. >
  13. <template v-slot:top>
  14. <v-text-field
  15. v-model="newText"
  16. @keyup.enter="create"
  17. @compositionstart="compositionStart"
  18. @compositionend="compositionEnd"
  19. prepend-inner-icon="mdi-pencil"
  20. label="New text"
  21. autofocus
  22. single-line
  23. hide-details
  24. filled
  25. />
  26. </template>
  27. <template v-slot:item.text="{ item }">
  28. <v-edit-dialog>
  29. <span class="title" style="font-weight:400">
  30. {{ item.text }}
  31. </span>
  32. <template v-slot:input>
  33. <v-textarea
  34. :value="item.text"
  35. @change="update(item.id, $event)"
  36. label="Edit"
  37. autofocus
  38. />
  39. </template>
  40. </v-edit-dialog>
  41. </template>
  42. <template v-slot:item.action="{ item }">
  43. <v-icon
  44. @click="deleteAnnotation(item.id)"
  45. small
  46. >
  47. delete
  48. </v-icon>
  49. </template>
  50. </v-data-table>
  51. </v-card>
  52. </template>
  53. <script>
  54. export default {
  55. props: {
  56. annotations: {
  57. type: Array,
  58. default: () => ([]),
  59. required: true
  60. },
  61. deleteAnnotation: {
  62. type: Function,
  63. default: () => ([]),
  64. required: true
  65. },
  66. updateAnnotation: {
  67. type: Function,
  68. default: () => ([]),
  69. required: true
  70. },
  71. createAnnotation: {
  72. type: Function,
  73. default: () => ([]),
  74. required: true
  75. }
  76. },
  77. data() {
  78. return {
  79. newText: '',
  80. headers: [
  81. {
  82. text: 'Text',
  83. align: 'left',
  84. value: 'text'
  85. },
  86. {
  87. text: 'Actions',
  88. align: 'right',
  89. value: 'action'
  90. }
  91. ],
  92. isComposing: false,
  93. hasCompositionJustEnded: false
  94. }
  95. },
  96. methods: {
  97. update(annotationId, text) {
  98. if (text.length > 0) {
  99. this.updateAnnotation(annotationId, text)
  100. } else {
  101. this.deleteAnnotation(annotationId)
  102. }
  103. },
  104. create() {
  105. if (this.isComposing || this.hasCompositionJustEnded) {
  106. this.hasCompositionJustEnded = false
  107. return
  108. }
  109. if (this.newText.length > 0) {
  110. this.createAnnotation(this.newText)
  111. this.newText = ''
  112. }
  113. },
  114. compositionStart() {
  115. this.isComposing = true
  116. },
  117. compositionEnd() {
  118. this.isComposing = false
  119. this.hasCompositionJustEnded = true
  120. }
  121. }
  122. }
  123. </script>