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.

156 lines
4.1 KiB

  1. <template>
  2. <v-main>
  3. <v-container fluid>
  4. <v-row justify="center">
  5. <v-col cols="12" md="9">
  6. <v-card>
  7. <v-img contain :src="currentDoc.filename" max-height="300" class="grey lighten-2" />
  8. </v-card>
  9. <v-card>
  10. <v-data-table
  11. :headers="headers"
  12. :items="currentDoc.annotations"
  13. item-key="id"
  14. hide-default-header
  15. hide-default-footer
  16. disable-pagination
  17. class="elevation-1"
  18. @input="update"
  19. >
  20. <template #top>
  21. <v-text-field
  22. v-model="newText"
  23. :prepend-inner-icon="mdiPencil"
  24. :label="$t('annotation.newText')"
  25. autofocus
  26. single-line
  27. hide-details
  28. filled
  29. @keyup.enter="create"
  30. @compositionstart="compositionStart"
  31. @compositionend="compositionEnd"
  32. />
  33. </template>
  34. <template #[`item.text`]="{ item }">
  35. <v-edit-dialog>
  36. <span class="title" style="font-weight: 400">
  37. {{ item.text }}
  38. </span>
  39. <template #input>
  40. <v-textarea
  41. :value="item.text"
  42. :label="$t('generic.edit')"
  43. autofocus
  44. @change="update(item.id, $event)"
  45. />
  46. </template>
  47. </v-edit-dialog>
  48. </template>
  49. <template #[`item.action`]="{ item }">
  50. <v-icon small @click="remove(item.id)">
  51. {{ mdiDeleteOutline }}
  52. </v-icon>
  53. </template>
  54. </v-data-table>
  55. </v-card>
  56. </v-col>
  57. <v-col cols="12" md="3">
  58. <list-metadata :metadata="currentDoc.meta" />
  59. </v-col>
  60. </v-row>
  61. </v-container>
  62. </v-main>
  63. </template>
  64. <script>
  65. import { mdiPencil, mdiDeleteOutline } from '@mdi/js'
  66. import ListMetadata from '@/components/tasks/metadata/ListMetadata'
  67. export default {
  68. components: {
  69. ListMetadata
  70. },
  71. layout: 'demo',
  72. data() {
  73. return {
  74. newText: '',
  75. headers: [
  76. {
  77. text: 'Text',
  78. align: 'left',
  79. value: 'text'
  80. },
  81. {
  82. text: 'Actions',
  83. align: 'right',
  84. value: 'action'
  85. }
  86. ],
  87. isComposing: false,
  88. hasCompositionJustEnded: false,
  89. mdiPencil,
  90. mdiDeleteOutline,
  91. currentDoc: {
  92. id: 8,
  93. filename: require('~/assets/images/demo/cat.jpeg'),
  94. annotations: [
  95. {
  96. id: 17,
  97. text: 'A cat playing with flowers',
  98. user: 1,
  99. document: 8
  100. },
  101. {
  102. id: 18,
  103. text: 'A flower is blooming on the ground',
  104. user: 1,
  105. document: 8
  106. }
  107. ],
  108. meta: {
  109. url: 'https://github.com/Hironsan'
  110. },
  111. annotation_approver: null
  112. }
  113. }
  114. },
  115. methods: {
  116. update(annotationId, text) {
  117. if (text.length > 0) {
  118. const index = this.currentDoc.annotations.findIndex((item) => item.id === annotationId)
  119. this.currentDoc.annotations[index].text = text
  120. } else {
  121. this.remove(annotationId)
  122. }
  123. },
  124. create() {
  125. if (this.isComposing || this.hasCompositionJustEnded) {
  126. this.hasCompositionJustEnded = false
  127. return
  128. }
  129. if (this.newText.length > 0) {
  130. const payload = {
  131. id: Math.floor(Math.random() * Math.floor(Number.MAX_SAFE_INTEGER)),
  132. text: this.newText
  133. }
  134. this.currentDoc.annotations.push(payload)
  135. this.newText = ''
  136. }
  137. },
  138. remove(annotationId) {
  139. this.currentDoc.annotations = this.currentDoc.annotations.filter(
  140. (item) => item.id !== annotationId
  141. )
  142. },
  143. compositionStart() {
  144. this.isComposing = true
  145. },
  146. compositionEnd() {
  147. this.isComposing = false
  148. this.hasCompositionJustEnded = true
  149. }
  150. }
  151. }
  152. </script>