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.

111 lines
2.2 KiB

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