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.

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