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.

94 lines
2.3 KiB

  1. <template>
  2. <v-card
  3. v-if="isReady"
  4. v-shortkey="multiKeys"
  5. @shortkey="addOrRemoveLabel"
  6. >
  7. <v-card-title>
  8. <multi-class-classification
  9. :labels="items"
  10. :annotations="currentDoc.annotations"
  11. :add-label="addLabel"
  12. :delete-label="removeLabel"
  13. />
  14. </v-card-title>
  15. <v-card-text class="title highlight" v-text="currentDoc.text" />
  16. </v-card>
  17. </template>
  18. <script>
  19. import Vue from 'vue'
  20. import { mapActions, mapGetters, mapState } from 'vuex'
  21. import MultiClassClassification from '@/components/organisms/annotation/MultiClassClassification'
  22. Vue.use(require('vue-shortkey'))
  23. export default {
  24. components: {
  25. MultiClassClassification
  26. },
  27. computed: {
  28. ...mapState('labels', ['items']),
  29. ...mapState('documents', ['loading']),
  30. ...mapGetters('documents', ['currentDoc']),
  31. multiKeys() {
  32. const multiKeys = {}
  33. for (const item of this.items) {
  34. multiKeys[item.id] = [item.suffix_key]
  35. }
  36. return multiKeys
  37. },
  38. isReady() {
  39. return this.currentDoc && this.items && !this.loading
  40. }
  41. },
  42. created() {
  43. this.getLabelList({
  44. projectId: this.$route.params.id
  45. })
  46. },
  47. methods: {
  48. ...mapActions('labels', ['getLabelList']),
  49. ...mapActions('documents', ['getDocumentList', 'deleteAnnotation', 'updateAnnotation', 'addAnnotation']),
  50. removeLabel(annotationId) {
  51. const payload = {
  52. annotationId,
  53. projectId: this.$route.params.id
  54. }
  55. this.deleteAnnotation(payload)
  56. },
  57. updateLabel(labelId, annotationId) {
  58. const payload = {
  59. annotationId,
  60. label: labelId,
  61. projectId: this.$route.params.id
  62. }
  63. this.updateAnnotation(payload)
  64. },
  65. addLabel(labelId) {
  66. const payload = {
  67. label: labelId,
  68. projectId: this.$route.params.id
  69. }
  70. this.addAnnotation(payload)
  71. },
  72. addOrRemoveLabel(event) {
  73. const label = this.items.find(item => item.id === parseInt(event.srcKey, 10))
  74. const annotation = this.currentDoc.annotations.find(item => item.label === label.id)
  75. if (annotation) {
  76. this.removeLabel(annotation.id)
  77. } else {
  78. this.addLabel(label.id)
  79. }
  80. }
  81. }
  82. }
  83. </script>
  84. <style scoped>
  85. .highlight {
  86. white-space: pre-wrap;
  87. }
  88. </style>