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.

164 lines
3.8 KiB

  1. <template>
  2. <div style="display:inline;">
  3. <v-tooltip bottom>
  4. <template v-slot:activator="{ on }">
  5. <v-btn
  6. class="text-capitalize ps-1 pe-1"
  7. min-width="36"
  8. icon
  9. v-on="on"
  10. @click="dialog=true"
  11. >
  12. <v-icon>
  13. mdi-chat
  14. </v-icon>
  15. </v-btn>
  16. </template>
  17. <span>{{ $t('annotation.commentTooltip') }}</span>
  18. </v-tooltip>
  19. <v-dialog
  20. v-model="dialog"
  21. width="800"
  22. >
  23. <base-card
  24. :title="$t('annotation.commentPopupTitle')"
  25. :cancel-text="$t('generic.close')"
  26. @cancel="dialog=false"
  27. >
  28. <template #content>
  29. <v-text-field
  30. v-model="comment"
  31. outlined
  32. >
  33. <template
  34. v-slot:append
  35. >
  36. <v-btn
  37. tile
  38. large
  39. icon
  40. height="auto"
  41. width="auto"
  42. color="primary"
  43. class="ma-0"
  44. @click="addItem"
  45. >
  46. <v-icon>mdi-plus</v-icon>
  47. </v-btn>
  48. </template>
  49. </v-text-field>
  50. <v-data-table
  51. :headers="headers"
  52. :items="currentDoc.comments"
  53. :items-per-page="10"
  54. class="elevation-1"
  55. >
  56. <template v-slot:item.action="{ item }">
  57. <v-icon
  58. small
  59. @click="deleteItem(item.id)"
  60. >
  61. mdi-delete
  62. </v-icon>
  63. </template>
  64. <template v-slot:item.text="props">
  65. <v-edit-dialog
  66. large
  67. persistent
  68. @save="editItem"
  69. @open="openEdit(props.item)"
  70. >
  71. <div>{{ props.item.text }}</div>
  72. <template v-slot:input>
  73. <div class="mt-4 title">
  74. Update Comment
  75. </div>
  76. <v-text-field
  77. v-model="editedComment.text"
  78. label="Edit"
  79. single-line
  80. counter
  81. autofocus
  82. />
  83. </template>
  84. </v-edit-dialog>
  85. </template>
  86. </v-data-table>
  87. </template>
  88. </base-card>
  89. </v-dialog>
  90. </div>
  91. </template>
  92. <script>
  93. import { mapGetters, mapActions } from 'vuex'
  94. import BaseCard from '@/components/molecules/BaseCard'
  95. export default {
  96. components: {
  97. BaseCard
  98. },
  99. data() {
  100. return {
  101. dialog: false,
  102. comment: '',
  103. editedComment: {
  104. text: '',
  105. id: null
  106. }
  107. }
  108. },
  109. computed: {
  110. ...mapGetters('documents', ['currentDoc']),
  111. headers() {
  112. return [
  113. {
  114. text: 'Comments',
  115. align: 'start',
  116. sortable: false,
  117. value: 'text'
  118. },
  119. { text: 'Action', value: 'action', sortable: false }
  120. ]
  121. }
  122. },
  123. methods: {
  124. ...mapActions('documents', ['addComment', 'deleteComment', 'updateComment']),
  125. addItem() {
  126. if (this.comment === '') {
  127. return
  128. }
  129. const payload = {
  130. text: this.comment,
  131. projectId: this.$route.params.id
  132. }
  133. this.addComment(payload)
  134. this.comment = ''
  135. },
  136. deleteItem(id) {
  137. const payload = {
  138. commentId: id,
  139. projectId: this.$route.params.id
  140. }
  141. this.deleteComment(payload)
  142. },
  143. editItem() {
  144. if (this.editedComment.text === '') {
  145. this.deleteItem(this.editedComment.id)
  146. } else {
  147. this.updateComment({
  148. projectId: this.$route.params.id,
  149. commentId: this.editedComment.id,
  150. text: this.editedComment.text
  151. })
  152. }
  153. },
  154. openEdit(item) {
  155. Object.assign(this.editedComment, item)
  156. }
  157. }
  158. }
  159. </script>