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.

119 lines
2.6 KiB

3 years ago
3 years ago
3 years ago
3 years ago
  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 #top>
  14. <v-text-field
  15. v-model="newText"
  16. :prepend-inner-icon="mdiPencil"
  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 #[`item.text`]="{ item }">
  28. <v-edit-dialog>
  29. <span class="title" style="font-weight:400">
  30. {{ item.text }}
  31. </span>
  32. <template #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 #[`item.action`]="{ item }">
  43. <v-icon
  44. small
  45. @click="remove(item.id)"
  46. >
  47. {{ mdiDeleteOutline }}
  48. </v-icon>
  49. </template>
  50. </v-data-table>
  51. </v-card>
  52. </template>
  53. <script lang="ts">
  54. import Vue from 'vue'
  55. import { mdiPencil, mdiDeleteOutline } from '@mdi/js'
  56. export default Vue.extend({
  57. props: {
  58. annotations: {
  59. type: Array,
  60. default: () => ([]),
  61. required: true
  62. }
  63. },
  64. data() {
  65. return {
  66. newText: '',
  67. headers: [
  68. {
  69. text: 'Text',
  70. align: 'left',
  71. value: 'text'
  72. },
  73. {
  74. text: 'Actions',
  75. align: 'right',
  76. value: 'action'
  77. }
  78. ],
  79. isComposing: false,
  80. hasCompositionJustEnded: false,
  81. mdiPencil,
  82. mdiDeleteOutline
  83. }
  84. },
  85. methods: {
  86. update(annotationId: number, text: string) {
  87. if (text.length > 0) {
  88. this.$emit('update:annotation', annotationId, text)
  89. } else {
  90. this.remove(annotationId)
  91. }
  92. },
  93. create() {
  94. if (this.isComposing || this.hasCompositionJustEnded) {
  95. this.hasCompositionJustEnded = false
  96. return
  97. }
  98. if (this.newText.length > 0) {
  99. this.$emit('create:annotation', this.newText)
  100. this.newText = ''
  101. }
  102. },
  103. remove(annotationId: number) {
  104. this.$emit('delete:annotation', annotationId)
  105. },
  106. compositionStart() {
  107. this.isComposing = true
  108. },
  109. compositionEnd() {
  110. this.isComposing = false
  111. this.hasCompositionJustEnded = true
  112. }
  113. }
  114. })
  115. </script>