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.

116 lines
2.6 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="$t('annotation.newText')"
  18. autofocus
  19. single-line
  20. hide-details
  21. filled
  22. @keyup.enter="create"
  23. @compositionstart="compositionStart"
  24. @compositionend="compositionEnd"
  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. :label="$t('generic.edit')"
  36. autofocus
  37. @change="update(item.id, $event)"
  38. />
  39. </template>
  40. </v-edit-dialog>
  41. </template>
  42. <template v-slot:[`item.action`]="{ item }">
  43. <v-icon
  44. small
  45. @click="remove(item.id)"
  46. >
  47. mdi-delete-outline
  48. </v-icon>
  49. </template>
  50. </v-data-table>
  51. </v-card>
  52. </template>
  53. <script lang="ts">
  54. import Vue from 'vue'
  55. export default Vue.extend({
  56. props: {
  57. annotations: {
  58. type: Array,
  59. default: () => ([]),
  60. required: true
  61. }
  62. },
  63. data() {
  64. return {
  65. newText: '',
  66. headers: [
  67. {
  68. text: 'Text',
  69. align: 'left',
  70. value: 'text'
  71. },
  72. {
  73. text: 'Actions',
  74. align: 'right',
  75. value: 'action'
  76. }
  77. ],
  78. isComposing: false,
  79. hasCompositionJustEnded: false
  80. }
  81. },
  82. methods: {
  83. update(annotationId: number, text: string) {
  84. if (text.length > 0) {
  85. this.$emit('update:annotation', annotationId, text)
  86. } else {
  87. this.remove(annotationId)
  88. }
  89. },
  90. create() {
  91. if (this.isComposing || this.hasCompositionJustEnded) {
  92. this.hasCompositionJustEnded = false
  93. return
  94. }
  95. if (this.newText.length > 0) {
  96. this.$emit('create:annotation', this.newText)
  97. this.newText = ''
  98. }
  99. },
  100. remove(annotationId: number) {
  101. this.$emit('delete:annotation', annotationId)
  102. },
  103. compositionStart() {
  104. this.isComposing = true
  105. },
  106. compositionEnd() {
  107. this.isComposing = false
  108. this.hasCompositionJustEnded = true
  109. }
  110. }
  111. })
  112. </script>